MaxScript execution behavior via command

MaxScript execution behavior via command

Siger_
Enthusiast Enthusiast
850 Views
2 Replies
Message 1 of 3

MaxScript execution behavior via command

Siger_
Enthusiast
Enthusiast

Hi,
I try to avoid MaxScript in my C# plugin, but sometimes I'm lazy 🙂
I pass MaxScript execution in command and string crashes Max. If I increase Initial MaxScript heap allocation to 512MB - all Ok. Strange...
If I change string interpolation to string format - Ok with smaller heap. Also very strange...

 

public ICommand OpenShortFileInMaxCommand
        {
            get
            {
                return _OpenShortFileInMaxCommand ?? (_OpenShortFileInMaxCommand = new RelayCommand<object>(it =>
                           {
                               if (!(it is IMatLabCSshortItem)) return;

                               if (SelectedShortScItem == null) return;

                               if (!IsShortcutFileExists) return;
							   
                               if (string.IsNullOrEmpty(SelectedShortScItem.ScenePath)) return;

                               var fileExt = Path.GetExtension(SelectedShortScItem.ScenePath);
                               if (fileExt != ".max")
                               {
                                   return;
                               }

                               if (MaxCore.Core.CheckForSave)
                               {
                                   MaxscriptSDK.ExecuteMaxscriptCommand($"loadMaxFile (@\"{SelectedShortScItem.ScenePath}\") useFileUnits:true quiet:true");
                               }
                           },
                           it =>
                           {
                               if (!(it is IMatLabCSshortItem))
                               {
                                   return false;
                               }

                               if (string.IsNullOrEmpty(SelectedShortScItem?.ScenePath))
                               {
                                   return false;
                               }
                               if (IsShortcutFileExists == false)
                               {
                                   return false;
                               }
                               var fileExt = Path.GetExtension(SelectedShortScItem.ScenePath);
                               return fileExt == ".max";
                           }));
            }
        }

 

Example of string format:

MaxscriptSDK.ExecuteMaxscriptCommand(string.Format("loadMaxFile (@\"{0}\") useFileUnits:true quiet:true", SelectedShortScItem.ScenePath));
0 Likes
851 Views
2 Replies
Replies (2)
Message 2 of 3

istan
Advisor
Advisor

I can't tell you much about C#, but I use MaxScript massively even in "realtime" actions in C++. I personally would avoid loading files via MaxScript..

0 Likes
Message 3 of 3

Siger_
Enthusiast
Enthusiast

Thank you for your answer.

Perhaps it is not a Max's issue. After restart (machine) all works ok (and if mxs passed as interpolated string).

But I rewrote method in C# withoud MXS.

0 Likes