[Closed] How do I use ExecuteMaxscriptCommand
There is a method in C#, I want to use it to run a Maxscript string.
public void YGB(string ms)
{
MaxscriptSDK.ExecuteMaxscriptCommand (ms);
}
I found that there are two methods in different 3ds max versions,
MaxscriptSDK.ExecuteMaxscriptCommand(ms, 1); //in 3ds max 2022
I wonder if there’s an easier way to run/execute maxscript string,Or is there a way to make it work in different 3ds max versions. I know this has been discussed before, but not clearly:
use reflection
in the end it would be smth like this
...
void ExecuteAnyVersion( string script )
{
int max_version = Funcs.GetMaxVersion();
switch( max_version )
{
case 2023:
{
var extra_arg = Funcs.GetExtraArgForVersion(max_version);
Type t = typeof(Funcs);
t.GetMethod("Execute").Invoke( null, new object[]{ script, extra_arg });
break;
}
case 2024:
case 2025:
case 2026:
case 2027:
{
var extra_arg = Funcs.GetExtraArgForVersion(max_version);
var autodesk_security_cookie = Funcs.GetAutodeskPermissionToExecuteScripts(max_version);
Type t = typeof(Funcs);
t.GetMethod("Execute").Invoke( null, new object[]{ script, extra_arg, autodesk_security_cookie });
break;
}
default:
{
Funcs.Execute( "older max versions" );
break;
}
}
}
static public class Funcs
{
static public void Execute( string str )
{
Console.WriteLine( $"--> {str}");
}
}
Thanks for your reply, but the “MaxscriptSDK” is an abstract class, Things are getting complicated. I’m trying to rewrite a derived class, But I failed.
t = dotNet.getType (dotNetClass "managedservices.maxscriptsdk")
method = t.getmethod "ExecuteMaxscriptCommand"
method.Invoke undefined #( "messageBox \"wow\"" )
Your method is feasible,But there are two parameters about “ExecuteMaxscriptCommand” in 3dsmax higher version(2022+). I can only write two styles by version judgment.
I doubt that it is possible to make a version agnostic method that would work for every future version, since you never know what args AD would want you to provide on invocation. Technically you can analyze which args are expected using reflection, but I’m not sure it can help much to create them without knowing the logic of their usage upfront.
Since it’s such a hassle, So can we find another way to run maxscript string in a c# method. in other words, We abandon the use of “ExecuteMaxscriptCommand” method.
if it is about execution of a script file then you could insert filein “/path_to/script.ms” into mini listener window and send enter key to execute it.
I need this functionality for encryption and decryption, If you expose the string, it’s meaningless
why’s that? obfuscate it and put it in .mse, then filein the .mse file.
Swap a few bytes in the beginning of the file and this mse file will become unextractable by the tools found on the internet. Of course, you’ll need to swap these bytes back and forth with some helper script to run it, but at least it will stop majority of hackers
Maxscript is an interpreted language so you can’t skip the process of parsing the source, so it is available as a plain text anyway.
Can you prevent anyone to set a breakpoint on every native function that is used to execute scripts.? No, you can’t
This encryption method has not been tried. Do you have any good tutorials to recommend.