Pocket 2d operation causes Fusion 360 to crash

Pocket 2d operation causes Fusion 360 to crash

omedvydskiy
Participant Participant
895 Views
4 Replies
Message 1 of 5

Pocket 2d operation causes Fusion 360 to crash

omedvydskiy
Participant
Participant

Hi, I am creating a 2d pocket operation for my setup and it cause the Fusion 360 crash. I am trying to add selected face (Planar face with id 52) as a pocket selection to the pocket operation.

It crashes on line "pocketSel.inputGeometry = [face]"

The same via UI looks successful.

 

    input = setup.operations.createInput('pocket2d')
    input.tool = tool  
    input.displayName = 'Pocket 2D'

    # Get the "pockets" parameter from the operation, which is a CAD Contour 2D.
    # The name of the parameter will vary depending on the type of operation.
    contourParam: adsk.cam.CadContours2dParameterValue = input.parameters.itemByName('pockets').value

    # Get the CurveSelections object from the CAD contour. This
    # object manages the list of contour selections.
    curveSelections = contourParam.getCurveSelections()

    # Create a new pocket selection.
    pocketSel: adsk.cam.PocketSelection = curveSelections.createNewPocketSelection()

    # Set some properties of pocket contour.
    pocketSel.isSelectingSamePlaneFaces = False

    # Add the selected face to the face contour.
    pocketSel.inputGeometry = [face]

    # Apply the curve selection back to the parameter.
    contourParam.applyCurveSelections(curveSelections)
 
    op = setup.operations.add(input)

omedvydskiy_0-1691400688549.png

Accepted solutions (1)
896 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor
Accepted solution

Hi @omedvydskiy -San.

 

Similar errors have been reported in the past.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/fusion-cam-api-pocket2d-input-parameter-er... 


Currently the only way seems to be to use CurveSelection.

・・・
    # Get the CurveSelections object from the CAD contour. This
    # object manages the list of contour selections.
    curveSelections = contourParam.getCurveSelections()

    # Create a new pocket selection.
    # pocketSel: adsk.cam.PocketSelection = curveSelections.createNewPocketSelection()

    # Set some properties of pocket contour.
    # pocketSel.isSelectingSamePlaneFaces = False

    # Add the selected face to the face contour.
    # pocketSel.inputGeometry = [face]

    # Select Face Edge.
    chain: adsk.cam.CurveSelection = curveSelections.createNewChainSelection()
    chain.isReverted = True
    chain.inputGeometry = [face.edges[0]]

    # Apply the curve selection back to the parameter.
    contourParam.applyCurveSelections(curveSelections)
・・・
Message 3 of 5

omedvydskiy
Participant
Participant
Thank you for your reply.
Message 4 of 5

echatzief
Advocate
Advocate

Hi Kandennti, hope you're doing great!

I noticed in line 17 you're setting the reversion of the chain selection to True, using the isReverted method from the api, but how can one tell if it be True since it only depends on Fusion's guess (see image attached) ?

Thank you!

 

0 Likes
Message 5 of 5

kandennti
Mentor
Mentor

@echatzief -San.

 

I simply ran the test code and ture the isReverted method because it was the other side.
Perhaps there are some rules, but I have not looked into them.

 

Since the April update, I feel that the CAM API has added enough functionality for automation.
I feel that now we need a technique to find and determine the required geometry in CAD.

 

Also, in this case, I think it is possible to get the same results by using a 3D Pocket instead of a 2D Pocket.
In the case of the 3D Pocket, the CAD data geometry is automatically used to make decisions, which should make it easier to think about the area.
In this regard, the choice of operation should also be important.

0 Likes