Insert a new InstanceDefinition of a Block into document


I was wondering if I could ask you regarding some sample code you posted back in 2018 that might be obsolete or changed.

Here you specify how to insert a block instance into the document.
I can’t find a method called InsertBlock in the RhinoCommon API.

I basically have some blocks defined in the BlockManager and I want to place them around in my model with some transformations and attributes.

Do you have any information that can help?

RhinoScript in VB was ported to the rhinoscriptsyntax package in Python. InsertBlock is available there:

If you have a look at its source code, you can also see it uses the RhinoCommon method ObjectTable.AddInstanceObject(Int32, Transform)

Thanks :slight_smile:
I see that the source code uses RhinoCommon functions that I can use myself, without resorting to InsertBlock (i.e. I can just use what ever is in that function).

What I am getting from AddInstanceObject(Int32, Transform) is a GUID, which means it was ‘successful’, but no actual Block Instance appeared in the document.

Do you know why this may be…?

You probably need to refresh the display (scriptcontext.doc.Views.Redraw()): rhinoscriptsyntax/ at c49bd0bf24c2513bdcb84d1bf307144489600fd9 · mcneel/rhinoscriptsyntax · GitHub

If you are using Python you can use rhinoscriptsyntax (instead of re-coding it from the RhinoCommon SDK), it will be very close to the RhinoScript VB examples.

Here is the Python example from rhinoscriptsyntax.AddBlock():

import rhinoscriptsyntax as rs
objs = rs.GetObjects("Select objects to define block")
if objs:
    point = rs.GetPoint("Block base point")
    if point:
        block = rs.AddBlock(objs, point, None, True)
        rs.InsertBlock(block, point)
1 Like

I’m using Python but outside GH, using rhinoinside.

I am executing the code inside of the InsertBlock and InsertBlock2 functions, which already includes:

if id!=System.Guid.Empty:

(I am using here file.Views.Redraw() to the same effect)
Shouldn’t this work as you suggest or am I missing something…?

Hi @Yafim_Simanovsky,

We’ll probably need to see code and have instruction on how to repeat what you are (not) seeing.

What are you running Rhino in?

– Dale

I am using Hops service, so after playing with it, I think the issue is solved using the .Save() on the RhinoDoc.

For those following this thread, here are Python versions of the RhinoScript samples that were linked above. (805 Bytes) (533 Bytes)

– Dale