Grid maker
Moderators: Víctor Paredes, Belgarath, slowtiger
Grid maker
This is simple grid maker. Idea: Ramón López.
http://bogush-r.narod.ru/moho/scripts/rb_grid.lua
2 7Feet: Thank You for helpful answers on my silly questions
Roman.
http://bogush-r.narod.ru/moho/scripts/rb_grid.lua
2 7Feet: Thank You for helpful answers on my silly questions
Roman.
I like the tool, and in some situations it's very usefull, and saves a lot of time. There are somethings that could get better (there were a couple of extra points on some places, and some other small things) but otherwise it's good. I made a quick test with it and came up with this (just in case your intrested):


...WOA!
What a SURPRISE!!! That it means that ALL that scripting ideas posted in the past will come with the time??
I'd be a DREAM!
...Jaja, THANK YOU VERY MUCH bogush_r, this can save lots of time! I specially use that kind of grids to can make an "Universal Grids" (checking "Inmune to Camera Movements") to have a grid that doesn't transform with the camera and use it like a guide in all the proyect... SO thank you again and *CIAO*




I made some enhances in GridMaker script.
(Old bugs was fixed and new added
)
http://bogush-r.narod.ru/moho/scripts/rb_grid.lua
(Old bugs was fixed and new added

http://bogush-r.narod.ru/moho/scripts/rb_grid.lua
Roman Bogush.







- Víctor Paredes
- Site Admin
- Posts: 5814
- Joined: Wed Jan 26, 2005 12:18 am
- Location: Barcelona/Chile
- Contact:
- Víctor Paredes
- Site Admin
- Posts: 5814
- Joined: Wed Jan 26, 2005 12:18 am
- Location: Barcelona/Chile
- Contact:
OK, Ulrik just send me the script by e-mail. Thank you so much, Ulrik!
Now, this script is so useful I want don't get lost again, so instead uploading to some free server I prefer to paste it here.
If someone want to use it, just copy this tiny letters and paste them on notepad, then save it as rb_grid.lua and save it on the folder anime studio/scripts/tool
Then, on the file _tool_list.txt add this line
button rb_grid ...
Now, this script is so useful I want don't get lost again, so instead uploading to some free server I prefer to paste it here.
If someone want to use it, just copy this tiny letters and paste them on notepad, then save it as rb_grid.lua and save it on the folder anime studio/scripts/tool
Then, on the file _tool_list.txt add this line
button rb_grid ...
#####################################################
-- Simple Grid maker by Roman Bogush (c)2005
-- To use just copy it in $MOHO/scripts/menu folder
-- #####################################################
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "RB_Grid"
-- **************************************************
-- General information about this script
-- **************************************************
RB_Grid = {}
function RB_Grid:Name()
return "Grid"
end
function RB_Grid:Version()
return "0.1.1"
end
function RB_Grid:Description()
return "Creates a new grid in the current layer."
end
function RB_Grid:Creator()
return "Roman Bogush"
end
function RB_Grid:UILabel()
return("Grid...")
end
-- **************************************************
-- Grid dialog
-- **************************************************
RB_Grid.SzH = 5
RB_Grid.SzV = 3
local RB_GridDialog = {}
function RB_GridDialog:new(moho)
local d = LM.GUI.SimpleDialog("Grid", RB_GridDialog)
local l = d:GetLayout()
d.moho = moho
l:PushV()
l:AddChild(LM.GUI.StaticText("Dimensions:"), LM.GUI.ALIGN_LEFT)
l:Indent()
l:PushH()
l:PushV()
l:AddChild(LM.GUI.StaticText("Horizontal cells:"), LM.GUI.ALIGN_LEFT)
l:AddChild(LM.GUI.StaticText("Vertical cells:"), LM.GUI.ALIGN_LEFT)
l:Pop()
l:PushV()
d.SzH = LM.GUI.TextControl(0, "0000", 0, LM.GUI.FIELD_UINT)
l:AddChild(d.SzH)
d.SzV = LM.GUI.TextControl(0, "0000", 0, LM.GUI.FIELD_UINT)
l:AddChild(d.SzV)
l:Pop()
l:Pop()
l:Unindent()
l:AddChild(LM.GUI.Divider(false), LM.GUI.ALIGN_FILL)
l:PushV()
l:AddChild(LM.GUI.StaticText("Fill:"), LM.GUI.ALIGN_LEFT)
l:Indent()
l:PushV()
d.FillNone = LM.GUI.RadioButton("None")
l:AddChild(d.FillNone, LM.GUI.ALIGN_LEFT)
d.FillChess = LM.GUI.RadioButton("Chess board")
l:AddChild(d.FillChess, LM.GUI.ALIGN_LEFT)
d.FillRandom = LM.GUI.RadioButton("Random colors")
l:AddChild(d.FillRandom, LM.GUI.ALIGN_LEFT)
l:Pop()
l:Unindent()
l:PushH()
l:AddChild(LM.GUI.StaticText("Fill with colors:"), LM.GUI.ALIGN_LEFT)
d.FillColor1 = LM.GUI.ColorSwatch(true, 10001)
l:AddChild(d.FillColor1, LM.GUI.ALIGN_RIGHT)
d.FillColor2 = LM.GUI.ColorSwatch(true, 10002)
l:AddChild(d.FillColor2, LM.GUI.ALIGN_RIGHT)
l:Pop()
l:AddChild(LM.GUI.Divider(false), LM.GUI.ALIGN_FILL)
l:PushV()
l:AddChild(LM.GUI.StaticText("Outline:"), LM.GUI.ALIGN_LEFT)
l:Indent()
l:PushV()
d.OutLine = LM.GUI.CheckBox("Outline cells")
l:AddChild(d.OutLine, LM.GUI.ALIGN_LEFT)
l:Pop()
l:Unindent()
l:Pop()
l:Pop()
return d
end
function RB_GridDialog:UpdateWidgets()
self.SzH:SetValue(RB_Grid.SzH)
self.SzV:SetValue(RB_Grid.SzV)
self.FillColor1:SetValue(RB_Grid.FillColor1:AsColorStruct())
self.FillColor2:SetValue(RB_Grid.FillColor2:AsColorStruct())
self.FillNone:SetValue(RB_Grid.FillMode == 1)
self.FillChess:SetValue(RB_Grid.FillMode == 2)
self.FillRandom:SetValue(RB_Grid.FillMode == 3)
self.OutLine:SetValue(RB_Grid.OutLine)
end
function RB_GridDialog:OnValidate()
local b = true
if (not self:Validate(self.SzH, 2, 50)) then
b = false
end
if (not self:Validate(self.SzV, 2, 50)) then
b = false
end
return b
end
function RB_GridDialog:OnOK()
RB_Grid.SzH = self.SzH:IntValue()
RB_Grid.SzV = self.SzV:IntValue()
RB_Grid.FillColor1:Set(self.FillColor1:Value())
RB_Grid.FillColor2:Set(self.FillColor2:Value())
if (self.FillNone:Value()) then
RB_Grid.FillMode = 1
elseif (self.FillChess:Value()) then
RB_Grid.FillMode = 2
else
RB_Grid.FillMode = 3
end
RB_Grid.OutLine = self.OutLine:Value()
end
-- **************************************************
-- The guts of this script
-- **************************************************
CHESS = true
HORIZONTAL = 0
VERTICAL = 1
PID = {}
RB_Grid.FillColor1 = LM.ColorVector:new_local()
RB_Grid.FillColor1:Set(0, 0, 0)
RB_Grid.FillColor2 = LM.ColorVector:new_local()
RB_Grid.FillColor2:Set(1,1,1)
RB_Grid.FillMode = 1
RB_Grid.OutLine = true
function RB_Grid:IsEnabled(moho)
if (moho.layer:LayerType() ~= MOHO.LT_VECTOR) then
return false
end
if (moho.layer:CurrentAction() ~= "") then
return false -- creating new objects in the middle of an action can lead to unexpected results
end
return true
end
function DrawLine(moho, P, C, segments, dir)
local mesh = moho:Mesh()
local RL, RP
if dir == VERTICAL then
RL = moho.document:AspectRatio()
RP = 1
else
RL = 1
RP = moho.document:AspectRatio()
end
-- Space between lines
local Lstep = 2 * RL / C
-- Space between points
local Pstep = 2 * RP / segments
local v = LM.Vector2:new_local()
if(dir == HORIZONTAL) then
v.x = -1 * moho.document:AspectRatio()
v.y = -1 + Lstep * P
else
v.x = -1 * moho.document:AspectRatio() + Lstep * P
v.y = -1
end
for i = 0, segments do
if i == 0 then
mesh:AddLonePoint(v, 0)
else
if(dir == HORIZONTAL) then
v.x = v.x + Pstep
else
v.y = v.y + Pstep
end
mesh:AppendPoint(v, 0)
end
if dir == HORIZONTAL then
if PID[P] == nil then PID[P] = {} end
local tmp = LM.Vector2:new_local()
tmp:Set(v)
PID[P] = tmp
end
end
end -- Of DrawLine
function RB_Grid:Run(moho)
local dlog = RB_GridDialog:new(moho)
if (dlog:DoModal() == LM.GUI.MSG_CANCEL) then
return
end
local mesh = moho:Mesh()
if (mesh == nil) then
return
end
local SzH = RB_Grid.SzH
local SzV = RB_Grid.SzV
local HPcnt = (1+SzV) *(1+ SzH) - 1
local oldPcnt = mesh:CountPoints()
moho.document:PrepUndo(moho.layer)
moho.document:SetDirty()
mesh:SelectNone()
-- Draw horizonal lines (vertical demension)
for i = 0, SzV do
DrawLine(moho, i, SzV, SzH, HORIZONTAL)
end
-- Draw vertical lines (horizontal demension)
for i = 0, SzH do
DrawLine(moho, i , SzH, SzV, VERTICAL)
end
for i = 0, SzV do
for j = 0, SzH do
local v = PID[j]
-- print(i, v.x, v.y)
local hp = mesh:ClosestPoint(v, -1, oldPcnt + HPcnt)
local vp = mesh:ClosestPoint(v, hp, mesh:CountPoints() + 1)
mesh:WeldPoints(hp, vp,0)
end
end
for i = 0, HPcnt do
mesh:Point( oldPcnt + i) :SetCurvature(MOHO.PEAKED, 0)
end
if RB_Grid.FillMode ~= 1 then
mesh:SelectNone()
local white = true
local prev = false
for i = 0, SzH - 1 do
for j = 0, SzV - 1 do
local color = LM.ColorVector:new_local()
mesh:Point(oldPcnt + i * (SzV+1) + j).fSelected = true
mesh:Point(oldPcnt + i * (SzV+1) + j + 1).fSelected = true
mesh:Point(oldPcnt + i * (SzV+1) + j+SzV + 1).fSelected = true
mesh:Point(oldPcnt + i * (SzV+1) + j+SzV + 2).fSelected = true
local id = moho:CreateShape(true)
mesh:Shape(id):RemoveStyles()
mesh:Shape(id).fHasOutline = false
if RB_Grid.FillMode == 2 then
if j == 0 then
if prev then
white = false
prev = false
else
white = true
prev = true
end
end
if white then
white = false
color:Set(RB_Grid.FillColor2:AsColorStruct())
else
white = true
color:Set(RB_Grid.FillColor1:AsColorStruct())
end
else
color.r = MOHO.RandomRange(RB_Grid.FillColor1.r, RB_Grid.FillColor2.r)
color.g = MOHO.RandomRange(RB_Grid.FillColor1.g, RB_Grid.FillColor2.g)
color.b = MOHO.RandomRange(RB_Grid.FillColor1.b, RB_Grid.FillColor2.b)
color.a = MOHO.RandomRange(RB_Grid.FillColor1.a, RB_Grid.FillColor2.a)
end
mesh:Shape(id).fMyStyle.fDefineFillCol= true
mesh:Shape(id).fMyStyle.fFillCol:SetValue(0, color:AsColorStruct())
mesh:SelectNone()
end -- for j
end -- for i
end -- FillMode == NONE (1)
if RB_Grid.OutLine then
for i = oldPcnt, oldPcnt + HPcnt do
mesh:Point(i).fSelected = true
end
moho:CreateShape(false)
end
end
- windstormer
- Posts: 40
- Joined: Wed May 27, 2009 3:36 am
Thanks for the help on getting this copied and on to the correct place. I'm having a little trouble figuring out where on the _tool_list.txt I should place this. Nothing seems to appear in the program after I place it on it. I saved the rd_grid.lua in the location also and restarted ASP. Any ideas what I could be doing wrong?
Thanks.
Thanks.
Windstormer wrote :
1/ Add "group Other" (if not already done) then add "button rb_grid ..." at the end of the _tool_list.txt
2/Create a small button image and name it "rb_grid.png", like this one for instance:
http://www.mediafire.com/?sharekey=304c ... 49b5870170
And put it in the script/tool folder.
That's all.
What worked for me:I'm having a little trouble figuring out where on the _tool_list.txt I should place this. Nothing seems to appear in the program after I place it on it. I saved the rd_grid.lua in the location also and restarted ASP. Any ideas what I could be doing wrong?
1/ Add "group Other" (if not already done) then add "button rb_grid ..." at the end of the _tool_list.txt
2/Create a small button image and name it "rb_grid.png", like this one for instance:
http://www.mediafire.com/?sharekey=304c ... 49b5870170
And put it in the script/tool folder.
That's all.
- Víctor Paredes
- Site Admin
- Posts: 5814
- Joined: Wed Jan 26, 2005 12:18 am
- Location: Barcelona/Chile
- Contact:
- windstormer
- Posts: 40
- Joined: Wed May 27, 2009 3:36 am
Also does this lua script work with Pro 6?
Last edited by windstormer on Wed Jul 08, 2009 4:43 pm, edited 1 time in total.
- windstormer
- Posts: 40
- Joined: Wed May 27, 2009 3:36 am
That's odd. for some reason it still isn't showing in my tools, it doesn't even show an "Other" section. I place both files(lua and png) in the Smith Micro/Anime Studio Pro 6/scripts/tool. Does this method work with Pro 6?
Here is my _tool_list.txt. Would you be able to see what I did wrong?:
group Draw
tool lm_select_points G
tool lm_translate_points T
tool lm_scale_points S
tool lm_rotate_points R
tool lm_add_point A
tool lm_freehand F
tool lm_shape E
button lm_insert_text ...
tool lm_scatterbrush ...
tool lm_delete_edge D
tool lm_curvature C
tool lm_magnet X
tool lm_perspective_points ...
tool lm_shear_points ...
tool lm_bend_points ...
tool lm_noise N
group Fill
tool lm_select_shape Q
tool lm_create_shape U
tool lm_paint_bucket P
tool lm_delete_shape ...
tool lm_eyedropper ...
tool lm_line_width W
tool lm_hide_edge H
group Bone
tool lm_select_bone B
tool lm_translate_bone T
tool lm_scale_bone S
tool lm_rotate_bone R
tool lm_add_bone A
tool lm_reparent_bone P
tool lm_bone_strength ...
tool lm_manipulate_bones Z
tool lm_bind_layer ...
tool lm_bind_points I
tool lm_offset_bone ...
group Layer
tool lm_translate_layer 1
tool lm_scale_layer 2
tool lm_rotate_layer 3
tool lm_set_origin 0
tool lm_rotate_layer_xy ...
tool lm_shear_layer ...
tool lm_switch_layer ...
tool lm_particle_layer ...
tool lm_video_tracking A
group Camera
tool lm_track_camera 4
tool lm_zoom_camera 5
tool lm_roll_camera 6
tool lm_pantilt_camera 7
group Workspace
tool lm_pan_workspace ...
tool lm_zoom_workspace ...
tool lm_rotate_workspace 8
tool lm_orbit_workspace 9
group Other
button rb_grid ...
Thanks for any help.
Here is my _tool_list.txt. Would you be able to see what I did wrong?:
group Draw
tool lm_select_points G
tool lm_translate_points T
tool lm_scale_points S
tool lm_rotate_points R
tool lm_add_point A
tool lm_freehand F
tool lm_shape E
button lm_insert_text ...
tool lm_scatterbrush ...
tool lm_delete_edge D
tool lm_curvature C
tool lm_magnet X
tool lm_perspective_points ...
tool lm_shear_points ...
tool lm_bend_points ...
tool lm_noise N
group Fill
tool lm_select_shape Q
tool lm_create_shape U
tool lm_paint_bucket P
tool lm_delete_shape ...
tool lm_eyedropper ...
tool lm_line_width W
tool lm_hide_edge H
group Bone
tool lm_select_bone B
tool lm_translate_bone T
tool lm_scale_bone S
tool lm_rotate_bone R
tool lm_add_bone A
tool lm_reparent_bone P
tool lm_bone_strength ...
tool lm_manipulate_bones Z
tool lm_bind_layer ...
tool lm_bind_points I
tool lm_offset_bone ...
group Layer
tool lm_translate_layer 1
tool lm_scale_layer 2
tool lm_rotate_layer 3
tool lm_set_origin 0
tool lm_rotate_layer_xy ...
tool lm_shear_layer ...
tool lm_switch_layer ...
tool lm_particle_layer ...
tool lm_video_tracking A
group Camera
tool lm_track_camera 4
tool lm_zoom_camera 5
tool lm_roll_camera 6
tool lm_pantilt_camera 7
group Workspace
tool lm_pan_workspace ...
tool lm_zoom_workspace ...
tool lm_rotate_workspace 8
tool lm_orbit_workspace 9
group Other
button rb_grid ...
Thanks for any help.
- Víctor Paredes
- Site Admin
- Posts: 5814
- Joined: Wed Jan 26, 2005 12:18 am
- Location: Barcelona/Chile
- Contact: