& Construction

Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
& Manufacturing

Professional CAD/CAM tools built on Inventor and AutoCAD
Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
Professional CAD/CAM tools built on Inventor and AutoCAD
Dear Fusion Community,
I have tried to write a code where a setup and a NC output is always created for each visible body.
Currently only setup and NC output should be created and named.
Unfortunately this does not work although no error is displayed. Can you perhaps help me with this?
Thank you very much
import adsk.core
import adsk.fusion
import traceback
def run(context):
try:
# Zugriff auf die aktive Fusion 360-Anwendung
app = adsk.core.Application.get()
ui = app.userInterface
# Zugriff auf das aktive Design
design = app.activeProduct
if not design:
ui.messageBox('Kein aktives Design gefunden. Bitte auf die Konstruktions Seite wechseln')
return
# Zugriff auf die aktive Komponente
root_comp = design.rootComponent
# Zugriff auf alle sichtbaren Körper im Design
bodies = root_comp.bRepBodies
for body in bodies:
# Erstelle ein Setup für jeden Körper
setup_name = f'Setup_{body.name}'
setup = root_comp.manufacturingSetups.addMillSetup(body, setup_name)
# Setze den Namen des Körpers als Setup-Namen
setup.name = body.name
# Erstelle eine NC-Ausgabe mit dem Körpernamen
nc_program_name = f'NC_{body.name}'
nc_program = setup.createNCProgram(root_comp, nc_program_name)
ui.messageBox('Setups und NC-Ausgaben wurden erfolgreich erstellt.')
except Exception as e:
ui.messageBox('Fehler aufgetreten:\n{}'.format(traceback.format_exc()))
run(None)
Solved! Go to Solution.
@patrikrump
Welcome to the Community.
I noticed that your code is in German. If you would feel more comfortable, I can move this post to the German Fusion forum. If you are happy to communicate in English, I can leave it here. Whatever you prefer. 🙂
Did you find a post helpful? Then feel free to give likes to these posts!
Did your question get successfully answered? Then just click on the 'Accept solution' button. Thanks and Enjoy!
Chris Benner
Industry Community Manager – Design & Manufacturing
I don't care about the language.
It's just important to me that many people see it because of the possible help
Hi
This is probably best asked in the API Forum:
https://forums.autodesk.com/t5/fusion-api-and-scripts/bd-p/22
Thank you for moving my post.
unfortunately I have not yet found a solution
Hi @patrikrump -San.
I believe that would be made by chatGPT, etc. It is a pretty disappointing code.
I created a basic sample.
Setup and NC program for each body shown. It is still lacking in functionality.
This can be done from the design workspace.
# Fusion360API Python script
import traceback
import adsk.core as core
import adsk.fusion as fusion
import adsk.cam as cam
import sys
def run(context):
ui: core.UserInterface = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
camObj: cam.CAM = get_cam_product()
rootOcc: fusion.Occurrence = camObj.designRootOccurrence
bodies = get_show_bodies(rootOcc.component)
if len(bodies) < 1: return
for body in bodies:
create_nc_program(
camObj,
create_setup(
camObj,
body
)
)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def create_nc_program(
camObj: cam.CAM,
targetSetup: cam.Setup,
) -> cam.NCProgram:
ncPrograms: cam.NCPrograms = camObj.ncPrograms
ncIpt: cam.NCProgramInput = ncPrograms.createInput()
ncIpt.displayName = targetSetup.name
set_cam_parameter(
ncIpt,
"nc_program_filename",
targetSetup.name,
)
set_cam_parameter(
ncIpt,
"nc_program_openInEditor",
True,
)
ncIpt.operations = [targetSetup]
ncPrograms.add(ncIpt)
def get_show_bodies(
root: fusion.Component
) -> list[fusion.BRepBody]:
bodies = root.findBRepUsingPoint(
core.Point3D.create(0,0,0),
fusion.BRepEntityTypes.BRepBodyEntityType,
sys.float_info.max,
True,
)
return list(bodies)
def create_setup(
camObj: cam.CAM,
targetBody: fusion.BRepBody,
) -> cam.Setup:
setups: cam.Setups = camObj.setups
setupIpt: cam.SetupInput = setups.createInput(
cam.OperationTypes.MillingOperation
)
setupIpt.models = [targetBody]
setup: cam.Setup = setups.add(setupIpt)
setup.name = targetBody.name
set_cam_parameter(
setup,
'job_stockMode',
'default',
)
set_cam_parameter(
setup,
'job_stockOffsetMode',
'keep',
)
return setup
def get_cam_parameter(
camEntity,
name: str,
) -> cam.CAMParameter:
try:
prm: cam.CAMParameter = camEntity.parameters.itemByName(
name
)
if not prm: return None
return prm.value.value
except:
return None
def set_cam_parameter(
camEntity,
name: str,
value: str,
) -> bool:
try:
prm: cam.CAMParameter = camEntity.parameters.itemByName(
name
)
if not prm: return False
prm.value.value = value
return True
except:
return False
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()
kandennti thank you so much for this great help,
The code does what it should, I have to create the appropriate edits depending on the requirements of the furniture.
I have an average of 8 to 12 setups per piece of furniture, so this work is very annoying. Thanks to your script I can concentrate on the work and not on the organization.
Thank you very much
How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
Type a product name