[SOLVED] how do i check if a object has a Look at constraint, or Link constraint?

[SOLVED] how do i check if a object has a Look at constraint, or Link constraint?

stigatle
Enthusiast Enthusiast
523 Views
3 Replies
Message 1 of 4

[SOLVED] how do i check if a object has a Look at constraint, or Link constraint?

stigatle
Enthusiast
Enthusiast
i'm stuck at a little line of code..
how do i check if a object has a Look at constraint, or Link constraint?
i cannot seem to figure this one out..

Tried everything i can think of..
0 Likes
524 Views
3 Replies
Replies (3)
Message 2 of 4

cthomas
Explorer
Explorer
Here is a section of code I used to have tree plates rotate with a camera to always look at the camera.
Hope it helps.

fn PtHelper CameraObj SourceObj i =
(
PtName = "LookAtPT-" + SourceObj.name
PtPos =

PTi = PointHelperObj name:PtName pos:PtPos
-- lac = AddListController SourceObj "Rotation" lookat_constraint
global ListCont = AddListController SourceObj "Rotation" Rotation_List
if classof ListCont.object != LookAt_Constraint then
(
global lac = AddConstraint SourceObj "Rotation" LookAt_Constraint true
)
else
(
global lac = ListCont.object
)

lac.appendTarget PTi 50
SetActiveController ListCont lac
lac.target_axis=1
lac.target_axisFlip=true
lac.viewline_length_abs=false
lac.upnode_axis=2
lac.StoUp_axis=2
)
0 Likes
Message 3 of 4

stigatle
Enthusiast
Enthusiast
After a lot of thinking, i found a sollution to this:


if ($.rotation.controller as string == "Controller:LookAt_Constraint") then
(
--do stuff here
)


For link constraint:


if ($.Transform.controller as string == "Controller:Link_Constraint") then
(
--do stuff here
)
0 Likes
Message 4 of 4

stigatle
Enthusiast
Enthusiast
Run from "utilities\maxscript" menu..

Here's a working code.


utility remlookat "Remove lookat" width:160 height:80
(
button btn1 "Remove" pos: width:112 height:16
GroupBox grp2 "Remove constraints" pos: width:144 height:56

on btn1 pressed do
(
LookArray = #()
if selection.count == 0 then (MessageBox "Please select at least one object" title:"ERROR")
for o in selection do
if (superclassof o == geometryclass) do
(
if (o.rotation.controller as string == "Controller:LookAt_Constraint") then
(
append LookArray o
)
)
c = 1
while c <= LookArray.count do
(
snapshot LookArray
delete LookArray
c += 1
)
)
)





0 Likes