Document Opening Class - Does Not Work With Drawings

Document Opening Class - Does Not Work With Drawings

isocam
Collaborator Collaborator
324 Views
1 Reply
Message 1 of 2

Document Opening Class - Does Not Work With Drawings

isocam
Collaborator
Collaborator

Can anybody help?

 

The following Fusion 360 Python "Class" works OK when opening an assembly, or a part, but does not work when opening a drawing.

 

class MyDocumentOpenedHandler(adsk.core.DocumentEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
global app, ui

ui = app.userInterface

design = adsk.fusion.Design.cast(app.activeProduct)

document = design.parentDocument

ui.messageBox("DOCUMENT OPENING", 'Fusion 360', 0, 3)

 

Does anybody know how to modify the code so that it also works when opening a drawing?

 

Many thanks in advance!

 

Darren

0 Likes
Accepted solutions (1)
325 Views
1 Reply
Reply (1)
Message 2 of 2

Rushikesh.kadam
Autodesk
Autodesk
Accepted solution

@isocam for drawing file the design object is returned as None. An error occurs for the line document = design.parentDocument. Hence the message box line is never executed.

Here is the modified code which worked for me.

class MyDocumentOpenedHandler(adsk.core.DocumentEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try: 
            global app, ui
            ui = app.userInterface
            design = adsk.fusion.Design.cast(app.activeProduct)
            if design is not None:
                document = design.parentDocument
            ui.messageBox("DOCUMENT OPENING", 'Fusion 360', 0, 3)
        except:
            app.log('AddIn Stop Failed: {}'.format(traceback.format_exc()))

------------------------------------------------------------------------------------------------------------------------------

If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed.




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


0 Likes