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: 

Mass PDF Drawing Export

2 REPLIES 2
Reply
Message 1 of 3
bmxjeff
234 Views, 2 Replies

Mass PDF Drawing Export

I'm working on a large project. Like 200 Prints+ Does anyone know of a way to export The Drawings in PDF for a Project? 

 

I found one for STEP files. One for reporting the PDF's would save me .. like 2 days of opening files : ) 

 

Thanks!

Jeff Hooper (Owner)
Hooper Machine and Design
[X] AUTODESK AMATUR ORDINARY
2 REPLIES 2
Message 2 of 3
BrianEkins
in reply to: bmxjeff

There's almost not drawing functionality exposed through the API. The one thing that is there is the functionality to export PDF. Here's a small sample that illustrates it.

import adsk.core, adsk.drawing, traceback

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

        # Get the Drawing object.
        drawing = adsk.drawing.Drawing.cast(app.activeProduct)
        if drawing is None:
            ui.messageBox('A drawing must be active.')
            return

        expMgr: adsk.drawing.DrawingExportManager = drawing.exportManager
        pdfOptions = expMgr.createPDFExportOptions('C:\Temp\Sheet1.pdf')
        pdfOptions.sheetRange = "1"
        expMgr.execute(pdfOptions)

        pdfOptions = expMgr.createPDFExportOptions('C:\Temp\Sheet2.pdf')
        pdfOptions.sheetRange = "2"
        expMgr.execute(pdfOptions)

        pdfOptions = expMgr.createPDFExportOptions('C:\Temp\SheetAll.pdf')
        pdfOptions.sheetsToExport = adsk.drawing.PDFSheetsExport.AllPDFSheetsExport
        expMgr.execute(pdfOptions)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

You might still run into some issues depending on what you need to do. As I said, very little drawing functionality is exposed through the API. Something that is not there is accessing the sheets. If you need to open a drawing and export each sheet as PDF, that's not easy because you can't find out how many sheets there are. I guess you could write out sheet 1, and sheet 2, and keep going until it fails. Of course, if you can't access sheets, you can't get any information about the sheet, like it's name, if you wanted to use that as part of the filename. 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3
gvisca44
in reply to: bmxjeff

Try this: @bmxjeff 

 

When you run it - you are prompted to select all the drawings (multiselect).  Then prompted for an output file location.  Then set and wait ... but a hell of a lot faster that doing it manually.

 

No error checking / drawing validity checking ... just a very simple export of what you've created.

 

PDF Export options are in the exportDrawingsToPDF function.  Change them as you see fit.

 

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

 

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