algorithmic modeling for Rhino
Hello everyone,
short story:
as the title says i'm looking for a way to select a mesh which was baked to rhino from within a c++ component.
longer story:
i m baking some points to rhino and using the meshfrompoints command (within the c++ script) to create the mesh, then i want to be able to have it as an output of the script...
so that you can animate/wb it or whatever else.
unfortunately didn t find a way to do that.
Any help/suggestions appreciated.
Thank you in advance
You can have a look in the attached file
Tags:
Hi Tudor,
Grasshopper is an interface to the Rhino SDK. In this case, the SDK does not expose a method to do this operation, so it's painful to do this and very difficult to do it properly in any language (in this case, the language is C# -- read c sharp).
Anyways, to make the code work, what you still need is a way to select the objects from the document. The following code might be a beginning for this last operation:
---
RMA.Rhino.MRhinoObjectIterator iterator =
new RMA.Rhino.MRhinoObjectIterator(IRhinoObjectIterator.object_state.normal_objects,
IRhinoObjectIterator.object_category.active_objects);
iterator.EnableSelectedFilter(true);
List<IOnMesh> meshes = new List<IOnMesh>();
RMA.Rhino.MRhinoObject current;
while((current = iterator.Next()) != null)
{
IOnGeometry g = current.Geometry();
if(g != null && g.ObjectType() == IOn.object_type.mesh_object)
{
IOnMesh tmp = OnMesh.ConstCast(g);
if(tmp != null)
meshes.Add(tmp);
}
}
A = meshes;
---
- Giulio
____________
giulio@mcneel.com
McNeel Europe, Barcelona
!!!!!!! Thank you Giulio !!!!!!!
That piece of code does more then i was expecting to get !!! thank you for your time, code and explanation!
All the best,
Tudor
This is way too difficult in RhinoCommon. I just added a bunch of functions that should make it easier. Starting from the next release, you should be able to write the following in the new C# component:
private void RunScript(List<Point3d> pts, bool run, ref object A)
{
if (!run) { return; }
if (pts == null) { return; }
if (pts.Count < 3) { return; }
//Unselect all objects
doc.Objects.UnselectAll();
//Then, bake the objects and remember all the IDs so we can delete them properly
List<Guid> pointIDs = new List<Guid>(pts.Count);
for (int i = 0; i < pts.Count; i++)
{
if (pts[i].IsValid) { pointIDs.Add(doc.Objects.AddPoint(pts[i])); }
}
if (pointIDs.Count < 3)
{
Print("Insufficient valid points for a Mesh");
doc.Objects.Delete(pointIDs, true);
return;
}
//Now run the MeshFromPoints command
doc.Objects.Select(pointIDs);
if (RhinoApp.RunScript("-_MeshfromPoints _Enter", false))
{
//If the script was successfully run, search for the most recently added object
Rhino.DocObjects.RhinoObject obj = doc.Objects.MostRecentObject();
A = obj.Geometry.Duplicate();
doc.Objects.Delete(obj, true);
}
//Now delete the points
doc.Objects.Delete(pointIDs, true);
}
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thank you David!
will give it a try as soon as the new release is out. Any hints on when the new release will come out? :P
The code i stitched together is, for now, doing what i was hoping for, but can't wait to see the one above doing its magic.
cheers!
I'm hoping to upload a beta release to the VB/C# forum today or maybe tomorrow. There have been a number of SDK breaks and I want to give GHA developers the opportunity to have a look at potential problems before I release publicly.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
That s great news! :)
Waiting for the beta then!
This is a debug build of Grasshopper, you cannot compare it with a Release build. Let's wait until the proper version is released and then we can start optimizing :)
--
David Rutten
david@mcneel.com
Poprad, Slovakia
cool! sounds like a plan :P
anyway, thank you as always, the new build looks very promising (especially the long list of changes)!!
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
© 2024 Created by Scott Davidson. Powered by