Open an .ms file with Edit()


Could someone please help with this idea: I would like to open a scriptfile (edit("")) that is linked to with eg $userScript instead of a full path in clear text.

In this reply (Can MXS add custom menus to eg Maxscript editor?), @Serejah provided an answer where you could extract the selected string inside the Maxscript Editor.

I went through the scripts I have and gathered an amount of variations of how the script-path could look like (you might know some more variations I have missed):


  • to open this one, we would need to run edit" … put selected string in here … "


  • edit" … put selected string in here … "

(getdir #userScripts)+"\Folder\")

  • edit( … put selected string in here … )

ScriptPath + “Folder\”`

  • in this case, “ScriptPath” is defined globally , like this: Global ScriptPath = “…something…”
  • edit( … put selected string in here … )


define a function to convert to real path


Could you help providing this function? :+1:

fn getrealpath string =
	pathsel = #(#userScripts)
	subpathsel = #("/Folder/")
	realpath = ""
	for i in pathsel do
			i = getdir i
			for j in subpathsel do
				if doesFileExist (i+j+string) do 
					realpath = i+j+string

edit(getrealpath "your file string")


Maybe I am wrong, but aren’t you complicating things? Probably I was a bit unclear too.

if we have $userScripts\Folder\ we would need edit"$userScripts\Folder\"

if we have $userScripts/Folder/ --> edit"$userScripts/Folder/"

(getdir #userScripts)+"\Folder\") --> edit((getdir #userScripts)+"\Folder\"))

ScriptPath + “Folder\” --> edit(ScriptPath + “Folder\”) … as mentioned before “ScriptPath” is defined globally , like this: Global ScriptPath = “…something…”

The task here is to create a macroscript that reads what you have selected in the Maxscript Editor och opens the file. Much like the “Open Selected Filename” in Maxscript Editor. That one works only on path in plain text.


edit (getFilenamePath "your file path" + filenameFromPath "your file path" )


I am afraid you are misunderstanding my question :slight_smile:

First, take a look at this post: Can MXS add custom menus to eg Maxscript editor?

There, you will see a solution that captures your selected text inside the Macroscript Editor.
For example, if I do this:

… and run the script provided in the link above, I get this output: “$scripts/SoulburnScripts/scripts/”

Now that we have come so far, I would want to package this into a single Macroscript: You select something, you run the macroscript, it opens up the file for you.


you had got what you selected , just need chenged it to the string , so why problem yet


If something doesn’t work check if you have all slashes in place

ScriptPath = "C:\Users\User\AppData\Local\Autodesk\3dsMax\2014 - 64bit\ENU\scripts"
edit ("$userscripts\outliner\") -- works
edit (ScriptPath + "\outliner\") -- works
edit (ScriptPath + "outliner\") -- missing slash, doesn't work
edit (pathConfig.appendPath ScriptPath "outliner\") -- works again


yes, of course. If we know the script works, then all that counts is the end-string, right? Even if there is a best practice among scripters (if there is one, please tell me) I cant do anything about it, because what I am looking for is a way to open ms-files defined in other peoples scripts. I can’t controll how everyone writes their code, but I can try to make a script that works with theirs :smiley:

This is what I ended up with so far, but it is not compatible with all kinds of cases (se below).
Also, please help me fine tune as much as you can.


fn GetMXSEditorWindowText hwnd =
local marshal = dotnetclass “System.Runtime.InteropServices.Marshal”
str = “”
try (

  len = windows.sendmessage hwnd 0xE 0 0
  lParam = marshal.AllocHGlobal (marshal.SystemDefaultCharSize*(len+1))
  windows.sendmessage hwnd 0xD (len+1) lParam 

  ptr = dotnetobject "System.IntPtr" lParam
  str = marshal.PtrToStringAuto ptr
  marshal.FreeHGlobal ptr

) catch ()

g = (dotNetClass “Autodesk.Max.GlobalInterface”).Instance

hwnd = g.TheMxsEditorInterface.EditorGetEditHWND
main = g.TheMxsEditorInterface.EditorGetMainHWND


start = windows.sendMessage hwnd SCI_GETSELECTIONSTART 0 0
end = windows.sendMessage hwnd SCI_GETSELECTIONEND 0 0

edit (substring (GetMXSEditorWindowText hwnd) (start+1) (end - start))


summary - please keep in mind that they are all working scripts. I am trying to apply this macroscript on “real life scripts”, that I download from developers websites or scriptspot and so on. I need this to work without the need to change the original script to make them work with mine:

$userScripts/subfolder/ -- works
$userScripts\\folder\\ -- does not work. Typing manually edit"$userScripts\\folder\\" works though
ScriptPath + "Folder\" -- does not work. Typing manually edit (ScriptPath + "Folder\ works though
((getdir #userScripts)+"\\folder\\") -- does not work. Typing manually edit((getdir #userScripts)+"\\folder\\") works though

There might be more cases and we need them all to work :wink:

Regarding the ones that don’t work, my guess it is because of all the nested slashes and parenthesis and all.
How can this be solved?


no-worked line because of wrong syntax
if you get right path , use getFilenamePath + filenameFromPath all syntax works , just need to case parametric with execute method



try this

substr = execute (substring (GetMXSEditorWindowText hwnd) (start+1) (end - start))
edit substr


Thank you very much! It works now :sunglasses:

Is it possible to foolproof this script? If I miss the first and/or last " for example, I get an error.
Another thing was if I got one ( or ) too many, then I get errors too.

How can we get a nicer warning, eg explaining the proper use of this script? Or simply not do anything? Or if possible, make it intelligent and have the script add a first/last " for us? What do you think?


You can trim not needed characters

trimLeft “apple” “a”
trimRight “apple” “e”
trimRight (trimLeft “apple” “a”) “e”


I doubt that you’ll find a ready solution to your problem.
As long as you depend on any local variable in someone’s script it is unlikely that you will be able to make a proper path.


Maybe :wink: A final try then: is there a way in maxscript to verify if a string is a valid path? With a friendly way (as opposed to an aggressive error message like the ones I get now) to tell us true or false?

Can MXS add custom menus to eg Maxscript editor?

Sure, check out doesFileExist and pathConfig struct methods.