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: 

AttributeError: 'NoneType' object has no attribute 'cast'

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
YouElz
215 Views, 2 Replies

AttributeError: 'NoneType' object has no attribute 'cast'

Hi all

Does anyone know why I am getting this error? 

 

Failed:
Traceback (most recent call last):
  File "C:/Users/YouElz/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/NewScript2/NewScript2.py", line 11, in run
    design = adsk.fusion.Design.cast(app.activeProduct)
             ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'cast'
import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        ui.messageBox('Hello script')

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

 

 

2 REPLIES 2
Message 2 of 3
j4n.vokurka
in reply to: YouElz

Hi,

what workspace is active in the document when you call this script? 

this should return a string which defines in which workspace you are:

product = app.activeProduct
productType = product.productType


If the value does not match with one of these, I would expect the error you reported to occur.

j4nvokurka_0-1712216708972.png

 




Message 3 of 3
YouElz
in reply to: j4n.vokurka

Thank you for the reply.

I was in the design workspace.  

 

I restarted Fusion and VSCode then debug and it worked... not sure what happened. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report