I’m having a new (since my last post) problem with the BooleanSplit.py
script. I’ve posted the script, along with my modifications to it (identified by comments starting with #mbmast
and the calling code to invoke the script:
import rhinoscriptsyntax as rs
import scriptcontext
import Rhino
def MySplit(sObjToCut, sCutter):
aObjToCut = rs.ObjectsByName(sObjToCut)
aCutter = rs.ObjectsByName(sCutter)
for objToCut in aObjToCut:
for cutter in aCutter:
BooleanSplit(objToCut, cutter)
def BooleanSplit(input0, input1, delete_input=True):
"""Performs a boolean split operation on two sets of input surfaces
and polysurfaces. For more details, see the BooleanSplit command in
the Rhino help file
Parameters:
input0 ([guid, ...]): list of surfaces to subtract from
input1 ([guid, ...]): list of surfaces to be subtracted
delete_input (bool, optional): delete all input objects
Returns:
list(guid, ...): of identifiers of newly created objects on success
None: on error
Example:
import rhinoscriptsyntax as rs
filter = rs.filter.surface | rs.filter.polysurface
input0 = rs.GetObjects("Select first set of surfaces or polysurfaces", filter)
if input0:
input1 = rs.GetObjects("Select second set of surfaces or polysurfaces", filter)
if input1: rs.BooleanSplit(input0, input1)
See Also:
BooleanDifference
BooleanIntersection
BooleanUnion
"""
if type(input0) is list or type(input0) is tuple: pass
else: input0 = [input0]
if type(input1) is list or type(input1) is tuple: pass
else: input1 = [input1]
breps0 = [rs.coercebrep(id, True) for id in input0]
breps1 = [rs.coercebrep(id, True) for id in input1]
tolerance = scriptcontext.doc.ModelAbsoluteTolerance
newbreps = Rhino.Geometry.Brep.CreateBooleanSplit(breps0, breps1, tolerance)
if newbreps is None: return scriptcontext.errorhandler()
rc = [scriptcontext.doc.Objects.AddBrep(brep) for brep in newbreps]
#mbmast added check for emptiness
if not rc:
return rc
#mbmast - kludge, I'm sure there's a better way to do this.
for newObj in rc:
rs.ObjectName(newObj, rs.ObjectName(input0))
if delete_input:
for id in input0: scriptcontext.doc.Objects.Delete(id, True)
#mbmast don't delete the cutter
#for id in input1: scriptcontext.doc.Objects.Delete(id, True)
scriptcontext.doc.Views.Redraw()
return rc
if __name__ == "__main__":
# call the function defined above
#MySplit("Block", "Plane")
MySplit("RectTrackInteriorWide", "ShellEyeExterior")
MySplit("RectTrackInteriorWide", "ShellTrackOverhangInterior")
MySplit("RectTrackExterior", "ShellEyeExterior")
MySplit("RectTrackExterior", "ShellTrackOverhangExterior")
aObjToSubtractFrom = rs.ObjectsByName("RectTrackExterior")
aObjToSubtractWith = rs.ObjectsByName("RectTrackInteriorWide")
for objToSubtractFrom in aObjToSubtractFrom:
if not rs.IsObjectNormal(objToSubtractFrom):
continue
if not rs.IsObjectValid(objToSubtractFrom):
continue
for objToSubtractWith in aObjToSubtractWith:
if not rs.IsObjectNormal(objToSubtractWith):
continue
if not rs.IsObjectValid(objToSubtractWith):
continue
print "sub from type: " + str(rs.ObjectType(objToSubtractFrom)) + ", sub with type: " + str(rs.ObjectType(objToSubtractWith))
rs.BooleanDifference(objToSubtractFrom, objToSubtractWith)
The problem I’m having is:
Message: e1d89d15-db0d-4f7a-80a4-9cd40b2f5dfb does not exist in ObjectTable
Traceback:
line 1065, in coercerhinoobject, "C:\Users\mbmas\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py"
line 1364, in ObjectType, "C:\Users\mbmas\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\object.py"
line 126, in <module>, "C:\Users\mbmas\Documents\3D Objects\Martian Eye\MyScript.py"
Line 126, in my calling code, is the print
statement.
What does it mean when an object does not exist in the ObjectTable?