RhinoCommon block example


Is there a .NET Rhino plugin example how to select Rhino blocks and iterate geometry objects inside of a block?

Iteration of InstanceDefinition

Select block instance, iterate

There are a couple more when you look at the search results here

Thank you very much.
Can these examples be used in command line c# plugins?
They seem to be much more simple than before.

These examples show the basics, but you should be able to write commands in C# plug-ins that tap into block definitions and their instances.

Thanks. One more question.

How do you cast Rhino object rhino_objects[i] to geometry types e.g. curves here

var rhino_objects = idef.GetObjects();
for (int i = 0; i < rhino_objects.Length; i++)
Rhino.RhinoApp.WriteLine(“Object {0} = {1}”, i, rhino_objects[i].Id);

You can use the RhinoObject.ObjectType Property to find out what ObjectType Enumeration an object is, then cast to one of the inheriting classes.


I suppose you can also use the is keyword in if checks:

RhinoObject ob = GetSomeUndeterminedObject();

if(ob is MeshObject meshOb) { /* play with meshOb */ }
else if(ob is CurveObject curveOb) { /* play with curveOb */ }
/* etc. */
1 Like

Works perfectly. Thank you

1 Like