Modify Block (with nested blocks) using Rhinocommon

For some reason the following code is failing. I am attempting to modify a block that contains nested blocks, to remove anything that isn’t a nested block instance.

	block = r.RhinoDoc.ActiveDoc.InstanceDefinitions.Find(name)
	idefIndex = block.Index
	oldGeom = block.GetObjects()
	newGeom = []
	newAttr = []
	for oldObj in oldGeom:
		if oldObj.ObjectType == r.DocObjects.ObjectType.InstanceReference:
			idefId = block.Id
			trans = oldObj.InstanceXform
			newObj = r.Geometry.InstanceReferenceGeometry(idefId,trans)
			
			newGeom.append(newObj)
			newAttr.append(oldObj.Attributes)
	
	#modify the instancedef
	res =  r.RhinoDoc.ActiveDoc.InstanceDefinitions.ModifyGeometry(idefIndex,newGeom,newAttr)

Im trying to grasp what is causing this to fail, I do have “linked” nested blocks in places, could this be the cause? Any help/ ideas would be appreciated.

edit: to clarify by failing I mean that the modifyGeometry function is returning “False”

Hi @dks5254

the new InstanceReferenceGeometry should be created from the Id if the internal block object and not the parent block

2 Likes

Let me try this out. thank you!

@Darryl_Menezes Works great now. Thank you. In hindsight it makes much more sense this way. :sweat_smile: