[Closed] Evaluating script != Run Script?
Hi,
I have recently run into a rather strange problem, if what I think is happening is indeed doing so.
I have written a short script to perform a few tedious tasks automatically, and it works just fine when I have it open in the editor window, and evaluate it (Ctrl+E). However, if I choose Run Script from the MAXScript window, I get a different result – nothing so obvious as a broken script, though it no longer does what I intended it to. I would think it impossible, but I’ve tried it a few times, and the error seems to happen every time, and go away if I switch to executing from the editor window. I’ve written a few scripts before, and never encountered anything like this.
So my question is, is this even possible? And if so, is there anything I can do about it, any commands that work differently if executed via the MAXScript menu instead of Evaluated via the Editor window?
I’m using 3DS Max 2009, 32 Bit
thanks in advance,
Mikkel
Question, if you ‘Run Script’ it twice does it do what you imagine it should?
Things like this tend to be a variable scope issue, IE: you may be assuming a variable is set earlier than it really is in your script, since it may be left over from the previous run?
Hard to say without seeing the script exactly though.
It’s a script to make it easier to mirror morph targets, and it might be a little hack-ish, but as described, it does work when evaluating
edit: should probably add instructions (I’d add interface etc to it but I want to get it working first!), what you do are:
- Copy the morph target
- Mirror it
- deselect everything
- select your “base” mesh
- while holding Ctrl, select the mirrored morph target
- run script
- if done from editor, rejoice, if done using run script, tear out hair and spend a few hours muttering “I don’t get it”
The script is this:
starttime = sliderTime
sliderTime = 0
basemesh = selection[1]
leftexpression = selection[2]
print ("Base mesh: " + basemesh.name)
print ("Mirror morph: " + leftexpression.name)
addModifier leftexpression (Morpher ())
WM3_MC_BuildFromNode leftexpression.morpher 1 basemesh
sliderTime = 10
with animate on
(
WM3_MC_SetValue leftexpression.morpher 1 100.0
)
baseduplicate = Copy basemesh
baseduplicate.pos = leftexpression.pos
addModifier baseduplicate (Skin_Wrap ())
baseduplicate.modifiers[#Skin_Wrap].meshList = #(leftexpression)
baseduplicate.modifiers[#Skin_Wrap].distance = 0.001
sliderTime = 0
convertToPoly baseduplicate
leftnavn = leftexpression.name
leftwire = leftexpression.wirecolor
delete leftexpression
baseduplicate.name = leftnavn
baseduplicate.wirecolor = leftwire
sliderTime = starttime
Out of curiosity, what happens if you use the Evaluate command in the Script Editor’s menu instead of Ctrl+E?
The obvious difference between running and Ctrl+E is that the Ctrl key is pressed down while the script is running (or at least in the beginning), which I have seen causing a difference.
Also, it would be cool to know WHAT exactly goes wrong when using Run, which would be the first step to debugging the problem.
Thanks for your answers Vsai and Bobo,
I tried Evaluating from the menu, same result as using Ctrl+E, so still working.
What happens when I Run Script instead, is that the mirrored target turns into the Base mesh, rather than the mirror of the Morph Target.
I’m rather confused as to why this happens, the script is pretty short, I’ve tried commenting out small parts of the script, but with no success so far.
I might be stating the obvious, but your code ASSUMES that the base mesh is the object selected FIRST and the other is the second in selection. Max generally remembers the order of selecting things, so theoretically picking the base object, then holding down CTRL and clicking the second object should preserve that order in the $selection object set. I wonder if calling the Run… is in some way inverting this order…
I tried a short script that contains only two lines – print selection[1]; print selection[2]
I tried to evaluate it with Ctrl+E and Run Script and got the same order of selected objects in both cases. Needless to say I have not experienced this before…
It looks to be a scope problem- putting the script in parenthesis and evaluating yields the ‘Run Script’ result. I don’t think the time is changing, but I’m looking now.
And the problem is definitely something to do with the selection[] lines (assigning an object like $Sphere01 works correctly both ways). Even though basemesh and leftexpression are not undefined, they are not being added to the morph modifier- this is the cause of the result.
And interesting enough, the “WM3_MC_BuildFromNode” function that is not working is returning ‘true’ nonetheless.
(
local base = selection[1]
local theMorph = selection[2]
local m = Morpher()
WM3_MC_BuildFromNode m 1 base
addModifier theMorph m
)
That doesn’t work (base is not added as a target to the morph modifier), no matter what I do with the modifier. I think this is a bug, also using Max 2008 32 bit on XP SP2. Also same result on Max 9 32 bit.
Yeah the selection[1], selection[2] part is definetely a bit hackish, and I suspected that as well. But I went ahead and built an interface with pickbuttons, and it gives the wrong result as well. The reason I used selection[1] selection[2] is that is was just intended as a quick fix to get some morph targets mirrored here and now. The thing is, I’ve tried adding prints to all sorts of places in the script, and it IS returning the right objects, but it’s simply not working when “Run”, only when evaluated from editor. Can any of you confirm (or deny) the errors I’ve seen (ie, it works when evaluated, fails when Run Script) ? I’ve tried it myself, and the animator (who discovered the error) has the same problem on a seperate PC, but it’s such a strange error that I still think it might be some quirk we’re only having with our installations (though there’s little to no custom stuff about them except for having a lot of versions of Max installed, in some cases all the way back to Max 6).