Message 1 of 6
How do you pass selections to cam operation geometery selection?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've attempted to follow this guide but I've yet to get it to work. I am wanting to automatically find and select the top face of my stock body and then pass it to my Face operation.
Holding shift over the selection button reveals the parameter name to be "sel_face_contours". However I keep getting this error:
---------------------------
TestScript
---------------------------
Failed:
Traceback (most recent call last):
File "TestScript.py", line 48, in run
contourParam: adsk.cam.CadContours2dParameterValue = op.parameters.itemByName('sel_face_contours').value
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'value'
---------------------------
OK
---------------------------
import adsk.core
import adsk.fusion
import adsk.cam
import traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.activeDocument
product = doc.products.itemByProductType('DesignProductType')
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
# Find the BRepBody named "Stock"
targetBody = None
# Check for the BRepBody in the root component
for body in rootComp.bRepBodies:
if body.name == 'Stock':
targetBody = body
break
# Find the planar face with the minimum Y coordinate
min_y_face = None
min_y = float('inf')
for face in targetBody.faces:
# Check for planar faces using the corrected enum: PlaneSurfaceType
if face.geometry.surfaceType == adsk.core.SurfaceTypes.PlaneSurfaceType:
bbox = face.boundingBox
# Check the minimum Y-coordinate of the face's bounding box
face_min_y = bbox.minPoint.y
if face_min_y < min_y:
min_y = face_min_y
min_y_face = face
# Get the CAM Product and the specific Setup/Operation
cam_product = doc.products.itemByProductType('CAMProductType')
cam: adsk.cam.CAM = adsk.cam.CAM.cast(cam_product)
setup: adsk.cam.Setup = cam.setups.itemByName('Charles')
op: adsk.cam.Operation = setup.operations.itemByName('Facinghead')
# Get the CadContours2dParameterValue object
contourParam: adsk.cam.CadContours2dParameterValue = op.parameters.itemByName('sel_face_contours').value
# Get the CurveSelections object and clear any previous selections
curveSelections = contourParam.getCurveSelections()
curveSelections.clear()
# Create a new face contour selection
faceContourSel: adsk.cam.FaceContourSelection = curveSelections.createNewFaceContourSelection()
# Set selection properties (common for stock contour)
faceContourSel.isSelectingSamePlaneFaces = False
faceContourSel.inputGeometry = [min_y_face]
contourParam.applyCurveSelections(curveSelections)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))