MaxScript String Formatting?

MaxScript String Formatting?

deven.saxenaP7BD5
Enthusiast Enthusiast
664 Views
4 Replies
Message 1 of 5

MaxScript String Formatting?

deven.saxenaP7BD5
Enthusiast
Enthusiast

Hello,

 

I am looking to access an external python file that is located in the documents folder for windows. 

The file that I wanna access "C:\Users\USERNAME\Documents\MaxScripts\mainUi\launch.py" 

 

I don't want to hardcode the Username so instead, I found this "sysInfo.username" that spits out the user name for the login. 

So to add that in the string I can do something like this in Python:

"C:\Users\{}\Documents\MaxScripts\mainUi\launch.py".format(sysInfo.username)

 

What would be the equivalent to this in Maxscript? Or is there a better alternative to what I am trying to achieve?

 

Actual code that I wanna run:

python.ExecuteFile @"C:\Users\USERNAME\Documents\MaxScripts\mainUi\launch.py" 

 

P.S. I will be linking this "python.Execute" to a button. 

0 Likes
Accepted solutions (1)
665 Views
4 Replies
Replies (4)
Message 2 of 5

denisT.MaxDoctor
Advisor
Advisor

The simple way is:

@"C:\Users\" + sysInfo.username + @"\Documents\MaxScripts\mainUi\launch.py"

There are several other ways, but in this case I recommend sticking to the simple

 

0 Likes
Message 3 of 5

deven.saxenaP7BD5
Enthusiast
Enthusiast

Hi Denis, 

I tried doing that but it looks like Python.ExecuteFile gets stuck at "C:\Users\" and treats it as a file and fails. Looks like it wants a single String to execute. 

 

 

-- MAXScript MacroScript Error Exception:
-- Runtime error: Failed to open file C:\Users\Failed to open file C:\Users\
-- MAXScript callstack:
--	thread data: threadID:6908
--	------------------------------------------------------
--	[stack level: 0]
--	In codeblock macroScript: DragAndDrop_Macro77; filename: C:\Users\USERNAME\AppData\Local\Autodesk\3dsMax\2022 - 64bit\ENU\usermacros\DragAndDrop-Macro77.mcr; position: 97; line: 4
--		Locals:
--		Externals:
--	------------------------------------------------------
--	[stack level: 1]
--	called from top-level

 

 

I also tried storing the file name as a variable and executing the variable instead of the string but no luck.

filePath = "C:\Users\" + sysInfo.username + "\Documents\MaxScripts\mainUi\launch.py"

python.ExecuteFile @"%" (filePath)

 

 

0 Likes
Message 4 of 5

denisT.MaxDoctor
Advisor
Advisor
Accepted solution
filePath = @"C:\Users\" + sysInfo.username + @"\Documents\MaxScripts\mainUi\launch.py"

python.ExecuteFile filePath
0 Likes
Message 5 of 5

deven.saxenaP7BD5
Enthusiast
Enthusiast

Awesome I knew I was close. Thanks, Denis for your help. 

0 Likes