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: 

Update drawing references

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
ianjwellings
588 Views, 7 Replies

Update drawing references

Hello,

I'm trying to update a drawing using the updateAllReferences method as follows:

 

app = adsk.core.Application.get()
drawing = adsk.drawing.Drawing.cast(app.activeProduct)
drawing.updateAllReferences()
 
The command fails with the following attribute error:

 

AttributeError: 'Drawing' object has no attribute 'updateAllReferences'

 

Does anyone know if I'm missing something in the code?

 

Have also tried:

 

app = adsk.core.Application.get()
active = app.activeDocument
active.updateAllReferences()

 

Thank you

7 REPLIES 7
Message 2 of 8

@ianjwellings 

This is something the team has worked on and will be supported in one of the upcoming Major releases.

Below code will work in that release.

 

app = adsk.core.Application.get()
active = app.activeDocument
active.updateAllReferences()

 

Regards,




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


Message 3 of 8
kandennti
in reply to: ianjwellings

Hi @ianjwellings .

 

Try this.

# Fusion360API Python script

import traceback
import adsk.core
import adsk.drawing

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

        cmdDef: adsk.core.CommandDefinition = ui.commandDefinitions.itemById(
            'FusionDocUpdateCommand'
        )
        cmdDef.execute()

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

 

 

@ianjwellings .

Will they enhance Draw next to enhance CAM?
That is something to look forward to.

Message 4 of 8

Ok thank you for the update

Message 5 of 8
ianjwellings
in reply to: kandennti

Thank you for this - it worked great.  Do you know if there is also a command to export the drawing as a dxf file?

Message 6 of 8
kandennti
in reply to: ianjwellings

@ianjwellings .

 

Unfortunately, the API does not provide much functionality for Drawing, so the only thing that can be exported is PDF.

Message 7 of 8
ianjwellings
in reply to: kandennti

This command works perfectly for updating the drawing.  I would like to run another function after this command is executed however the function runs before this command has finished.  Is it possible to wait until the drawing update command is finished and then call an export_drawing() function?

 

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

        cmdDef: adsk.core.CommandDefinition = ui.commandDefinitions.itemById('FusionDocUpdateCommand')
        cmdDef.execute()
        ####WAIT FOR COMMAND TO FINISH###
        export_drawing()
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Message 8 of 8
kandennti
in reply to: ianjwellings

@ianjwellings .

 

If you want to perform an update in the middle of a process, you can do so by doing the following.

 

def update_drawing():
    ui = None
    try:
        app = adsk.core.Application.get()
        # ui  = app.userInterface

        # cmdDef: adsk.core.CommandDefinition = ui.commandDefinitions.itemById('FusionDocUpdateCommand')
        # cmdDef.execute()
        app.executeTextCommand(u'Commands.Start FusionDocUpdateCommand')

        ####WAIT FOR COMMAND TO FINISH###
        # export_drawing()
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

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

Post to forums  

Autodesk Design & Make Report