I’d like to be able to use the MXS functions MaxFileName and MaxFilePath in my C# code.
Is it possible to execute Max Script form within a C# script?
I searched on this topic and saw a contradictory set of answers, spread out over time:
…“you can’t call Max script from C#”
…“you can only do it with C++”
…“you can only do it using Ephere’s Max.NET”
…“you can call max script from c# using < ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand(MXSstring) >” (ManagedServices.MaxscriptSDK appears undocumented…)
So what is the real answer?
Also I found the sensible suggestion to avoid Max script and simply seek the SDK equivalent.
Is there a practical method for doing this, beyond brute force search of the SDK html docs?
I took a stab at finding MaxFileName and MaxFilePath or something like it in the SDK doc, but nothing yielded easily.
Yep, ‘ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand’ is what you want for running Mxs from C#. However you won’t get return results so it has somewhat limited use.
public static void RunMxs( string cmd )
{
ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand(cmd);
}
Also I found the sensible suggestion to avoid Max script and simply seek the SDK equivalent.
That would be ideal, something I agree with and would LOVE to do. However, sometimes, in practice it’s just much simpler to run maxscript from C#… I end up doing this, usually, after I get annoyed that I’ve spent hours trying to find what I want in the sdk, and then I give in.
class MaxApi
{
static public IGlobal Global = Autodesk.Max.GlobalInterface.Instance;
static public IInterface13 Interface = MaxApi.Global.COREInterface13;
static public string FileName()
{
return MaxApi.Interface.CurFileName;
}
}