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: 

[HANG] app.documents.open(dataFile=drawingFile, visible=False)

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

[HANG] app.documents.open(dataFile=drawingFile, visible=False)

Hi there, 

 

I've been writing a script to export a bunch of drawing files to PDFs.

 

When visible is set to TRUE ...documents.open(dataFile=drawingFile, visible=True) all is OK.

But - when visible is set to False - Fusion hangs. 

 

Seems like the drawing file opens (I can see the component browser) - the toolbar is a little whacky - no drawing per se - and Fusion just sits still.

 

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

app = None
ui = None
design:adsk.fusion.Design = None

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

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

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

        #outputFolder:adsk.core.DataFolder = getDrawingOutputFolder()
        outputDirectory = getDrawingOutputDirectory()

        for drawingFile in drawingFiles:
            #doc:adsk.core.Document = app.documents.open(drawingFile) 
            drawingDoc:adsk.drawing.DrawingDocument = app.documents.open(dataFile=drawingFile, visible=True)
            #drawingFile.
            exportDrawingToPdf(drawingDoc, outputDirectory)
            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 getDrawingOutputFolder() -> adsk.core.DataFolder:
    cloudDialog = ui.createCloudFileDialog()
    cloudDialog.title = 'Select output folder.'

    dialogResult = cloudDialog.showSave()
    if dialogResult == adsk.core.DialogResults.DialogOK:
        dataFolder:adsk.core.DataFolder = cloudDialog.dataFolder
        dataFiles:adsk.core.DataFiles
        return dataFolder
    
def getDrawingOutputDirectory():
    folderDialog = ui.createFolderDialog()
    folderDialog.title = 'Selection output folder.'
    dialogResult = folderDialog.showDialog()

    if dialogResult == adsk.core.DialogResults.DialogOK:
        foldername = folderDialog.folder
        return foldername
    else:
        return
    
def exportDrawingToPdf(
        drawingDoc:adsk.drawing.DrawingDocument, 
        #outputFolder:adsk.core.DataFolder
        outputDir:str
    ):

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

    #msg = f'{outputFolder.name}'
    #app.log(msg)

    msg = f'{outputDir}'
    app.log(msg)

    outputFileName = drawingDoc.name

    filename = outputDir + '/' + outputFileName + '.pdf'

    exportManager:adsk.drawing.DrawingExportManager = drawingDoc.drawing.exportManager
    PDFOptions:adsk.drawing.PDFExportOptions = exportManager.createPDFExportOptions(filename)
    PDFOptions.filename = filename
    PDFOptions.sheetsToExport = adsk.drawing.PDFSheetsExport.AllPDFSheetsExport
    PDFOptions.openPDF = False
    PDFOptions.useLineWeights = False

    exportOK = exportManager.execute(PDFOptions)

    return exportOK

 

Cheers !

 

Glenn.

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