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: 

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

2 REPLIES 2
Reply
Message 1 of 3
isocam
253 Views, 2 Replies

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

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

2 REPLIES 2
Message 2 of 3
BrianEkins
in reply to: isocam

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
Message 3 of 3
kandennti
in reply to: isocam

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 ''

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