Softimage SDK Programmer's Guide > Script Development > Python Scripting >

# Linking Python Classes to Command Buttons

For the most part, associating Python scripts to buttons is done much the same way as with any other scripting language: you can assign any command to a button, and if you drag a code snippet from the Script Editor onto a toolbar, Softimage handles the conversion from snippet to command.

You can even use classes in your commands or code snippets; however, you cannot use a class constructor as the Handler for your command. To initialize the class, use a dummy procedure such as in the following example:

    #-------------------------------------------------------------------------
    class MyMsg:
    	"""Testing of Classes within Softimage Environment"""
    	def __init__(self, First="3D", Last="Artist"):
    		self.f = First
    		self.l = Last
    		Application.LogMessage("Hello, %s %s, MyMsg!" %(self.f, self.l))

    	def first(self):
    		Application.LogMessage("%s, First Method is a go!" % (self.f))
    	def second(self):
    		Application.LogMessage("%s, Second Method is a go!" %(self.f))
    	def third(self):
    		pass

    #-----------------------------------------------------------------------
    #initialize the class and methods
    def TestPython():
    	parent = MyMsg("Daffy", "Duck")
    	parent.first()
    	parent.second()
    #-----------------------------------------------------------------------