Block instance copy issue

Hi All,

Have a small issue with the following script:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext

#copy a block instance in place with new name
filter = rs.filter.instance
id = rs.GetObject('Select block instance to copy in place', filter)

basePt = rs.BlockInstanceInsertPoint(id)
instName = rs.BlockInstanceName(id)
xform = rs.BlockInstanceXform(id)

expObjIds = rs.ExplodeBlockInstance(id)
newName = rs.GetString('New block instance name (current name: {}'.format(instName))

try:
    rs.AddBlock(expObjIds, basePt, newName, True)
    print 'Added block to document'
except:
    print 'Could not add block to document!'
    
try:
    insertedBlockId = rs.InsertBlock(newName, basePt)
    print 'New block {} was created and inserted at {}'.format(newName, basePt)
except:
    print 'Could not insert new block in model'

The selected block instance is exploded. A new block instance using the objects from the exploded block instance is added to the doc with a new name and original base point. Then it is inserted in the document at the same insertion point.

The script works as expected. But for some reason it is difficult to select and / or zoom to the new selected block. Zooming too close causes it to disappear, as if it’s bounding box were excluded from the current view bounding box in the Display Pipeline. Clicking on it will not select it but a crossing window will.

What do you think is happening?

EDIT: The above only happens if the original block’s base point is NOT at 0,0,0 world origin

Its not clear to me what you are trying to do. But copying a block instance is as simple as copying any other object. For example, run Rhino’s Insert command, to insert a block instance, and then run the Copy command.

Are you trying to copy a block’s (underlying) definition?

This is the scenario:

I often I create a block, move it to a new location and have to make a new block at that location which is ‘derived’ from the original block (i.e. very similar but with some modifications).

To avoid having to manually explode the block, modify the geometry and then create a new block with a new name and base point, I would like to automate this task with the above script ---- first generate a duplicate with a new name, maintaining the base point, then edit the geometry in block edit.

I ran into this same issue programmatically creating blocks with RhinoCommon. [Bug] Blocks created through scripting disappear intermittently

The equivalent RhinoScript seems to work:

Sub Main

	Const RH_BLOCK = 4096
	Dim id, point, name, xform, arr, newname
	
	id = Rhino.GetObject("Select block instance to copy in place", RH_BLOCK)
	point = Rhino.BlockInstanceInsertPoint(id)
	name = Rhino.BlockInstanceName(id)
	xform = Rhino.BlockInstanceXform(id)

	arr = Rhino.ExplodeBlockInstance(id)
	newname = name & "_new"
	
	Call Rhino.AddBlock(arr, point, newname, True)
	Call Rhino.InsertBlock(newname, point)
End Sub

Still digging…

The equivalent RhinoScript seems to work:

Sub Main

	Const RH_BLOCK = 4096
	Dim id, point, name, xform, arr, newname
	
	id = Rhino.GetObject("Select block instance to copy in place", RH_BLOCK)
	point = Rhino.BlockInstanceInsertPoint(id)
	name = Rhino.BlockInstanceName(id)
	xform = Rhino.BlockInstanceXform(id)

	arr = Rhino.ExplodeBlockInstance(id)
	newname = name & "_new"
	
	Call Rhino.AddBlock(arr, point, newname, True)
	Call Rhino.InsertBlock(newname, point)
End Sub

Still digging…

Well, this is a bug. Its been fixed:

http://mcneel.myjetbrains.com/youtrack/issue/RH-29636

Hopefully it will make it into SR11…