- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can anybody help?
Is it possible, using a Fusion 360 Python script to determine if an open document is a "Drawing"?
Many thanks!!!!
Darren
Solved! Go to Solution.
Can anybody help?
Is it possible, using a Fusion 360 Python script to determine if an open document is a "Drawing"?
Many thanks!!!!
Darren
Solved! Go to Solution.
Hi @isocam .
# Fusion360API Python script
import traceback
import adsk.fusion
import adsk.core
def run(context):
ui: adsk.core.UserInterface = None
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
doc: adsk.core.Document = app.activeDocument
if doc.objectType == 'adsk::drawing::DrawingDocument':
msg = '.f2d'
elif doc.objectType == 'adsk::fusion::FusionDocument':
msg = '.f3d or .f3z'
else:
msg = 'pcb'
ui.messageBox(msg)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Its not always a good idea to use strings to represent class types. A more idealised version (IMO) would be:
# Fusion360API Python script
import traceback
import adsk.fusion, adsk.core, adsk.drawing
def run(context):
ui: adsk.core.UserInterface = None
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
doc: adsk.core.Document = app.activeDocument
if doc.objectType == adsk.drawing.DrawingDocument.objectType:
msg = '.f2d'
elif doc.objectType == adsk.fusion.FusionDocument.objectType:
msg = '.f3d or .f3z'
else:
msg = 'pcb'
ui.messageBox(msg)
except:
if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
You can also just use type to compare so:
# Fusion360API Python script
import traceback
import adsk.fusion, adsk.core, adsk.drawing
def run(context):
ui: adsk.core.UserInterface = None
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
docType: type = type(app.activeDocument)
if docType is adsk.drawing.DrawingDocument:
msg = '.f2d'
elif docType is adsk.fusion.FusionDocument:
msg = '.f3d or .f3z'
else:
msg = 'pcb'
ui.messageBox(msg)
except:
if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Or you can use the 'isinstance' func:
# Fusion360API Python script
import traceback
import adsk.fusion, adsk.core, adsk.drawing
def run(context):
ui: adsk.core.UserInterface = None
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
doc: adsk.core.Document = app.activeDocument
if isinstance(doc,adsk.drawing.DrawingDocument):
msg = '.f2d'
elif isinstance(doc,adsk.fusion.FusionDocument):
msg = '.f3d or .f3z'
else:
msg = 'pcb'
ui.messageBox(msg)
except:
if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Im sure there's a slight difference in the performance of each, however for general purposes, they are all functionally equivalent.