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: 

Script to automatically populate file name with operation notes when post processing.

1 REPLY 1
Reply
Message 1 of 2
jameswVTJ5V
198 Views, 1 Reply

Script to automatically populate file name with operation notes when post processing.

Hi all,

 

Is there a way to automatically populate the file name with the contents of an operation's notes when post processing?

 

So I usually have a setup/s with various operations. Due to tech restrictions I have to post process each operation separately and rename them with an appropriate file name in the post dialog.

 

To make sense of them I create a file name in the operation notes and copy that into the file name when posting eg operation 1 notes might contain "SH1-SS-OP1" and file name is entered manually as "SH1-SS-OP1". The content of the notes is also used in the setup sheet to identify the operation and thus which files need to be machined in order.

 

A way to automate this would be awesome for 2 reasons. 1 it is tedious doing it manually and 2 (more importantly) it would eliminate errors when editing the file name. Is this achievable using a script?

 

Unfortunately I am no coder so if anyone is able to help that would be fantastic!

 

TIA

1 REPLY 1
Message 2 of 2
kandennti
in reply to: jameswVTJ5V

Hi @jameswVTJ5V -San.

 

Words alone may not be what is intended.
Especially for CAM, since there are many setting items, it is most desirable to have the data attached.


This is a script that sets the first operation NOTES of the NC program that has already been created to the file name of the NC program.

1.png

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.cam as cam

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

        camObj: cam.CAM = get_cam_product()
        ncPros: cam.NCPrograms = camObj.ncPrograms
        if ncPros.count < 1: return

        infos = []
        for ncPro in ncPros:
            opes: cam.Operations = ncPro.operations
            if len(opes) < 1: continue

            ope: cam.Operation = opes[0]
            if ope.classType() == cam.Setup.classType():
                ope = ope.operations[0]

            fName = get_cam_parameter(
                ncPro,
                "nc_program_filename",
            )

            notes = ope.notes
            if len(notes) < 1: continue

            set_cam_parameter(
                ncPro,
                "nc_program_filename",
                notes,
            )

            infos.append(f"{fName} -> {notes}")

        ui.messageBox("\n".join(infos))

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


def get_cam_parameter(
        camEntity,
        name: str,
):
    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()
    activate_cam_env()

    return app.activeProduct


def activate_cam_env() -> None:
    app: core.Application = core.Application.get()
    ui: core.UserInterface = app.userInterface

    camWS: core.Workspace = ui.workspaces.itemById('CAMEnvironment') 
    camWS.activate()

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

Post to forums  

Autodesk Design & Make Report