Update drawing references

Update drawing references

ianjwellings
Contributor Contributor
936 Views
7 Replies
Message 1 of 8

Update drawing references

ianjwellings
Contributor
Contributor

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

0 Likes
Accepted solutions (2)
937 Views
7 Replies
Replies (7)
Message 2 of 8

Rushikesh.kadam
Autodesk
Autodesk

@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
Mentor
Mentor
Accepted solution

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.

0 Likes
Message 4 of 8

ianjwellings
Contributor
Contributor

Ok thank you for the update

0 Likes
Message 5 of 8

ianjwellings
Contributor
Contributor

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

0 Likes
Message 6 of 8

kandennti
Mentor
Mentor

@ianjwellings .

 

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

0 Likes
Message 7 of 8

ianjwellings
Contributor
Contributor

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()))

 

0 Likes
Message 8 of 8

kandennti
Mentor
Mentor
Accepted solution

@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()))