algorithmic modeling for Rhino
I am a bit new to Python. I have a hang of doing ghpythonlib.component... but not so much rhino common and rhinoscryptsyntax. First I tried doing Rhino.Geometry.Mesh.Reduce(), but then I noticed that it only returns a Boolean. Then I searched the internet, found this discussion and the script at the bottom works. Andrew did this in C#:
private void RunScript(Mesh M, double P, ref object A)
{
if(M != null){
Guid meshObj = doc.Objects.AddMesh(M);
doc.Objects.UnselectAll();
doc.Objects.Select(meshObj);
Rhino.RhinoApp.RunScript("_-ReduceMesh _ReductionPercentage " + Convert.ToString(P) + " _Enter", false);
Rhino.DocObjects.RhinoObject MObj = doc.Objects.GetSelectedObjects(false, false).First();
doc.Objects.Delete(meshObj, true);
A = MObj.Geometry;
}
How do I do this in Python. I understand the concept behind Rhino.RhinoApp.RunScript(), but how do I aim that command at a mesh (especially one from grasshopper). And what is the deal with this command being destructive to the original geometry?
Thanks.
Tags:
The reason this script does some things in a seemingly strange way is to get around the fact that the Rhino SDK does not expose the reduce mesh functionality. In order to use it from Grasshopper, you have to 1. take the GH mesh and bake it into the rhino document, 2. Run the reducemesh command, 3. gather the results of the command back in to grasshopper, and 3. delete the temporary mesh you put in Rhino. This is by no means ideal, but it's the only way I know of.
As far as doing it in python, the method is approximately the same - see the attached script. The only major difference is that you need to iterate over the results retrieved from GetSelectedObjects (rather than just grabbing the first item).
Thanks for the response. It helps for me to see the code written in Python. The reason why I needed this component was to make the mesh lighter so that things calculated faster later in the definition. But right now, pyMeshReduce is taking longer to execute than expected. Is there any wayto use ghpythonlib.parallel to speed this component up? Would it work with the whole select and deselect situation?
Hi!
I learn python script, and I wanna study rhinoApp and rhinoDoc.
If we can use reference site or tutorial, please tell me URL.
Thanks.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by