Get Drawing Sheet Size (A1, A2, A3 or A4) using a Fusion 360 Python script

isocam
Collaborator

Get Drawing Sheet Size (A1, A2, A3 or A4) using a Fusion 360 Python script

isocam
Collaborator
Collaborator

Can anybody help?

 

Is it possible, for testing purposes, to get the drawing sheet size (A1, A2, A3 or A4) using a Fusion 360 Python script and display it in a message box?

 

Many thanks in advance!

 

Darren

0 Likes
Reply
393 Views
2 Replies
Replies (2)

BrianEkins
Mentor
Mentor

The API currently has almost no functionality for drawings.  The first of any drawing capabilities were just added to the API within the last couple of months.  With it, you can access a DrawingDocument and the Drawing product it contains and get access to the ExportManager object to be able to export the drawing as PDF.  That's it.  There's no access to the sheets or anything else that is drawing specific.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes

kandennti
Mentor
Mentor

Hi @isocam .

 

This is a forced method, but I tried it and was able to get the following characters.

1.png

#Fusion360API Python script
import adsk.core, adsk.fusion, traceback
import adsk.drawing


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

        drawDoc = adsk.drawing.DrawingDocument.cast(app.activeDocument)
        if not drawDoc: return

        size = getSheetSize()
        if not size: return
        
        ui.messageBox(size)

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


def getSheetSize() -> str:
    app = adsk.core.Application.get()

    app.executeTextCommand(u'Commands.Start FusionChangeSheetSizeCommand')
    dlgInfos = app.executeTextCommand(u'Toolkit.cmdDialog').split(',')
    app.executeTextCommand(u'NuCommands.CancelCmd')
    
    lst = []
    for idx, info in enumerate(dlgInfos):
        if 'Label=' in info:
            lst = dlgInfos[idx+1].splitlines()

    if lst:
        return lst[0]
    else:
        return ''
1 Like