Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Fusion is crashing when I select BrepFaces for boundaries on the setupInput object, but not when I select a sketch object.
import adsk.core, adsk.fusion, adsk.cam, traceback
app = adsk.core.Application.get()
ui = app.userInterface
def run(context):
try:
doc = app.activeDocument
design:adsk.fusion.Design = doc.products.itemByProductType("DesignProductType")
design.workspaces.itemById("FusionSolidEnvironment").activate()
root = design.rootComponent
#create new component and Brep Body
occ = root.occurrences.addNewComponent(adsk.core.Matrix3D.create())
s = occ.component.sketches.add(occ.component.xYConstructionPlane)
s.sketchCurves.sketchLines.addTwoPointRectangle(adsk.core.Point3D.create(-0.5,-0.5,0),adsk.core.Point3D.create(0.5,0.5,0))
extrudes = occ.component.features.extrudeFeatures
exFeature = extrudes.addSimple(s.profiles.item(0),adsk.core.ValueInput.createByReal(1),adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
body = exFeature.bodies.item(0)
body.name = "Body"
#activate CAM
ui.workspaces.itemById("CAMEnvironment").activate()
cam:adsk.cam.CAM = doc.products.itemByProductType('CAMProductType')
#Get the occurence and body in CAM workspace
cadRoot = cam.designRootOccurrence.component
occurrence = cadRoot.occurrences.item(0)
stockBody = occurrence.component.bRepBodies.itemByName("Body")
#get lowest face
stockFaces = []
for face in stockBody.faces:
stockFaces.append(face)
sortedList = sorted(stockFaces,key=lambda face: face.centroid.z) #default is ascending
lowestFace:adsk.fusion.BRepFace = sortedList[0].createForAssemblyContext(occurrence)
#create a new setup
setups = cam.setups
setupInput = setups.createInput(adsk.cam.OperationTypes.MillingOperation)
setupInput.stockMode = adsk.cam.SetupStockModes.SolidStock
setupInput.stockSolids = [stockBody]
setup = setups.add(setupInput)
#Create a new operation
operations = setup.operations
operationInput = operations.createInput("pocket_clearing")
parameters = operationInput.parameters
#Get the boundary parameter
parameters.itemByName("boundaryMode").value.value = 'selection'
boundary:adsk.cam.CadContours2dParameterValue = parameters.itemByName("machiningBoundarySel").value
curveSels: adsk.cam.CurveSelections = boundary.getCurveSelections()
# WORKS - set the sketch to be the boundary
if False:
sel = curveSels.createNewSketchSelection()
sel.inputGeometry = [s]
boundary.applyCurveSelections(curveSels)
# WORKS - set the edges of the face to be the boundary
if False:
sel = curveSels.createNewChainSelection()
sel.inputGeometry = [edge for edge in lowestFace.edges]
boundary.applyCurveSelections(curveSels)
# CRASH - set the face to be the boundary
if True:
sel = curveSels.createNewFaceContourSelection()
sel.inputGeometry = [lowestFace]
boundary.applyCurveSelections(curveSels)
#add the operation to the setup
operations.add(operationInput)
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.