Grasshopper

algorithmic modeling for Rhino

Been looking around for a while with the interest of Nested blocks through C#.  From what I can tell, is impossible wihtout exploding the nested block into its base geometry... 

Any modification to the instance definition table only accepts a GeometryBase as in input on what can be added, making a nested block impossible.  Some form of this...

InstanceDefinition.Add(string, string, point, GeometryBase, ObjectAttributes )

Can someone confirm this for me?

Views: 1372

Replies to This Discussion

InstanceReferenceGeometry inherits from GeometryBase - so you can just add other blocks to your instance definition along with any other geometry. If you're working with an existing block instance, you'll need to use the InstanceReferenceGeometry constructor - which accepts the definition Guid and the transform, which you can get off the existing instance. 

Thank you both for your reply!

Would either InstanceDefinitionGeometry or InstanceReferenceGeometry nest the block, or would it only place the raw geometry within the block?  I need to maintain the nested block's association with the InstanceDefinitionTable.

Use instancereferencegeometry. It will be the same as nesting a block.

I have never used InstanceReferenceGeometry or InstanceDefinitionGeometry before.  

How do I assign a blocks geometry to each?  

is it simply something like this?

InstanceReferenceGeometry [] myGeom = InstanceReferenceGeometry(System.Guid, Transform);

If you have an existing block instance somewhere, you need to get the id of its definition, and then the transform it's been placed with. See below:



private void RunScript(Guid x, object y, ref object A)
{
//Get a reference to the block in Rhino. Easiest thing is to hook up a GUID parameter
//and right click choose "set one Guid" and pick the block object in Rhino.
InstanceObject blockInstanceInRhino = RhinoDocument.Objects.Find(x) as InstanceObject;
//create a new InstanceReferenceGeometry
InstanceReferenceGeometry IRG = new InstanceReferenceGeometry(blockInstanceInRhino.InstanceDefinition.Id, blockInstanceInRhino.InstanceXform);
//Add the new block to the Rhino Document's Instance Definition Tables
RhinoDocument.InstanceDefinitions.Add("Example Nested Block", "Example", Point3d.Origin, IRG, RhinoDocument.CreateDefaultAttributes());

}

Thats for the help thus far!  

I have been playing around with InstanceReferenceGeometry a little, and below is what I have gotten so far.  It works great if I only select one object in Rhino, but how do i include multiple nested blocks?  They are all in the list "myIRG", so I could think I would just change the "myIRG[0]" to "myIRG", but that fails.  

{

  if(run)
    return;
  //Restarts script on button toggle

  List<InstanceReferenceGeometry> myIRG = new List<InstanceReferenceGeometry>();
  // Creates Empty list of InstantReferenceGeometry
  List <Rhino.DocObjects.RhinoObject> SelectedObjects = new List<Rhino.DocObjects.RhinoObject>(doc.Objects.GetSelectedObjects(false, false));
 // Selects Rhino Objects (As Many as Highlighted)

  int i = 0;
  while(i < SelectedObjects.Count)
  {
    System.Guid tempGuid = SelectedObjects[i].Id;
    //create a new InstanceReferenceGeometry
    InstanceObject blockInstanceInRhino = RhinoDocument.Objects.Find(tempGuid) as InstanceObject;
    // Add the new block to the Rhino Document's Instance Definition Tables
    InstanceReferenceGeometry tempIRG = new InstanceReferenceGeometry(blockInstanceInRhino.InstanceDefinition.Id, blockInstanceInRhino.InstanceXform);
    // Creates Temporary InstanceReferenceGeometry of each individual block selected
    myIRG.Add(tempIRG);
    // Adds all InstanceReferenceGeometry sets to a single list
    i++;
  }

  RhinoDocument.InstanceDefinitions.Add("Example Nested Block", "Example", Point3d.Origin, myIRG[0], RhinoDocument.CreateDefaultAttributes());

}

the "InstanceDefinitions.Add" method has an overload to accept a List<GeometryBase> and a List<ObjectAttribute>

Ah! Totally missed that!  Thanks a ton! Lifesaver!

Out of curiosity, could you give me an example of how to use InstanceDefinitionGeometry 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service