Message 1 of 1
Add machine from the library to the Setup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all!
I'm a total API Newbie and so i'm struggeling to finish my AutoSetupAPI. This API should create a setup. Selects the Model and the fixtures, puts in the WCS and a name and creates a manual NC with my FixtureID. I was able to get this functions to work. Now the only thing I'm don't get to work is to add a machine from my library to my setup. Can anybody help me with that?
Heres my API:
#Fusion360API Python script
import traceback
import adsk.core as core
import adsk.fusion as fusion
import adsk.cam as cam
import os
from enum import Enum
def run(context):
ui: core.UserInterface = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = fusion.Design.cast(product)
#Start
##ui.messageBox('Start Autosetup')
#WCS
WCS = design.userParameters.itemByName('wcs').expression
machine = 'Hedelius RS805-Automation'
ui.messageBox('WCS {} is selected'.format(WCS))
#Get DocumentName
doc = app.activeDocument
docname = app.activeDocument.name
camObj: cam.CAM = get_cam_product()
rootOcc: fusion.Occurrence = camObj.designRootOccurrence
root: fusion.Component = rootOcc.component
# models
modelsOcc: fusion.Occurrence = root.allOccurrences.itemByName("targetBody:1")
if not modelsOcc:
return ui.messageBox('targetBody:1 nicht vorhanden!')
# fixtures:
fixturesOcc: fusion.Occurrence = root.allOccurrences.itemByName("Fixture:1")
if not fixturesOcc:
return ui.messageBox('Fixtures:1 nicht vorhanden')
setup: cam.Setup = create_setup(
camObj,
[modelsOcc],
[fixturesOcc],
)
#Make a few adjustments
programNameParam = setup.parameters.itemByName('job_programName')
programNameParam.expression = "'{}'".format(docname)
programWorkoffsetParam = setup.parameters.itemByName('job_workOffset')
programWorkoffsetParam.expression = WCS
setup.name = docname
machine_select = setup.parameters.itemByName('machine_select')
machine_select.expression = machine
#####TEST MANUAL NC ##########
input = setup.operations.createInput('manual')
setup.operations.add(input)
#ui.messageBox("Done")
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def create_setup(
camObj: cam.CAM,
models: list[core.Base],
fixtures: list[core.Base],
) -> cam.Setup:
setups: cam.Setups = camObj.setups
setupIpt: cam.SetupInput = setups.createInput(
cam.OperationTypes.MillingOperation
)
setupIpt.models = models
setupIpt.fixtures = fixtures
setup: cam.Setup = setups.add(setupIpt)
return setup
def get_cam_product() -> cam.CAM:
app: core.Application = core.Application.get()
activete_cam_env()
return app.activeProduct
def activete_cam_env() -> None:
app: core.Application = core.Application.get()
ui: core.UserInterface = app.userInterface
camWS: core.Workspace = ui.workspaces.itemById('CAMEnvironment')
camWS.activate()