Hello,
I’m a novice plugin developer, so I apologize beforehand if this has already been answered elsewhere.
Is there a way of ‘using’ the SelEdgeLoop command from within a plugin command?
By this I mean if there is any Rhino C++ SDK API function doing this same thing? (much like other RhinoXYZ functions for other commands…) I’ve also checked ON_Mesh with no luck…
I’m also aware of RhinoApp().RunScript(), and while this solution is not preferred, I could work with it. However, I do not know how edges can be selected from a script, if at all possible. I tried edge indices but it didn’t work.
[On a related side topic: is there any way to figure out the arguments you can pass into commands in script mode, i.e. RhinoApp().RunScript()?]
ON_SubDEdgeChain is the C++ SDK class that is closest in function to the SelEdgeLoop command. A combination of BeginEdgeChain and AddAllNeighbors (once in each direction) should get you close to what the command is doing.
Note that if what you want to do is allow the user to click one edge, and get the edge loop in return, then it is usually easier to rely on the subobject picking of Rhino. A CRhinoGetObject with the geometry filter set to CRhinoGetObject::meshedge_filter, and subobject selection enabled, will let the user select an edge loop with Ctrl+Shift+DoubleClick. You get a list of SubD edges returned, and can rebuild the edge chain with ON_SubDEdgeChain::SortEdgesIntoEdgeChains. That makes highlighting and pre-selection easier to sort out.
Basically everything that you can type in Rhino’s command line should work here, and prefixing command names with an hyphen - will allow more options. The online help lists them.
Sorry I was deep in SubD and forgot SelEdgeLoop applies to meshes too. I do not see anything accessible in the C++ SDK for mesh edge loops unfortunately. You could convert to SubD, get the edge loop with ON_SubDEdgeChain, then convert back to a mesh, but at that point I would just script the command.
I was trying to get this to work, but noticed a problem.
Edge indices seem to change from the mesh to the SubD. Can I assume they always increase by one? My ON_Mesh mesh is a manifold, with no ngons, no duplicate vertices, etc. I worry ON_SubD::Internal_CreateFromMeshWithValidNgons might still introduce new topology.
I have also managed to get this to work, by a combination of CRhinoMeshObject::SelectSubObject and RhinoApp::RunScript. However, I need to:
first create a copy of the CRhinoMeshObject object, as selection on the const CRhinoGetObject::Object object doesn’t work.
select the seed edge with CRhinoMeshObject::SelectSubObject and then replace the original CRhinoMeshObject with the copy
script the command with RhinoApp::RunScript
loop over every edge in the CRhinoMeshObject::Mesh topology and check whether it was selected with CRhinoMeshObject::IsSubObjectSelected
You can see how this is not very efficient when I need to run it over a thousand times on a large mesh. Is there a better way to do this?
I’m surprised, SelectSubObject's signature seems to be OK with const objects. Do you mean that scripting SelEdgeLoop itself does not work if your mesh object is const? Can you start with a non-const, or do a const_cast instead?
CRhinoMeshObject::GetSelectedSubObjects looks like it will be more efficient than your method.
Apart from that, sounds like standard code for scripting a command from C++.