cbass
05-12-2008, 09:07 PM
Hi everyone,
I’m having an issue in the following script.
In an earlier version of this script, an pre-drawn object (“Pyramid01” ) is copied and aligned to one of its 12 faces. The face is referenced using a variable “n” and a number between 1 and 12 (changing the n variable value from 1-12 changes the location of the new object). This worked fine.
However, I wanted to designate the face using letters instead of numbers, so I added the “case of” statement. When the script runs, some letters (like “d” for instance) don’t return the right value and the newly placed shape ends up in the wrong place. Other times, the letters don’t seem to affect the outcome at all and the shape keeps getting placed at the same location (is this a scope issue?). I probably have incorrect syntax for the “case of” expression too, but I’ve looked at the help and online and this is the best I’ve come up with (and like I said, it has worked intermittently in the past).
I’m including both the script that works with numbers, the script I’m having issues with and the file that goes with either script, if anyone has the time/inclination to help. I’m still a noob when it comes to programming, so any suggestions are welcome.
TIA!
Carlo
---------------------------
original working code
-- This is a sample code using "Rhombic Dodecahedron super clean 05 10 2008.max" file.
-- The file has one object of Editable-Poly whose pivot is located (0,0,0) and named as "Pyramid01"
-- This is to move a copied object to the position of other face(n).
a = $Pyramid01 -- original object
b = copy a -- keep one
n = 2 -- index of face in Box01 range [1 ~ 12] -- Change this value to change position of object
firstID = 2 -- there are two cases 2 or 4 to speciy the X local axis using the 2nd or 4th vertex.
theCenter = polyOp.getFaceCenter a n --Nth face's center
axisZ = polyOp.getFaceNormal a n --the normal direction of Nth face
theVert = (a.GetFaceVertex n firstID) -- get the second vertexID of Nth face
theVertPos=polyOp.GetVert a theVert -- get the world position of the vertex
axisX =normalize [(theVertPos.x - theCenter.x), (theVertPos.y - theCenter.y), (theVertPos.z-theCenter.z)] -- create local X-axis
axisY = normalize (cross axisX axisZ) -- create local Y-axis
theTM = matrix3 axisX axisY axisZ theCenter -- create Transform Matrix
b.transform = theTM -- move the copied objec to the Nth face of Original obj.
----------------------
non-working code
FaceSel = c -- input a letter from "a" to "l" to change position of new object
case FaceSel of
(
a : n=1
b : n=2
c : n=3
d : n=4
e : n=5
f : n=6
g : n=7
h : n=8
i : n=9
j : n=10
k : n=11
l : n=12
)
t = $Pyramid01 -- original object
s = copy t -- keep one
n -- index of face in Box01 range [1 ~ 12]
firstID = 2 -- there are two cases 2 or 4 to speciy the X local axis using the 2nd or 4th vertex.
theCenter = polyOp.getFaceCenter t n --Nth face's center
axisZ = polyOp.getFaceNormal t n --the normal direction of Nth face
theVert = (t.GetFaceVertex n firstID) -- get the second vertexID of Nth face
theVertPos=polyOp.GetVert t theVert -- get the world position of the vertex
axisX =normalize [(theVertPos.x - theCenter.x), (theVertPos.y - theCenter.y), (theVertPos.z-theCenter.z)] -- create local X-axis
axisY = normalize (cross axisX axisZ) -- create local Y-axis
theTM = matrix3 axisX axisY axisZ theCenter -- create Transform Matrix
s.transform = theTM -- move the copied objec to the Nth face of Original obj.
I’m having an issue in the following script.
In an earlier version of this script, an pre-drawn object (“Pyramid01” ) is copied and aligned to one of its 12 faces. The face is referenced using a variable “n” and a number between 1 and 12 (changing the n variable value from 1-12 changes the location of the new object). This worked fine.
However, I wanted to designate the face using letters instead of numbers, so I added the “case of” statement. When the script runs, some letters (like “d” for instance) don’t return the right value and the newly placed shape ends up in the wrong place. Other times, the letters don’t seem to affect the outcome at all and the shape keeps getting placed at the same location (is this a scope issue?). I probably have incorrect syntax for the “case of” expression too, but I’ve looked at the help and online and this is the best I’ve come up with (and like I said, it has worked intermittently in the past).
I’m including both the script that works with numbers, the script I’m having issues with and the file that goes with either script, if anyone has the time/inclination to help. I’m still a noob when it comes to programming, so any suggestions are welcome.
TIA!
Carlo
---------------------------
original working code
-- This is a sample code using "Rhombic Dodecahedron super clean 05 10 2008.max" file.
-- The file has one object of Editable-Poly whose pivot is located (0,0,0) and named as "Pyramid01"
-- This is to move a copied object to the position of other face(n).
a = $Pyramid01 -- original object
b = copy a -- keep one
n = 2 -- index of face in Box01 range [1 ~ 12] -- Change this value to change position of object
firstID = 2 -- there are two cases 2 or 4 to speciy the X local axis using the 2nd or 4th vertex.
theCenter = polyOp.getFaceCenter a n --Nth face's center
axisZ = polyOp.getFaceNormal a n --the normal direction of Nth face
theVert = (a.GetFaceVertex n firstID) -- get the second vertexID of Nth face
theVertPos=polyOp.GetVert a theVert -- get the world position of the vertex
axisX =normalize [(theVertPos.x - theCenter.x), (theVertPos.y - theCenter.y), (theVertPos.z-theCenter.z)] -- create local X-axis
axisY = normalize (cross axisX axisZ) -- create local Y-axis
theTM = matrix3 axisX axisY axisZ theCenter -- create Transform Matrix
b.transform = theTM -- move the copied objec to the Nth face of Original obj.
----------------------
non-working code
FaceSel = c -- input a letter from "a" to "l" to change position of new object
case FaceSel of
(
a : n=1
b : n=2
c : n=3
d : n=4
e : n=5
f : n=6
g : n=7
h : n=8
i : n=9
j : n=10
k : n=11
l : n=12
)
t = $Pyramid01 -- original object
s = copy t -- keep one
n -- index of face in Box01 range [1 ~ 12]
firstID = 2 -- there are two cases 2 or 4 to speciy the X local axis using the 2nd or 4th vertex.
theCenter = polyOp.getFaceCenter t n --Nth face's center
axisZ = polyOp.getFaceNormal t n --the normal direction of Nth face
theVert = (t.GetFaceVertex n firstID) -- get the second vertexID of Nth face
theVertPos=polyOp.GetVert t theVert -- get the world position of the vertex
axisX =normalize [(theVertPos.x - theCenter.x), (theVertPos.y - theCenter.y), (theVertPos.z-theCenter.z)] -- create local X-axis
axisY = normalize (cross axisX axisZ) -- create local Y-axis
theTM = matrix3 axisX axisY axisZ theCenter -- create Transform Matrix
s.transform = theTM -- move the copied objec to the Nth face of Original obj.
