Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

CAM Avoid Groups API

joshtrim
Explorer

CAM Avoid Groups API

joshtrim
Explorer
Explorer

Hello, I am having trouble fixing my CAM toolpath avoid surfaces script since the September 2024 update. I have gotten to a point where fusion is not giving me any errors, however upon generating my toolpath the avoid group does not show up at all and the script does essentially nothing.

 

The main goal of the script is to find vertical faces on a given body by evaluating the face normals and then adding those faces to an avoid group for an exisiting toolpath. I had gotten a script to do this prior to the update, but haven't been able to figure it out since.

 

Here is the part of the code that introduces the machine avoid group:

verticalWalls = []
surfaceGroupsParam: adsk.cam.CadMachineAvoidGroupsParameterValue = operation.parameters.itemByName('checkSurfaceSelectionSets').value
machineAvoidGroups = surfaceGroupsParam.getMachineAvoidGroups()

machineAvoidGroup: adsk.cam.MachineAvoidDirectSelection = machineAvoidGroups.createNewMachineAvoidDirectSelectionGroup()
machineAvoidGroup.machineMode = adsk.cam.MachiningMode.Avoid_MachiningMode
machineAvoidGroup.radialOffset = .02
machineAvoidGroup.axialOffset = .02

bodyFaces = bRepBody.faces

for face in bodyFaces:
    normal = face.evaluator.getNormalAtPoint(face.centroid)
    normalZ = round(normal[1].z, 10)
    if normalZ == 0:
        verticalWalls.append(face)

machineAvoidGroup.inputGeometry = list(verticalWalls)

cam.generateToolpath(operation)

 

bRepBody is a variable referncing a given body and operation is a variable representing an exisitng toolpath operation.

 

I would greatly appreciate any insight into my issue. Thank you!

 

0 Likes
Reply
Accepted solutions (1)
179 Views
3 Replies
Replies (3)

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

Since there is not model/script to test it, I'd ask:

Is it that you don't see the avoid in the operation configuration or that the faces list is empty?

If it is the latter, did you check verticalWalls is not empty? 

In your snippet code I'd change lines #14 and #15 by:

if abs(normal[1].z) < 1e-10:  # or the max tolerance you need
0 Likes

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi,

 

I believe I found the problem: you just need to call

surfaceGroupsParam.applyMachineAvoidGroups(machineAvoidGroups)

after you set all properties to the newly created avoid group (after line #19 in your snipped code).

 

It worked on my site with this sample design (image taken after running the script then edited the operation):

Jorge_Jaramillo_0-1733336285146.png

 

 

Regards,

Jorge Jaramillo

 

 

0 Likes

Hello Jorge,

 

This solution works exactly how I want it to! I never came across applyMachineAvoidGroups in my searching of the documentation so thank you for being able to solve my problem.

 

Best,

Josh Trimberger

1 Like