Rhino.AddBlock() doesn't seem to exist


The RhinoScript documentation describes an AddBlock method, but when I attempt to use it, I get this error message:

“‘module’ object has no attribute ‘AddBlock’”

I’ve also noticed that Komodo, which normally has autocomplete for RS methods, does not seem to know about this method.

Any suggestions?


(Pascal Golay) #2

Hi Ed - So, you’ve imported the RhinoscriptSyntax at the top of a Python script and are using it that way, is that how you’re getting to this function?

Like so:

import rhinoscriptsyntax as rs




Yes, that’s correct. And I’m calling many other RS methods successfully.

(I’m using Rhino on a Mac)

(Pascal Golay) #4

Yep, got that. Does not show up here either on the mac - thanks for the report.



Given this, I’ve been trying to trying to use rs.Command(“Block…”) as an alternative, but I can’t seem to find the proper way to include the objects to be put in the block. For this piece of code:

    import rhinoscriptsyntax as rs
    obj1 = rs.AddCylinder ([0, 0, 0], [0, 0, 4], 2)
    obj2 = rs.AddCylinder ([3, 4, 0], [3, 4, 6], 2)
    rs.Command("-_Block ???")

How do I include obj1 and obj2 as options in the block command?

(Pascal Golay) #6

I’d deselect all objects, select the desired objects, then run the Rhino command.



I’m trying to build a model consisting of many objects and many blocks using scripting alone. If I have to hand select the objects using the mouse, it renders scripting useless for my purposes. Is there no way to construct a proper _Block command using scripting alone?


You can select the previously referenced elements like this:




Once the objects are selected, you can run your rs.Command and the selected objects will be acted upon.


(Pascal Golay) #9

Sorry, I meant use RS.UnselectAllObjects() and RS.SelectObjects(). I cannot check right at the moment whether these are both implemented in Python but I would think so.



Thanks Mitch and Pascal. That works fine, but now it’s forcing me to give it a description and a URL. I’d rather not have to provide those (they’re supposed to be optional), but even if I want to provide them I can’t seem to figure out the proper syntax:

obj1 = rs.AddCylinder ([0, 0, 0], [0, 0, 4], 2)
obj2 = rs.AddCylinder ([3, 4, 0], [3, 4, 6], 2)
rs.SelectObjects([obj1, obj2])
rs.Command("-_Block 0,0,0 Block1 <what goes here???>")

In the dialog that pops up, I can simply hit “enter” twice to indicate that I don’t want to use those options. Is there someway to insert two "Enter"s at the end of the command to indicate that I don’t want to enter those?

P.S. I have my notifications set to “Watching”, but I’m receiving email notification only for the first reply to my posts, not to any subsequent replies. Is there someway to continue to get notification to subsequent replies?


I am really halted on my project if I cannot create blocks. As I understand it, blocks are the only way to encapsulate several objects so that they can be moved and rotated as a unit.

Am I correct in my understanding of this essential function of blocks? Or is there some other mechanism I can use?

Is there any chance the AddBlock() method will get implemented soon?

In the meantime, can anybody tell me out how to get rs.Command("-_Block ") to work?


(Pascal Golay) #12

Hi Ed-

see also Group for this- and for Blocks, see http://wiki.mcneel.com/rhino/usingblocks

Use _Enter in the command input anytime you’d do that from Rhino to get past an option. Here’s a RhinoScript example I dredged up from my scripts:

Sub BlockSelected()

Dim aObj: aObj = Rhino.GetObjects("Select objects to Block",,, True)
If not IsArray(aObj) then exit sub
dim sObj, sPt

Rhino.EnableRedraw False

For each sObj in aObj
	If not Rhino.IsBlockInstance(sObj) then
		sPt = "W" & Rhino.Pt2Str(Rhino.BoundingBox(sObj, Rhino.WorldXYPlane())(0))
		Rhino.SelectObject sObj
		Rhino.Command "_-Block " & spt & " _Enter _Enter _Enter _Enter", False
	End if

Rhino.EnableRedraw True

End Sub



Thank you @pascal Pascal. I’ve now managed to make blocks, and move/rotate them. But I’m a bit confused by your suggestion of groups as an alternative to blocks. As I understand it, groups (unlike blocks) are not objects, and I can’t seem to find any methods for moving or rotating groups. Am I missing something?


You can simply get all the objects in a group into an array using ObjectsByGroup(groupname) and then use MoveObjects or RotateObjects with that array…


(Pascal Golay) #15

Hi Ed- I was not necessarily suggesting use of Groups for any particular context, I was offering Group an a sort of answer to your comment

“blocks are the only way to encapsulate several objects so that they can be moved and rotated as a unit.”

Groups do that.