[Closed] slice plane automation utility
(hope this is no double post)
This is my first attempt at maxScript; it serves to slice a editable poly at a set interval. My problem is the following error:
>> MAXScript Rollout Handler Exception: – Argument count error: getSlicePlane wanted 3, got 1 <<
– Error occurred in btn1.pressed(); filename: C:dsmax2008Scriptsslic2.ms; position: 936
Ok, I know I need to provide 3 args, but don’t know what to fill in. I just want to operate the sliceplane on the selected object. $.EditablePoly as the first arg might work. please help. Here’s the code
– This rollout serves to automate a sliceplane
rollout SliceIt “SliceIt” width:199 height:300
(
radiobuttons direction “Move Direction” pos:[9,118] width:97 height:30 labels:#(“X”, “Y”, “Z”) columns:3
spinner trans “move” pos:[26,69] width:73 height:16 range:[0,100,0]
button btn1 “Do it!” pos:[45,202] width:90 height:29
spinner iterations “iterations” pos:[25,90] width:79 height:16 type:#integer
on btn1 pressed do
(
if($.EditablePoly.inSlicePlaneMode()) then
(
planeRay = $.EditablePoly.getSlicePlane($.EditablePoly)
curRay = copy planeRay
if (direction.value==“X”) then
(
incrementArray = [trans.value,0,0]
) else if(direction.value==“Y”) then
(
incrementArray = [0,trans.value,0]
) else if(direction.value==“Z”) then
(
incrementArray = [0,0,trans.value]
)
for i = 1 to iterations.value do
(
$.EditablePoly.slice curRay flaggedFacesOnly:on
curRay.pos = CurRay.pos + incrementArray
)
)
)
)
newroll=newrolloutfloater “Slice It” 260 302 750 80
addrollout SliceIt newroll
This is the maxscript reference:
[left]polyop.getSlicePlane <Poly poly>
size:<&size_float_var> node:<node=unsupplied>
[/left]
[left]Returns
the location and direction of the slice plane as a Ray value. If <size> is specified, the size
of the slice plane is returned in the referenced variable. If <poly> is a node, or if
<poly> is an Editable Poly and
<node> is specified, the ray
returned is in the current coordinate system context. If <poly> is an Editable Poly and
<node> is not specified, the
return value is in the poly’s local coordinate
system.
[/left]
HI,
Well, you are confusing the EditablePoly and Polyop interfaces.
also, radiobuttions have a state property, not a value property.
here is the editablePoly version:
(
-- This rollout serves to automate a sliceplane
rollout SliceIt "SliceIt" width:199 height:300
(
radiobuttons direction "Move Direction" pos:[9,118] width:97 height:30 labels:#("X", "Y", "Z") columns:3
spinner trans "move" pos:[26,69] width:73 height:16 range:[0,100,0]
button btn1 "Do it!" pos:[45,202] width:90 height:29
spinner iterations "iterations" pos:[25,90] width:79 height:16 type:#integer
on btn1 pressed do
(
-- store the selected object
obj=selection[1]
if classof obj==Editable_poly do
(
if(obj.EditablePoly.inSlicePlaneMode()) then
(
-- define variables to be passed as reference to the getSlicePlane function
plane_normal = Point3 0 0 0
plane_center = Point3 0 0 0
plane_size = 1.0
-- this fills the variables with the current slice pane
obj.EditablePoly.getSlicePlane &plane_normal &plane_center &plane_size
-- Check the radiobuttons state
increment = case direction.state of
(
1: [trans.value,0,0]
2: [0,trans.value,0]
3: [0,0,trans.value]
)
-- add an undo context
With undo "Slice it" on
(
for i = 1 to iterations.value do
(
-- slice the selected faces
obj.EditablePoly.slice plane_normal plane_center flaggedFacesOnly:on
-- move the slice plane
plane_center += increment
)
)
)
)
)
)
newroll=newrolloutfloater "Slice It" 260 302 750 80
addrollout SliceIt newroll
)
and for fun, this is the polyop version
no need to be in subobject mode or in slice plane mode.
(
-- This rollout serves to automate a sliceplane
rollout SliceIt "SliceIt" width:199 height:300
(
radiobuttons direction "Move Direction" pos:[9,118] width:97 height:30 labels:#("X", "Y", "Z") columns:3
spinner trans "move" pos:[26,69] width:73 height:16 range:[0,100,0]
button btn1 "Do it!" pos:[45,202] width:90 height:29
spinner iterations "iterations" pos:[25,90] width:79 height:16 type:#integer
on btn1 pressed do
(
-- store the selected object
obj=selection[1]
if classof obj==Editable_poly do -- is it an Ediotable_Poly ?
(
planeRay = polyop.getSlicePlane obj
-- Check the radiobuttons state
increment = case direction.state of
(
1: [trans.value,0,0]
2: [0,trans.value,0]
3: [0,0,trans.value]
)
-- grab the face selection - if no faces selected operate on the whole object
sel=polyop.getFaceSelection obj
if sel.numberset==0 do sel=#{1..(polyop.getNumFaces obj)}
-- add an undo context, just in case ;)
With undo "Slice it" on
(
for i = 1 to iterations.value do
(
polyop.slice obj sel planeRay
planeRay.pos += increment
)
)
)
)
)
newroll=newrolloutfloater "Slice It" 260 302 750 80
addrollout SliceIt newroll
)
2 for the price of 1, sweet ?
Honey sweet
I’ll try it when I get home. My knowledge is real shallow, so my failure was imminent. I really need it though. Trying to make ventilation grills for a tube tv; gaps are placed at 3 mm intervals!
I wrote a similar script a while back called julienne.
macroScript Julienne
category:"Pongoloid"
buttonText:"Julienne"
toolTip:"Julienne"
(
undolabel = "Julienne"
rollout julienne "Julienne"
(
checkbox Xcheck "X"
checkbox Ycheck "Y"
checkbox Zcheck "Z"
spinner XSpin type:#integer range:[2,100,2] pos:[45,5]
spinner YSpin type:#integer range:[2,100,2] pos:[45,24]
spinner ZSpin type:#integer range:[2,100,2] pos:[45,44]
button dice "Dice" pos:[120,5] height:55
on dice pressed do
(
try
(
undo label:undolabel on
(
p = (selection as array)[1]
zeroed = quat 0 0 0 1
sticker = p.rotation
p.rotation = zeroed
SliceMin = p.min
SliceMax = p.max
if xcheck.checked == true then
(
xchops = xspin.value
)
else
(
xchops = undefined
)
if ycheck.checked == true then
(
ychops = yspin.value
)
else
(
ychops = undefined
)
if Zcheck.checked == true then
(
zchops = zspin.value
)
else
(
zchops = undefined
)
if xchops != undefined then
(
slicelen = slicemax-slicemin
slicelen = slicelen/xchops
for i = 1 to (xchops-1) do
(
slicepoint = [(slicemin.x+(i*slicelen.x)), (slicemin.y+(i*slicelen.y)), (slicemin.z+(i*slicelen.z))]
p.slice [1,0,0] (slicepoint-p.pos)
)
)
if ychops != undefined then
(
slicelen = slicemax-slicemin
slicelen = slicelen/ychops
for i = 1 to (ychops-1) do
(
slicepoint = [(slicemin.x+(i*slicelen.x)), (slicemin.y+(i*slicelen.y)), (slicemin.z+(i*slicelen.z))]
p.slice [0,1,0] (slicepoint-p.pos)
)
)
if zchops != undefined then
(
slicelen = slicemax-slicemin
slicelen = slicelen/zchops
for i = 1 to (zchops-1) do
(
slicepoint = [(slicemin.x+(i*slicelen.x)), (slicemin.y+(i*slicelen.y)), (slicemin.z+(i*slicelen.z))]
p.slice [0,0,1] (slicepoint-p.pos)
)
)
p.rotation = sticker
) -- end Undo
) -- end try
catch (messagebox "Something went wrong. Make sure it's an editable poly.")
) -- end on "Dice"
)
createdialog julienne
)
First off, thanks for these scripts, they are incredibly useful and I’m surprised there is not a wider need for these. I’ve been moving the slice plane manually for far too long and have finally started to look into scripting something and luckily stumbled across these.
I’ve tried using both the editable poly version as well as the polyop version and have a slight issue. I have to press the button to perform each iteration rather than the script running through the loop automatically. I’ve looked into the script a bit and nothing seems glaringly wrong.
Any ideas as to what could be going on?
Cheers.