Trying to debug a simple script
I'm just learning scripting and trying to write a script to automate the process of creating blend shapes based on a world space modifier. I have a plane that is projected via conform space warp onto an animated object. What I do is scrub from one frame to the next, duplicating the projected geo, collapsing to the WSM modifier in the stack (which creates a static mesh "snapshot" of the mesh) which I can later use as blend shapes. The steps I want to perform with the script are:
- duplicate selected mesh
- collapse to WSM on duped mesh
- rename new mesh with current frame number
- repeat for each frame in slider range
- pop up a "done" window when finished
So far, I have one version that works, but doesn't scrub through the timeline itself. I have to run the script for each frame:
BaseMorphMesh = $ clearSelection() CurrentFrame = sliderTime EndFrame = animationRange.end if CurrentFrame < EndFrame then ( select BaseMorphMesh CurrentFrameName = sliderTime as string TrimmedFrameName = trimright CurrentFrameName "f" maxOps.cloneNodes $ cloneType:#copy newNodes:&nnl select nnl $.name = TrimmedFrameName maxOps.CollapseNodeTo $ 1 true move $ [200,0,0] clearSelection() sliderTime += 1 ) else messageBox "Done"
and another version which seems to generate the proper snapshots, but gets stuck in some kind of death loop and freezes up Max:
BaseMorphMesh = $ clearSelection() CurrentFrame = sliderTime EndFrame = animationRange.end while CurrentFrame < EndFrame do ( select BaseMorphMesh CurrentFrameName = sliderTime as string TrimmedFrameName = trimright CurrentFrameName "f" maxOps.cloneNodes $ cloneType:#copy newNodes:&nnl select nnl $.name = TrimmedFrameName maxOps.CollapseNodeTo $ 1 true move $ [200,0,0] clearSelection() sliderTime += 1 ) when CurrentFrame == EndFrame do messageBox "Done"
I tried defining the process as a function as well, but my syntax is apparently wrong and it doesn't seem to call the function:
BaseMorphMesh = $ clearSelection() fn stuff = ( select BaseMorphMesh CurrentFrameName = sliderTime as string TrimmedFrameName = trimright CurrentFrameName "f" maxOps.cloneNodes $ cloneType:#copy newNodes:&nnl select nnl $.name = TrimmedFrameName maxOps.CollapseNodeTo $ 1 true move $ [200,0,0] clearSelection() sliderTime += 1 ) CurrentFrame = sliderTime EndFrame = animationRange.end if CurrentFrame < EndFrame then stuff else messageBox "Done"
Any advice would be much appreciated.
Comments
Fixed
Nevermind. Function call didn't have parentheses after, works now.