|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| Maxscript 2010 bug - reading transform values
|
|
|
Hey there…
Been working with 3ds max 2010, and Im finding a serious problem when trying to read transform values.
When I execute a script line from the script editor like.
sphere.pos = box.pos
It places the sphere at [0,0,0] because it reads the box’s position to be [0,0,0].
While executing the same line from maxscript listener, gives the expected result of having the sphere’s position to be the same as the box’s position.
Is there a fix for this bug?? Or am I the only one with this problem??
|
|
|
|
$Sphere.pos = $Box.pos
Assuming you have an object named “Sphere” and an object named “Box”. Works perfectly here from the listener, from the editor and from a saved script executed from MAXScript | Run Script. No bug that I can see.
Note. Always put CODE tags around any code you post here - the forum software messes with it something rotten, making it impossible to copy/paste code from the post.
Max 4.2 through 2012 (SP2+SAP).
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
|
Ok, I got the same result as you. dont you just hate it, when its works when it shouldn’t:-) So the problem occured when I tried to execute this script. To begin with there is a spline-line in the scene.
--Knots on spline =< SpineRez
fn snakeRig CharName = (
global ChName = CharName+"_"
--gets spline
snakeSpline = getnodebyname CharName
--all vertices to smooth
for i in 1 to (numKnots snakeSpline 1) do
(
setKnotType snakeSpline 1 i #smooth
)
--adds splineIK
addmodifier snakeSpline (Spline_IK_Control linktypes:2)
snakeSpline.modifiers[1].createHelper (numKnots snakeSpline 1)
splinePoints = for i in 1 to (numKnots snakeSpline 1) collect (getnodebyname ("Point0"+i as string))
for i in 1 to splinePoints.count do
(
splinePoints[i].name = (ChName+"Point_"+(i as string))
)
--creates spaceWarp conform
ConfSpaceWarp = ConformSpaceWarp Icon_Size:20
--creates conform planes
Planes = #()
for i in 1 to (numKnots snakeSpline 1) do
(
pla = plane lengthsegs:2 widthsegs:2 name:(ChName+"Plane_"+(i as string))
pla.pos = splinePoints[i].pos
append Planes pla
bindSpaceWarp pla ConfSpaceWarp
)
)
snakeRig "Snake"
When I execute this script planes’ positon do not go to the positon of the splinePoints.
This problem is similar to a bunch of other scripts that I have written in 3ds max 2009 and works fine there.
|
|
|
|
It’s something to do with the spacewarp. If you comment out the “bindSpaceWarp” line then it works as expected and the planes are created centered on the dummy helpers.
Quick point. The “splinepoints = for i in ...” line won’t work if you have more than 9 knots because the tenth one will be called “Point10” (not “Point010") and so your “getnodebyname “Point0"+" will fail.
Max 4.2 through 2012 (SP2+SAP).
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
Steve_Curley 12 November 2009 10:36 AM
It’s something to do with the spacewarp. If you comment out the “bindSpaceWarp” line then it works as expected and the planes are created centered on the dummy helpers.
Quick point. The “splinepoints = for i in ...” line won’t work if you have more than 9 knots because the tenth one will be called “Point10” (not “Point010") and so your “getnodebyname “Point0"+" will fail.
And this is where I get a different result from you. I commented out the “bindSpaceWarp”, and the planes still do not move from [0,0,0]. On this PC I’m working with 3ds max 2010 SP1, do you have any further updates or something that might cause this difference??
And, yeah, I know about the collecting of the “splinePoints”, just a bodgejob to get on with the script:-)
|
|
|
|
Possibly. There’s a Hotfix 2009_09_22 which I have downloaded but I can’t remember if if I installed it or not. XP isn’t even showing me SP1 (in Add/Remove programs) so I can’t tell for sure. I definitely have SP1 installed.
Oh.. this is odd. I just tried the script in the 32bit version and it went wrong. Ok, so reloaded the 64bit version - and now IT goes wrong as well. Something is very amiss here which I’ll have to sort out, because it is undoubtedly related to your problem. It absolutely worked - repeatedly - earlier.
Max 4.2 through 2012 (SP2+SAP).
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
|
hmmm… interesting about the 32-bit and 64-bit difference. I have been switching between the two, so the problem might originate from this.
|
|
|
|
I only switched to see if it was that causing a difference - it doesn’t seem to be because they both now fail.
The wierd thing is that if you check the position in the listener then it works, but not in a script.
Fortunately there’s a work-around. Because the helpers are created at each knot, you can use
pla = plane blah blah pos:(getKnotPoint snakeSpline 1 i)
instead. Should be the same location and it appears to work.
Btw, you don’t need so many separate loops - can do it all in one.
( --Knots on spline =< SpineRez
fn snakeRig CharName =
(
global ChName = CharName+"_"
--gets spline
snakeSpline = getnodebyname CharName
--knot count will be needed again
kCount = (numKnots snakeSpline 1)
--adds splineIK
IK_Mod = Spline_IK_Control linktypes:2
addmodifier snakeSpline IK_Mod
--create the helpers
IK_Mod.createHelper kCount
--creates spaceWarp conform
ConfSpaceWarp = ConformSpaceWarp Icon_Size:20
Planes = #()
for i = 1 to kCount do
(
--set vertex to smooth
setKnotType snakeSpline 1 i #smooth
--change the helper name
tmpStr = IK_Mod.helper_List[i].name
tmpStr = (substituteString tmpStr "Point" (ChName+"Point_"))
IK_Mod.helper_List[i].name = tmpStr
--create the plane name
tmpStr = (substituteString tmpStr "Point" "Plane")
--create the plane
pla = plane lengthsegs:2 widthsegs:2 name:tmpStr pos:(getKnotPoint snakeSpline 1 i)
--save the plane
append Planes pla
--bind it to the spacewarp
bindSpaceWarp pla ConfSpaceWarp
) -- end for loop
)-- end fn definition
snakeRig "Snake"
) -- end script
Max 4.2 through 2012 (SP2+SAP).
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
|
Wow, yeah it works. Though its still very annoying that the whole transform-values thing isn’t working for me. Kinda important since I use it alot.
And very nice clean structure of code you did there… should organize my scripts better.
|
|
|
|
|
It’s very strange - if you run the script without making the planes - just up to where it creates the helpers, and enter the necessary code in the listener, then it works (as per your original code), but in a script it doesn’t. I tried printing the pos values in the loop, but they were always 0. Really strange.
As for the code, there are times when it makes sense to use separate loops, and times when it makes sense to keep all the loop-dependant stuff together. Not a matter of right and wrong, just a slightly different approach which seemed logical under the circumstances.
Author: Steve_Curley
|
| Replied: 12 November 2009 06:31 AM
|
|
|
|
|
now I get into trouble with the script again, since Im trying to build bones.
--freeze transform as function fn FreezeTransform item =
(
local CurObj = item
if classof CurObj.rotation.controller != Rotation_Layer do
(
-- freeze rotation
CurObj.rotation.controller = Euler_Xyz()
CurObj.rotation.controller = Rotation_list()
CurObj.rotation.controller.available.controller = Euler_xyz()
/* "Localization on" */
CurObj.rotation.controller.setname 1 "Frozen Rotation"
CurObj.rotation.controller.setname 2 "Zero Euler XYZ"
/* "Localization off" */
CurObj.rotation.controller.SetActive 2
)
if classof CurObj.position.controller != Position_Layer do
(
-- freeze position
CurObj.position.controller = Bezier_Position()
CurObj.position.controller = position_list()
CurObj.position.controller.available.controller = Position_XYZ()
/* "Localization on" */
CurObj.position.controller.setname 1 "Frozen Position"
CurObj.position.controller.setname 2 "Zero Pos XYZ"
/* "Localization off" */
CurObj.position.controller.SetActive 2
-- position to zero
CurObj.Position.controller[2].x_Position = 0
CurObj.Position.controller[2].y_Position = 0
CurObj.Position.controller[2].z_Position = 0
)
)
( --Knots on spline =< SpineRez
fn snakeRig CharName =
(
global ChName = CharName+"_"
--gets spline
snakeSpline = getnodebyname CharName
--knot count will be needed again
kCount = (numKnots snakeSpline 1)
--adds splineIK
IK_Mod = Spline_IK_Control linktypes:2
addmodifier snakeSpline IK_Mod
--create the helpers
IK_Mod.createHelper kCount
--creates spaceWarp conform
ConfSpaceWarp = ConformSpaceWarp Icon_Size:20
Planes = #()
for i = 1 to kCount do
(
--set vertex to smooth
setKnotType snakeSpline 1 i #smooth
--change the helper name
tmpStr = IK_Mod.helper_List[i].name
tmpStr = (substituteString tmpStr "Point" (ChName+"Point_"))
IK_Mod.helper_List[i].name = tmpStr
--create the plane name
tmpStr = (substituteString tmpStr "Point" "Plane")
--create the plane
pla = plane lengthsegs:2 widthsegs:2 name:tmpStr pos:(getKnotPoint snakeSpline 1 i)
--save the plane
append Planes pla
--bind it to the spacewarp
bindSpaceWarp pla ConfSpaceWarp
--create the pointAtt name
tmpStr = (substituteString tmpStr "Plane" "pointAtt")
--create the attachment point
pointAtt = point cross:true box:false pos:(getKnotPoint snakeSpline 1 i) name:tmpStr
FreezeTransform pointAtt
--adds attachment controller to the point
actrl = Attachment node:Planes[i]
pointAtt.position.controller.Available.controller = actrl
addNewKey actrl 0f
theAKey = AttachCtrl.getKey actrl 1
theAKey.coord = [0,0]
--parents spline helpers to pointatt
IK_Mod.helper_List[i].parent = pointAtt
) -- end for loop
--creates bones
for i in 1 to kCount-1 do
(
sBone = BoneSys.createBone IK_Mod.helper_List[i].pos IK_Mod.helper_List[i+1].pos [0,0,1]
sBoneNull = BoneSys.createBone [0,0,0] [0,0,0] [0,0,1]
sBoneNull.transform = sBone.transform
sBoneNull.pos = IK_Mod.helper_List[i+1].pos
)--end for loop
)-- end fn definition
snakeRig "Snake"
) -- end script
the bones are stuck at [0,0,0], and I need them be build along the splinePoints
|
|
|
|
|
I’ve not tried this, but try substituting the getKnotPoint for the IK_Mod.helper_list statements - as we did earlier in the script.
Author: Steve_Curley
|
| Replied: 12 November 2009 08:05 AM
|
|
|
|
|
Although it might not be what’s causing the issue, I’ve had trouble in the past writing the following:
for i in 1 to kCount-1 do ...
If you intend to go through a count try this:
for i = 1 to kCount-1 do ...
I typically use the former format if I’m iterating items of an array/collection:
for obj in objArray do ...
---
3DSMax 2009 SP1
|
|
|
|
|
I still think it’s the IK_Mod.helper_list which isn’t working.
Either way, looking at the help for the “for” loop, “in” and “=” appear to be interchangable, though I must admit that I always use “=” for numeric loops (like most languages do) and “in” only for collections. The help actually has an example of a numeric loop using “in” so that shouldn’t be the problem (though you never can tell ;) ).
Author: Steve_Curley
|
| Replied: 08 December 2009 09:36 PM
|
|
|
|
|
| Settings
| Choose Theme color:
|
|
|
|
|
|
|