jython: instantiating max class
Hi, can someone help me,
I'm using jython (loadbang.net) with maxmsp and I try to use maxmsp class in jython. But I can't instantiate a class
Here is what i do:
===code===
import com.cycling74.max
test = com.cycling74.max.MaxObject() # or
test = com.cycling74.max.MaxObject.getInstance()
test.outlet(0,"something")
==end code===
and max message box returns me this error:
TypeError: No visible constructors for class (com.cycling74.max.MaxObject)
did i forget something?
Hi-
Did you study the "jython.BasicUsage.mxt" patch that's included with the distribution? I'm not hugely familiar with how it handles the MaxObject, but I don't think you need to import or construct a reference to it to throw something down an outlet.
Best, Charles
hi, thanks for your reply, yes I studied it and used it greatly so far.
But for my project need, it would be so handy for me to use this function (and other functions) within a class that is called by the main script.
I posted another message just after this one that explains that, can you have a look at it?
Gus
You can't instantiate a MaxObject because it's abstract. In practice, the MXJ machinery builds a MaxObject instance for you (which, if working in Java, you sub-class) and links it into Max via JNI - you can't just create them dynamically.
In the Jython system I make the owning MaxObject instance available in the Python namespace as "maxObject" - you'll need to pass this around, or wrap another object around it, in order to do output.
oh ok, thanks.
And is it the same for other classes? can we instantiate for example MaxClock and use its methods?
Depends: look at the javadocs (bundled in the Max distribution) to see which classes are abstract, and/or which ones have constructors which need arguments.