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: 

[BUG] DrawingDocument.isUpToDate always True

0 REPLIES 0
Reply
Message 1 of 1
gvisca44
74 Views, 0 Replies

[BUG] DrawingDocument.isUpToDate always True

I think the DrawingDocument.isUpToDate property always returns True.

 

(refer my other recent posts on export drawings to PDF).

 

Consider the following: (note - I have tried to remove irrelevant code - leaving just whats needed to highlight what I think is an error - so if I've created an error I'm sorry.).

 

Run the script - You'll be present to choose a drawing file.  Select one that is out of date.  A message will be written indicating the isUpToDate is True (I believe).  Choose one that IS up to date - same message.

 

If you modify the code and attempt to "updateAllReferences" a fatal error occurs. 

 

import adsk.core 
import adsk.fusion 
import adsk.drawing
import traceback

app = None
ui = None

def run(context):
    global app, ui
    ui = None

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

        drawingFiles:adsk.core.DataFiles = getDrawingFiles()
        adsk.doEvents()

        for drawingFile in drawingFiles:
            #doc:adsk.core.Document = app.documents.open(drawingFile) 
            drawingDoc:adsk.drawing.DrawingDocument = app.documents.open(dataFile=drawingFile, visible=True)

            drawingDoc = updateDocReferences(drawingDoc)

            if drawingDoc == None:
                # an error occurred
                return
            
            adsk.doEvents()

            drawingDoc.close(saveChanges=False)

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

def getDrawingFiles() -> adsk.core.DataFiles:

    cloudDialog = ui.createCloudFileDialog()
    cloudDialog.title = 'Select drawings to export.'
    cloudDialog.isMultiSelectEnabled = True
    cloudDialog.filter = 'f2d'

    dialogResult = cloudDialog.showOpen()
    if dialogResult == adsk.core.DialogResults.DialogOK:
        #dataFolder:adsk.core.DataFolder = cloudDialog.dataFolder
        dataFiles:adsk.core.DataFiles = cloudDialog.dataFiles
        return dataFiles

def updateDocReferences(
        drawingDoc:adsk.drawing.DrawingDocument
    ) -> adsk.drawing.DrawingDocument:

    msg = f'{drawingDoc.name} isUpToDate = {drawingDoc.isUpToDate}'
    app.log(msg)
    adsk.doEvents()

    if not drawingDoc.isUpToDate:
        if drawingDoc.updateAllReferences() == False:
            msg = f'{drawingDoc.name} updateAllReferences failed'
            app.log(msg)
            adsk.doEvents()
            return None

        saveDescription = 'Update references'
        if drawingDoc.save(saveDescription) == False:
            msg = f'{drawingDoc.name} save failed'
            app.log(msg)
            adsk.doEvents()
            return None

        msg = f'{drawingDoc.name}'
        app.log(msg)
        adsk.doEvents()

    return drawingDoc

 

0 REPLIES 0

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