Page 1 of 1
ScalePoints problems
Posted: Mon Aug 07, 2006 10:21 am
by len
Hi all.
I'm fairly new to scripting and was trying what seems to be simple.
I am accessing the points in a mesh and I want to scale them.
I'm using this code:
mesh = moho:Mesh()
mesh:SelectAll()
mesh:ScalePoints(4, 4, mesh:SelectedCenter())
Everything goes through fine and all the points are selected, but no transformations. I am expecting the points to separate by 4 times their current position relative to the center. Nothing at all happens besides being selected.
Any ideas what I'm missing here? Thanks!
Posted: Mon Aug 07, 2006 12:39 pm
by Fazek
mesh = moho:Mesh()
mesh:SelectAll()
mesh:PrepMovePoints()
mesh:ScalePoints(4, 4, mesh:SelectedCenter())
PrepMovePoints copies the actual fPos variables into fTempPos for the points and ScalePoints reads fTempPos and writes fPos when operating.
Posted: Mon Aug 07, 2006 5:26 pm
by len
Wow, thanks for the quick reply Fazek!
I tried your fix but there still seems to be something missing.
Here's the code I'm trying and I still only get the points to select but no movement. Is there anything I have to do AFTER the ScalePoints command? It's definitely getting to SelectAll since I see the points select.
Any other conditions you can think of that would make the scale fail?
mesh:SelectAll()
mesh:PrepMovePoints()
mesh:ScalePoints(4, 4, mesh:SelectedCenter())
Thanks!
Posted: Wed Aug 09, 2006 6:50 am
by len
In case someone wants to check out the full script, here it is, a menu script. I'm still baffled as to why it doesn't do anything!
-- **************************************************
-- Provide Moho with the name of this scrippt object
-- ***************************************************
ScriptName = "LW_SCALE_POINTS"
-- ***************************************************
-- General information about this script
-- ***************************************************
LW_LuaUtils = {}
LW_SCALE_POINTS = {}
LW_SCALE_POINTS.MAJOR_VERSION = 1
LW_SCALE_POINTS.MINOR_VERSION = 1
function LW_SCALE_POINTS:Name()
return("LW_SCALE_POINTS")
end
function LW_SCALE_POINTS:Version()
return "" .. LW_SCALE_POINTS.MAJOR_VERSION .. ".".. LW_SCALE_POINTS.MINOR_VERSION
end
function LW_SCALE_POINTS:Description()
return "Scale points in a layer"
end
function LW_SCALE_POINTS:Creator()
return "Len White"
end
function LW_SCALE_POINTS:UILabel()
return "LW: Scale all points in layer"
end
-- ***************************************************
-- Recurring values
-- ***************************************************
LW_SCALE_POINTS.file = {}
-- ***************************************************
-- The guts of this script
-- ***********************************************
function LW_SCALE_POINTS:Run(moho)
local curLayer = moho.layer
local mesh
if ( curLayer == nil ) then
return
end
local curLayerType = curLayer:LayerType()
if ( curLayerType == MOHO.LT_VECTOR) then
mesh = moho:Mesh()
mesh:SelectAll()
mesh:PrepMovePoints()
mesh:ScalePoints(4, 4, mesh:SelectedCenter())
else
return
end
end
Posted: Wed Aug 09, 2006 8:58 am
by 7feet
One more addition...
Code: Select all
function LW_SCALE_POINTS:Run(moho)
local curLayer = moho.layer
local mesh
if ( curLayer == nil ) then
return
end
local curLayerType = curLayer:LayerType()
if ( curLayerType == MOHO.LT_VECTOR) then
mesh = moho:Mesh()
mesh:SelectAll()
mesh:PrepMovePoints()
mesh:ScalePoints(.5, .4, mesh:SelectedCenter())
moho:AddPointKeyframe(moho.frame)
end
end
Seems to do the trick. Guess Moho doesn't think it's real until you create a keyframe.
Posted: Wed Aug 09, 2006 5:15 pm
by len
Awesome! Thanks 7feet! That totally did the trick. I'll keep an eye on that keyframe issue from now on.