MaxScript Dotnet global

 
 
 
Posted by:susanta
Data created:27 October 2010

Hi,

As Max.net is using dotnet runtime 4.0 and Autodesk MaxScript 2011 Dotnet is using 2.0, How to initialize a MaxScript global to store a .net class instance (Not a User Interface class) from Max.net( constructor of derived class of IPlugin)? Basically I want to keep refernce to IGlobal instance as a MaxScript global...so I can call some MaxSDK functinality through it from MaxScript.

N.B.

I have cheked: https://www.ephere.com/autodesk/max/docs/987.html

But problem is I think Max.Net (because of two separate runtime??) is creating separte copy of class and static memebers. So using (dotnetClass "MyClass").MyStaticMember is not same with MyClass.MyStaticMember I have initialized in IPlugin constructor during Plugin loading.

Thanks in advance.

Hey,

Next build of Max.NET will have a static Autodesk.Max.GlobalInterface.Instance member accessible from anywhere (without requiring IPlugin interface initialization). This is something I'm working on now.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

That will really help thanks. Is that also will be possible any dotnet class instance created through a Max.net plugin can be accessed through MaxScript?

Yes, that should be possible as long as its all within the same AppDomain.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

I think it is not at the momment with Max 2011(64 bit). Or am I missing somthing?

    This my plugin class...where x static member set to 10 during load.
    
    public class MyClass :IPlugin
    {
        public static int x = 0;
        IGlobal mGlobal;

        public void PrintOnListener(ref string msg)
        {
            this.mGlobal.TheListener.EditStream.Printf(msg, null);
        }

        #region IPlugin Members

        public void Cleanup()
        {
            
        }

        public void Initialize(IGlobal global, System.ComponentModel.ISynchronizeInvoke sync)
        {
            mGlobal = global;
            MyClass.x = 10;
            string msg = "value of X = " + MyClass.x;
            PrintOnListener(ref msg);
        }

        #endregion
    }

    It is priniting perfectly during max startup
    value of X = 10

    Now If I try to access MyClass.x ... MaxScript not found the class so I got error...
    (dotnetClass "Custom.MyClass").x
    -- Unknown property: "x" in undefined
    
    So I load the assembly manually and then try to access
    dotnet.loadAssembly @"dotnet.loadAssembly @"C:\Program Files\Autodesk\3ds Max 2011\plugins\Custom.dll"
    (dotnetClass "Custom.MyClass").x
    
    it will get it but value is not 10.... So it is the separate copy of the class defination???

Max.Net does load the .dll but it doesn't lock the file, so thats probably why it loads it over top of the existing definition. I'm not sure what the full syntax of dotnetClass command is, but I imagine that you can pass fully qualified class name to it.

I would try that, it'd go something like (dotnetClass "Custom.MyClass,Custom,1.0.0.0").x I can't remember the exact syntaxt for passing fully qualified names but its on MSDN and google.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Yea also tried somthing like that to find the loaded one but no luck :( ... as CurrentAppdomain (from MaxScript) got no entry for custom assembly as Loaded assembly or reflection only assembly.

(dotnetClass "System.reflection.Assembly").Load "Custom, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"


seems like appdomain what Max.net is using to load  a plugin and App domain maxscript is using  are different (because of two separate .net runtime)? Max.Net one is giving "DefaultDomain" as frinedly name while from MaxScript one is "3dsmax.exe".

That is odd indeed, I remember being able to access all properties of my (max.net-loaded) plugin from MaxScript just fine. However, that was before the .NET 4.0 switch. I guess I'll need to try it again before giving any answers.

Marsel Khadiyev (Software Developer, EPHERE Inc.)