[Closed] Update at startup a previously evaluated and registered MacroScript
Hi everyone!
I’m trying to solve the problem in subject.
I have a .mcr file with all the code needed for working inside.
It basically opens a rollout that I use to import specific files and perform some optimizations.
I’ve evaluated the file and added the command in one of my menus.
Every time I edit the code, a simple “evaluate all” properly update the scrip when launched from the UI.
Now I’d like to distribute this macroscript using a version control on other PCs.
My idea was to add the versioned directory to the user path on each PC and make 3dsmax re-evaluate it at launch time, so I could update the code, submit the mcr file and everyone get the new version without doing stuff.
But it doesn’t work as I expected.
A simple script placed in a custom directory (with a trivial print “message”) inside works, but not a mcr.
I’ve tried to place it in startup, standard plugins, custom folder and so on… I have no errors but the script doesn’t update.
I still have to open it and re-evaluate.
I’m sure I’m missing something here, but I’m quite confused by the documentation page.
Could you give me any help about that?
I’d also like to expand this stuff, creating one or more scripts with functions always evaluated that I can use inside other ms or mcr files, but I suppose this is another problem
Thanks in advance!
Daniele
The hack I use is: MCR > (filein) Loader > (filein) Actual MS. This allows me to version my actual script code, but the end users never see the difference and the MCR only has to be registered once, since it doesn’t actual contain any code/UI. Changes mean a one line edit to the loader and everyone gets the new code the next time they hit the button.
-Eric
Hi Eric!
I’ve given it a try and a setup like this seems to work:
First, an AutoUpdate.mcr file containing:
macroScript autoUpdate
category:“My Scripts”
buttonText:“Auto Update”
toolTip:“auto update a macroscript”
(
on execute do
(
fileIn (“my_path\Loader.ms”)
)
)
Then Loader.ms contains only the line:
[i][b]filein “my_path\Test.ms”
[/b][/i]And in the end, Test.ms with all my code, structs, functions, rollout, UI… that actually creates the GUI and that ends like this:
[i][b]try(destroydialog myRollout) catch()
createdialog myRollout
[/b][/i]
I’m not sure if this could be an elegant solution.
It doesn’t need to put any scripts in specific “startup folder” but only to manually evaluate the macroscript the first time.
However, it seems to me that this causes all the script code to be re-evaluated each time I execute the macroscript, not to simply “run” it… But honestly I’m not sure about that
(I also added a global variable (this one created at startup putting a ms file in stplgins\scripts folder) that stores as string the absolute path to the root of my script library)
Correct it reevaluates the code on run, but is that really a problem? If you are pushing changes how else would the code know what has changed? You would need to do versioned structs/code and check if the new is same as current and only run when changed. So it is really up to you on what is more elegant. Checking and deciding to reevaluate, or just reevaluate and replace what is in memory?
My preference is reevaluate as you know anything that has changed is now changed in memory on run.
-Eric
Hi Eric!
Yes you’re probably right: it’not real problem
I’d like to ask you another question about your hack: what’s the point of the loader?
I suppose you do that way because any change the ms containing the code (even a file name change or a split to more files), is managed inside the loader and there is no need to modify anymore the mcr.
However I’m beginning to structure my library and everything seems to be ok… Up to now!
Bye!
Mainly for versioning the code, without a github or versioning tool. I can quickly swap versions, by changing v01 to v02 in the loader. Someone has issues I role back to v01 in 5 seconds.
-Eric
Perfectly clear
I can rely on SVN but a fast swap between files is cheap and quick.
Thanks for your time Eric!