Sunday, November 21, 2010

3dsmax: COM classes

create .NET classes
register assembly (DLL) to COM

Python:
reference:
http://techarttiki.blogspot.com/2008/03/calling-python-from-maxscript.html
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html

python COM server

class PythonUtilities:
_public_methods_ = [ 'AreaOfCircle' ]
_reg_progid_ = "PythonDemos.Utilities"
# NEVER copy the following ID
# Use "print pythoncom.CreateGuid()" to make a new one.
_reg_clsid_ = "{968B74C1-5B12-47CE-93DF-EE2C1418A542}"


def AreaOfCircle(self, radius):
return 3.14159 * radius * radius


# Add code so that when this script is run by
# Python.exe, it self-registers.
if __name__=='__main__':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)



then compile and run this class...

in 3DS max > MAXScript Listener:

comObj = createOLEObject "PythonDemos.Utilities"
a = comObj.AreaOfCircle(10)


but have to reload 3DS max whenever the COM class is changed

No comments: