Grasshopper

algorithmic modeling for Rhino

I seem to be having a lot of issues, all stemming from casting between the three of these.  Here is an example of what I'm Struggling with... 

I have an Instance Definition, and want to get all of its objects... so I Do this:

string defName = "Block_01";
Rhino.DocObject.RhinoObject[] defObjs;

Rhino.DocObject.InstanceDefinition myDef = doc.InstanceDefenitions.Find(defName,false);

defObjs = myDef.GetObjects();

That works great.  I have a bunch of objects in an array.  But now, I want to see which of those objects are nested Blocks... so I Do this:

List<bool> isInstObj = new List<bool>();

int defObjsCount = 0;

while (defObjsCount < defObjs.Count())

{

  if(defObjs[defObjsCount].GetType().Name == "InstanceObject")

    isInstObj.Add(true);

  else

    isInstObj.Add(false);

  defObjsCount++;

}

Still Goes great.  I have a list of booleans telling me if it is an Instance Object.  Now I want to get the Instance Attributes of the Instance Objects (such as InsertionPoint, InstanceXform, and Instance Definition).  Not to be confused with the Rhino Attributes.  But I cannot get the Instance Attributes because it is still of Type RhinoObject.  Here is what I want to do (but cant figure out how to):


List<Point3d> instIP = new List<Point3d>();
List<Rhino.DocObjects.InstanceDefinition> instDef = new List<Rhino.DocObjects.InstanceDefinition>();
List<Transform> instTrans = new List<Transform>();

defObjsCount = 0;

while (defObjsCount < defObjs.Count())

{

  if (isInstObj[defObjsCount] = true)

  {
    instIP.Add(defObjs[defObjsCount].InsertionPoint);
    instDef.Add(defObjs[defObjsCount].InstanceDefinition);
    instTrans.Add(defObjs[defObjsCount].InstanceXform);

  }

  defObjsCount++;

}

But that doesn't work, Because of the casting issue.  This is my end goal, and if I can figure this out, I think it would solve a lot of my confusion.  If there is a better or alternative way to do this, I'm up for anything!  Any help would be appreciated.

Thanks in advance!

Views: 437

Replies to This Discussion

It may be best if you post this on our discourse forum. This is a pure RhinoCommon SDK question after all, and all the SDK programmers hang out there rather than here.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2025   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service