file name expression

file name expression

simeonX24F9
Contributor Contributor
1,206 Views
5 Replies
Message 1 of 6

file name expression

simeonX24F9
Contributor
Contributor

hello

 

does somebody know the file name expression? 

 

i want to have the name of the file i am working on always show up in program comment on a new setup......

Capture.PNG

1,207 Views
5 Replies
Replies (5)
Message 2 of 6

JeromeBriot
Mentor
Mentor

Hello,

 

Try this example:

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

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

        docName = app.activeDocument.name

        ui.messageBox(docName)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 3 of 6

simeonX24F9
Contributor
Contributor
This doesn't seen to work. And it doesn't stay. Next time I go to edit it is
gone
0 Likes
Message 4 of 6

JeromeBriot
Mentor
Mentor

I should have read your post more carefully before replying.

AFAIK, it's not possible to use the API to populate a opened dialog.

 

0 Likes
Message 5 of 6

chris.r.schroeder
Participant
Participant

Did you ever find a way to do this?  I have been looking for the same thing.  It would be immensely more maintainable to have CAM files matching the part name perhaps concatenated with the setup name automatically. 

0 Likes
Message 6 of 6

BrianEkins
Mentor
Mentor

Here's a little script that should do it.

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

def run(context):
    app = adsk.core.Application.get()
    ui = app.userInterface
    try:
        # Get the design from the active document.
        doc = app.activeDocument
        des: adsk.fusion.Design = doc.products.itemByProductType('DesignProductType')
        cam: adsk.cam.CAM = doc.products.itemByProductType('CAMProductType')

        # Get the first setup in Manufacturing.
        setup = cam.setups[0]

        # Get the parameter for the program comment.
        param = setup.parameters.itemByName('job_programComment')

        # Change the value to the same name as the document.
        stringVal: adsk.cam.StringParameterValue = param.value
        stringVal.value = doc.name        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com