[Closed] maptoview failure
hello, created this little script, so that i can select and object, press a button, and have it mapped to view.
unfortunately, i get an error message when i try and run it as a button, although it works
without a hitch as a script. what have i done wrong.
macroScript MaptoView
category:“mine”
toolTip:“yes”
(
addmodifier $ (unwrap_uvw())
subobjectLevel = 3
max select all
$.unwrap_uvw.mappingmode 1
$.unwrap_uvw.mappingAlignToView()
$.modifiers[#unwrap_uvw].unwrap5.setNormalizeMap off
$.unwrap_uvw.mappingmode 1
$.unwrap_uvw.pack 1 0.0 true false false
)
As usual, this is a case where executing the lines one by one from the Listener works as expected, but putting everything into a macroscript fails because the modifier stack has not updated at the moment where the method is called.
Once again, the solution is as simple as it is hacky – call classof $ before calling the .mappingAlignToView() method to force a modifier stack update:
macroScript MapToView
category:"Forum Help"
toolTip:"Map To View Fixed"
(
on isEnabled return selection.count == 1 and modPanel.ValidModifier unwrap_uvw
on execute do
(
theMod = unwrap_uvw()
addmodifier $ theMod
subobjectLevel = 3
max select all
theMod.mappingmode 1
classof $ --FORCE STACK UPDATE
theMod.mappingAlignToView()
theMod.unwrap5.setNormalizeMap off
theMod.mappingmode 1
theMod.pack 1 0.0 true false false
)
)
I am guessing, but I think you didnt run you script while you were on the modifier panel. If you add this line to the begining of your code it wont give you a system exception.
[color=white][/color]
[color=white]max[/color][size=2] modify mode
[/size]
-RyanT
i tried that, evaluated, and still get a system exception when running it as a macroscripted button.
although that max modify mode fixed another bug i experienced with this.
HI,
try this:
macroScript MaptoView
category:“mine”
toolTip:“yes”
(
max modify mode
addmodifier $ (unwrap_uvw())
local uv=modpanel.getcurrentObject()
subobjectLevel = 3
max select all
uv.mappingmode 1
uv.mappingAlignToView()
uv.unwrap5.setNormalizeMap off
uv.mappingmode 1
uv.pack 1 0.0 true false false
subobjectLevel = 0
)
well, it didn’t create any errors, but the line
uv.mappingmode and uv.mappingaligntoview()
are not doing what they’re supposed to, IE nothings happending.