December 2020 Product Update - API "Export a Drawing as a PDF"

December 2020 Product Update - API "Export a Drawing as a PDF"

isocam
Collaborator Collaborator
627 Views
2 Replies
Message 1 of 3

December 2020 Product Update - API "Export a Drawing as a PDF"

isocam
Collaborator
Collaborator

Can anybody help?

 

In the December 2020 Product Update, you can now using API, export a PDF file.

 

Can somebody at AutoDesk post a sample "script file" to show how to do this?

 

Many thanks in advance!!

 

Darren

0 Likes
628 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
0 Likes
Message 3 of 3

BrianEkins
Mentor
Mentor

Here's a script that will export the active drawing as PDF.

 

import adsk.core, adsk.drawing, traceback

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

        drawing = adsk.drawing.Drawing.cast(app.activeProduct)
        if not drawing:
            ui.messageBox( 'A drawing must be active.')
            return

        exportMgr = drawing.exportManager
        exportOptions = exportMgr.createPDFExportOptions('C:/Temp/PDFExportText.pdf')
        exportOptions.sheetsToExport = adsk.drawing.PDFSheetsExport.AllPDFSheetsExport
        exportOptions.useLineWeights = True
        exportMgr.execute(exportOptions)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com