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

YouElz
Contributor

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

YouElz
Contributor
Contributor

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()))

 

 

0 Likes
Reply
Accepted solutions (1)
264 Views
2 Replies
Replies (2)

j4n.vokurka
Advocate
Advocate
Accepted solution

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

 




1 Like

YouElz
Contributor
Contributor

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. 

0 Likes