ScalePoints problems

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
len
Posts: 22
Joined: Thu Jun 22, 2006 10:26 pm

ScalePoints problems

Post 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!
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post 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.
- - - Fazek
len
Posts: 22
Joined: Thu Jun 22, 2006 10:26 pm

Post 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!
len
Posts: 22
Joined: Thu Jun 22, 2006 10:26 pm

Post 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
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post 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.
len
Posts: 22
Joined: Thu Jun 22, 2006 10:26 pm

Post by len »

Awesome! Thanks 7feet! That totally did the trick. I'll keep an eye on that keyframe issue from now on.
Post Reply