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: 

Class Object

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Peter__B
336 Views, 3 Replies

Class Object

Hello

 

Part of my python code contains the following:

 

class ParameterChange:

      def __init__(self,dia, length):

           self.DIA = dia

           self.LENGTH = length

 

If I execute it and also run e.g.

 

param = ParameterChange(1.1,2.2), I will get for param.DIA...1.1 but python says that param.LENGTH does not exist. Just the first works.

 

In standard python it works but not in the Spyder version in fusion 360.

 

Does anybody know why ?

 

Best Regards

Peter

 

3 REPLIES 3
Message 2 of 4
JeromeBriot
in reply to: Peter__B

Hello,

 

the following script works as expected:

 

import adsk.core, traceback

class ParameterChange:

      def __init__(self,dia, length):

           self.DIA = dia
           self.LENGTH = length

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        param = ParameterChange(1.1,2.2)

        ui.messageBox('{} , {}'.format(param.DIA, param.LENGTH))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Message 3 of 4
Peter__B
in reply to: Peter__B

Is it necessary to have all statements e.g. in the run function ? or can I have them outside to ? perhaps it special for "python Spyder fusion script" ?

 

/Peter

Message 4 of 4
ross.korsky
in reply to: Peter__B

In short, no. You can write your code outside the "run" method but you need to hook into "events" to do so - see this help topic.

 

I write my add-ins like proper python with objects, modules, packages, the whole bit. See this post for my boiler plate code which uses some black magic to abstract away the irritating "event object instance" pains.

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