[Closed] Check Transform before Deleting
I have a script where I create a dummy, and then make it’s transform match a selected object’s transform. The selected object’s transform is then matched to the world origin dummy for editing. Later, the selected object’s transform is matched back to the original location dummy’s transform so that the selected object is put back in it’s original place. Then I delete the original location dummy. This all works fine.
But before I delete the original location dummy… I would like to check and make sure the selected object’s transform matches that of the original location dummy’s transform. I have written this… but it doesn’t work for me. What am I doing wrong?
if $.transform = locDUM.transform then delete locDUM
Thanks!
I believe you would need to use a comparison expression, such as ‘==’ to check against, a single ‘=’ is used as an assignment operator.
John,
Thanks for the ideas. I tried adding the ‘==’ but it didn’t delete the dummy. Not sure what the right syntax is.
Thanks again.
The problem is def. the == like johnny mentioned. If your dummy isn’t getting deleted then it’s probably not the same transform as the other object… try doing a quick print on each one to check…?
Just double checking locDum is a variable, right? not the name of an object, in which case you’d have to use $locDum
This actually goes deeper than it seems. Matrix3 values are complex values containing multiple Point3 components and to a certain extent are more similar to Arrays than Numbers.
You cannot correctly perform an equality test of a matrix against another matrix.
Try this:
a=matrix3 1 --create an identity matrix
(matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])
b = copy a --copy the value, now b has the same value as a
(matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])
a == b --compare the two...
false
--SURPRISE! YOU GET FALSE!
--This is because the test checks to see whether the two variables point
--at the same memory address, not whether the values are the same.
--In a way, a == b asks 'are these instances of the same value'?
--Even if you create another identical value, you get the same
c = matrix3 1
(matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])
a == c
false
--You only get true if the two point at the same memory, kind of instancing them:
d = a
(matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])
a == d
true
--But, if you compare the two values as strings, you can get them to return true:
a as string == b as string
true
a as string == c as string
true
--Alternatively, you can compare all their components, but that's a bit long...
a.row1 == b.row1 AND a.row2 == b.row2 AND a.row3 == b.row3 AND a.row4 == b.row4
true
hmm, I have no idea why comparing transforms doesn’t work but you can always just test against position and rotation and well scale to if you like.
Something like:
a = $Box01
b = $Box02
if a.pos == b.pos and a.rotation == b.rotation and a.scale == b.scale then delete b
EDIT: In my befuddlement two people posted! And yes what I posted is quite long, I couldn't figure out why the transforms weren't working (other than a != b, for obvious reasons), thanks for the explanation :) and convert and compare strings... sneaky ;)
LOL, A glitch in the Matrix
I am guessing that everything else checks against the actual values?
I was going to suggest this as well (did not have max open to actually test if matrix == matrix would work.
Thanks for the lesson, bobo!
LOL.
As far as I can tell, it is an undocumented FEATURE of the Matrix
At least it was until 5 minutes ago…
It will be documented next time ’round.
Thanks to everyone for the great info!!
Bobo (and everyone else… including me) knows I don’t have a clue when it comes to Maxscript! But amazingly, after all these years, I am hammering out some crude stone tools to automate my work a bit (and really enjoying my crude success!).
On my current project, I have a cityscape where the modelling sucks. Many of the foreground buildings (which look like the WackyShack) need to be trued up (squared up). There doesn’t seem to be any automated maxscript tool which will take a WackyShack building model, let the user select a corner vert (let this vert be called true… left alone) and true up the neighboring verts to this vert, etc. So the building models must be edited by hand (one at a time) using normal mesh/poly tools, etc.
I created a simple script that will create 2 dummies at the world origin, match the transform of one of the dummies to the local position of the building object and then match the transform of the building object to the world origin dummy. I edit the model and then later use another script to match the building object back to it’s original location. To my amazement… it works great!!
But before I finally deleted the local position dummy, I wanted to be sure that the building object had indeed been moved back to it’s original location. That’s why I wanted to do this test.
I will try your suggestions.
Thanks again to all!
two matrices are equal if the result of multiplication of first one and inverse of second is the identity matrix
fn matixEquals m1 m2 = isIdentity (m1*(inverse m2))