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: 

Rename an active document (Part File) using a Python script

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
isocam
179 Views, 2 Replies

Rename an active document (Part File) using a Python script

Can anybody help?

 

Is it possible to rename the currently active fusion 360 document (Part File) using a Python script?

 

For example,

 

Say I have a part currently open called "TEST-A", can I change its document name to "TEST-B"???

 

Many thanks in advance!

 

Darren

2 REPLIES 2
Message 2 of 3
Rushikesh.kadam
in reply to: isocam

@isocam Below is the code that will change the name of the active document.

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

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        doc = app.activeDocument
        ui.messageBox(f"Name of the document before renaming: {doc.name}")
        doc.name  = "NewName"
        ui.messageBox(f"Name of the document after renaming: {doc.name}")

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

------------------------------------------------------------------------------------------------------------------------------

If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed.




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


Message 3 of 3
BrianEkins
in reply to: isocam

I happened to be looking at this a couple of weeks ago and here's what I found. 

  • You can edit the document's name using the Document.name property IF the document has not been saved. The name you provide will be the default name in the dialog when the user saves the document. They can edit this name in the dialog to whatever they want.
  • If the document has been saved, you can still set the name using the Document.name property, but Fusion will ignore this change and set it back to the saved name. The API should document this behavior and should probably fail in that case because you're doing something that is not supported.
  • Because the file has been saved, the file on the cloud is the master copy. To change the name you need to change that name. You can do that with the code below, where "doc" is the variable name referencing a Document object.

 

doc.dataFile.name = 'New Name'​

The code above will fail if the document has not been saved because there isn't a DataFile for it.

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

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