Hallo,
I'm new to Fusion and this forum so please tell me if I need to change anything in this question.
The problem I need to solve is how to split an eye model, which is constructed with the Fusion UI and consists of several asymmetric parts, into tiny cubes, like a rubics cube (at a later date probably into radial symmetric parts as well).
At the moment my code generates several construction planes in all three dimensions (see picture one).
My problem is that when I use these construction planes as splitTools to split all the bodies that are part of my eye model there will be planes that don't intersect with some of the bodies. This generates of course an error: "No intersection between target(s) and split tools." which stops the code.
So I had some ideas how to circumvent this problem by:
- checking beforehand if the construction plane and body have an intersection, but I only found such a function for planes and curves.
- somehow catching the error thrown by the split function and telling the program to just continue, no idea how to do that
- or create one combined splitting tool, because that combined splitting tool will have an intersection which each body. But it seems like it's not possible to combine construction planes.
Maybe my code is helpful(its also attached):
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
# Get the root component of the active design
rootComp = design.rootComponent
#Creating construction planes where I want them
#Create a new Sketch on the xy-Plane
sketches = rootComp.sketches
# Make all xyz-Planes known
xyPlane = rootComp.xYConstructionPlane
sketch = sketches.add(xyPlane)
xzPlane = rootComp.xZConstructionPlane
sketch = sketches.add(xyPlane)
yzPlane = rootComp.yZConstructionPlane
sketch = sketches.add(xyPlane)
#-------------------------------
#-------------------------------
#creates new Planes in each of the three directions, in mm steps, since
#the diameter of the eye is about 23mm the loop goes from -15mm to +15mm
#this should be enough to include the 1mm thick eye applicator
#will be used to cut our eye-mdel into several cubes, to be used as
#sensitive scorers
for xyz_planes in [xyPlane, xzPlane, yzPlane]:
for i in range(-15, 16): #cm, will be converted into mm later
# Get construction planes
planes = rootComp.constructionPlanes
# Create construction plane input
planeInput = planes.createInput()
# Add construction plane by offset
offsetValue = adsk.core.ValueInput.createByReal(i/100.)#in mm now
planeInput.setByOffset(xyz_planes, offsetValue)
planeOne = planes.add(planeInput)
#Creating Planes end
# the following is just how it would work in an ideal world
# simply take each body and split it with every possible
# splitting tool and ignore any errors that occur
allBodies = rootComp.bRepBodies
for body in allBodies:
#Splitting
#Create SplitBodyFeatureInput
splitBodyFeats = rootComp.features.splitBodyFeatures
splitBodyInput = splitBodyFeats.createInput(body, planeOne, True) #1: body to be split, 2: SplittingTool, #3:SplittingToolExtended
# Create split body feature
split_ Object = splitBodyFeats.add(splitBodyInput)
#Splitting end
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I would be really thankful for any help regarding this problem. As well as general improvement ideas for my code since I'm a beginner. And is there a way to copy code here and not lose all the indentations?
Greetings,
Saskia
Solved! Go to Solution.