Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Fusion CAM API Failed to set up stock body

1 REPLY 1
SOLVED
Reply
Message 1 of 2
karolis.s
123 Views, 1 Reply

Fusion CAM API Failed to set up stock body

Hello, I am creating a stock for parts in API. The simplest way to do this is to create a new body and use it as a stock.

Here is my code:

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        doc = Doc()

        setups = doc.cam.setups
        # Create a SetupsInput object to define a milling setup.

        setupInput = setups.createInput(adsk.cam.OperationTypes.MillingOperation)
        setupInput.models = [doc.body]
        setupInput.name = 'TestSolidSelect'

        stockModeParam = setupInput.parameters.itemByName('job_stockMode')
        stockModeParam.expression = '\'solid\''

        stockSolidParam: adsk.cam.CadObjectParameterValue = setupInput.parameters.itemByName('job_stockSolid')
        stockSolid = doc.cam.designRootOccurrence.bRepBodies[1]
        stockSolidParam.value = [stockSolid]

        setup = setups.add(setupInput)



    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


class Doc:
    def __init__(self):
        app = adsk.core.Application.get()
        ui  = app.userInterface
        productType = app.activeProduct.productType

        # root component
        self.rootC = None
        self.body: adsk.fusion.BRepBody = None

        if productType == 'CAMProductType':
            cam: adsk.cam.CAM = app.activeDocument.products.itemByProductType('CAMProductType')
            camOcc = cam.designRootOccurrence
            self.rootC = camOcc.component
            self.body = camOcc.bRepBodies[0]
            self.cam: adsk.cam.CAM = cam
        elif productType == 'DesignProductType':
            design = app.activeProduct
            self.rootC = design.rootComponent
            self.body = self.rootC.bRepBodies.item(0)

        if self.rootC == None or self.body == None:
            ui.messageBox('Active product is not Design or CAM product')
            return    

 

Here is the error I get:

karoliss_0-1689546780853.png


I tried all the combinations that came to my mind. Any ideas?



1 REPLY 1
Message 2 of 2
kandennti
in reply to: karolis.s

Hi @karolis.s -San.

 

Try this.

・・・
        stockSolidParam: adsk.cam.CadObjectParameterValue = setupInput.parameters.itemByName('job_stockSolid')
        stockSolid = doc.cam.designRootOccurrence.bRepBodies[1]
        stockSolidParam.value.value = [stockSolid]
・・・

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report