I want to select the block to enlarge, help me, write C# code ?

Block.gh (44.3 KB)

If you don’t mind to use a plugin, here is one way using elefront plugin.

Block_re.gh (49.1 KB)

Hi, I find this is a interesting topic and I have a question: What would be the equivalent to:Rhino.RhinoDoc.ActiveDoc.Objects.AddInstanceObject(def.Index, scale)
Do I need to get all the geometry scale it and pack it back into a block or is it there a simpler way?

Thanks and regards

private void RunScript(bool Bake, string BlockName, List BlockGeom, Point3d BlockOrigin, Point3d BasePoint, ref object Info, ref object A)

// Ends Script if Bake isnt True
if (!Bake)

// Looks for duplicate name
Rhino.DocObjects.InstanceDefinition DelBlock = doc.InstanceDefinitions.Find(BlockName, false);

// Deletes Duplicate Block
if(DelBlock != null)
  doc.InstanceDefinitions.Delete(DelBlock.Index, true, true);

// Creates Block
int index = doc.InstanceDefinitions.Add(BlockName, "description", BlockOrigin, BlockGeom);

// Creates a Z Vector
Vector3d Zvec = new Vector3d(0, 0, 1);

// Creates a plane with a Basepoint and Z Vector
Plane BasePlane = new Plane(BasePoint, Zvec);

// SOmething to do with referencing a block in rhino
Rhino.DocObjects.InstanceDefinition Bdef = RhinoDocument.InstanceDefinitions.Find(BlockName, true);

// creates variable to hold atributes (atts) and sets it to the defualt atributes in the file
ObjectAttributes atts = RhinoDocument.CreateDefaultAttributes();

// modifies the variable (atts) and gives it the (BlockName) variable
atts.SetUserString(BlockName, Component.ComponentGuid.ToString());

// creates a variable (Trans) that is the transformation between the world 0,0,0 and a referenced plane
Transform Trans = Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, BasePlane);

// I think this creates something in Rhino, Maybe bakes it?
Info = RhinoDocument.Objects.AddInstanceObject(Bdef.Index, Trans, atts);
A = Rhino.RhinoDoc.ActiveDoc.Objects.AddInstanceObject(def.Index, scale);

// battery red

it would help if you would explain what you’re trying to do. The code you posted doesn’t make much sense - it refers to variables that have never been defined (scale, def for instance). Do you just want to define a block, and insert it somewhere with a scale transform?

Hi @andheum,

thanks for the reply and I am really sorry for the missing information.

I know how to scale a Block and place it in the Rhino Document, like this:

private void RunScript(string block, double factor, Plane plane, ref object A)
    InstanceDefinition def = Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions.Find(block);
    Transform scale = Transform.Scale(plane.Origin, factor);
    Rhino.RhinoDoc.ActiveDoc.Objects.AddInstanceObject(def.Index, scale);

Now I would like to know how it is possible as HS_Kim showed with the Elefront Plugin, to do the same in C#

I tried to apply the scale on the the InstanceDefintion, but Transform is not possible.

When I output the InstanceDefintion in A I get an error message on the Scale component:

So I am asking me to what type casts Elfront, or how is this possible.

I hope I was clearer this time,and again, thanks for your effort.


20190223_BlockCast.gh (6.6 KB)

Do it that way:

How to use it?

Block.gh (51.1 KB)

As far as I understand it adds the blocks to the Rhino document, but maybe I just dont get it.

How did you convert the screenshot to text?I have never seen this, and I assume you didnt typed it :smiley:

OK, I’ll provide a full C# demo on that matter soon (i.e. get the List of instances available, pick one by index and then having a bunch of trans on hand … do whatever you want).

In the mean time:

  1. Instance definitions are “static” in the sence that you can’t modify them (for good reason: they are just the cookie cutters for the cookies). Imagine having lot’s of nested (as in real-life) instance defs … and doing havoc on them that way. If on the other hand you want to create a variant of a given instance def (or vary the anchor point etc etc) … well … that’s another animal (notify if you need to include that to the demo).

  2. If you want to apply a trans on an instance def … then you do it at placement time (in the Active Doc: that does the doc.Objects.AddinstanceObject(…)). This means that the objects placed (the cookies from the cookie cutter) are added (as Baris observed) to the R file and no baking - obviously - is required. So we have cookies that are identical with regard the data structure with the donor cookie … plus a transformation (per placed cookie) that varies the “look” of it.

Am looking forward toQQ%E5%9B%BE%E7%89%8720190226140756

Today IS the happy bunny day

Instances_place_12_V1.gh (133.5 KB)
Instances_place_12_V1.3dm (1.5 MB)

This is one of my (about 50) defs used to measure GPU performance: how fast can R place 1K Instances? (CPU is not an issue - for the likes of I7, I9, Ryzen etc etc).

So the 2 top most C#'s create a random collection of axis and the transformations required for placing AND transforming the instance in question. Since these axis are “linear” the demo instances used are “linear” as well.

The middle C# reports what instances are available and allows you to pick one (Note: on purpose 2 out of 3 have wrong orientation: the most important thingy in assembly/component modeling is the right orientation/pivot etc etc).

The last does the job: For using your data you must provide a matching collection (tree) of planes and transformations (and obviously an ID name).

Of course R is not an app for doing that type of stuff in real-life … but we don’t live in real-life anyway.


And here comes the pain: How many dollars have you spend for your gear? That’s the 1Z question (Note: use any R file with instances).

Instances_place_GPUCPUtests_35_V1.gh (156.8 KB)

This works in 3 modes (workMode var):

  1. Either provide valid (not Point3d.Unset) points and instances are placed there
  2. Or provide valid planes (that does the first C# as a demo). DO NOT use the big mesh if you are not a big spender on firmware: Reason is that Rhino does the placement of 5K things very fast … but the big question is: can your GPU cut the mustard (in Rendered viewport mode) properly ??? (We live once: hit the bank and go for SLI NVidia Kepler Quadros 4/5/6)
  3. Or provide a valid BrepFace and things (for count: use Instances ) are placed randomly .

You can control what sort of trans is used for the placement (rotation, scale etc). Test it with some happy bunnies ID (as meshes) or use a proper T-Rex heavy ID mesh (only for the very brave).

NOTE: After placement if you want to delete’m all just disable the last C#. If you don’t do that … well … any change that happens in any slider anywhere … yields more instances in the Active document (the same or different). Anyway … If for any reason you have multiple placements you should pick a loaded one by index and then disable the C# (that deletes all the instances present with the same name). Of course you can delete’m the manual way.

Moral: hit the bank.