The script works when passing objs as a list of Guids (without for loop) to the addBlock function, turning all polysurfaces into a single block. The addblock definition actually says that the function takes an array as first parameter but trying to put the Guid into list within the for loop ends also with error “Guid is not iterable”
Hints are much appreciated, thanks.
I’m getting rhino models from a colleague every now and then and then do further editing in sketchup. If polysurfaces are exported to sketchup, you end up with bunch of unconnected surfaces and edges, while blocks become components, hence much easier editing in sketchup.
Not the ideal solution but I ended up with rewriting the original AddBlock method for a single Guid
and adding it to a new module (eg “myCustomModule”) within the Rhino app content folder.
run this in atom:
import rhinoscriptsyntax as rs
objs = rs.ObjectsByType(16, False)
for obj in objs:
point = (0, 0, 0)
block = rs.AddBlockForSingleObject(obj, point, None, True) # my rewritten function
rs.InsertBlock(block, point)
the new module function:
def AddBlockForSingleObject(id, base_point, name=None, delete_input=False):
base_point = rhutil.coerce3dpoint(base_point, True)
if not name:
name = scriptcontext.doc.InstanceDefinitions.GetUnusedInstanceDefinitionName()
found = scriptcontext.doc.InstanceDefinitions.Find(name, True)
objects = []
obj = rhutil.coercerhinoobject(id, True)
if obj.IsReference: return
ot = obj.ObjectType
if ot==Rhino.DocObjects.ObjectType.Light: return
if ot==Rhino.DocObjects.ObjectType.Grip: return
if ot==Rhino.DocObjects.ObjectType.Phantom: return
if ot==Rhino.DocObjects.ObjectType.InstanceReference and found:
uses, nesting = obj.UsesDefinition(found.Index)
if uses: return
objects.append(obj)
if objects:
geometry = [obj.Geometry for obj in objects]
attrs = [obj.Attributes for obj in objects]
rc = 0
if found:
rc = scriptcontext.doc.InstanceDefinitions.ModifyGeometry(found.Index, geometry, attrs)
else:
rc = scriptcontext.doc.InstanceDefinitions.Add(name, "", base_point, geometry, attrs)
if rc>=0:
if delete_input:
for obj in objects: scriptcontext.doc.Objects.Delete(obj, True)
scriptcontext.doc.Views.Redraw()
return name