[Closed] Scripting with Lookat constraint
I have a series of objects that I would like to apply the ‘lookat’ constraint. Following the listener, I’ve gotten to “select $
macros.run “Constraints” “LookAt””
in which at the end of the command I have to choose the target. Now I have about six hundred of these to apply to and when I execute the comman for multiple objects at the same time, it would only execute on one of them and end. I’ve tried putting #($), $(all of the objects needed to be worked on) and it doesn’t work. Is there a way I could select a whole batch and apply the look at command through scripting?
the script you provided me current applies to one object… is there a way I can have it so that it would work with whole group of objects together? I’ve tried #($) at the end and it didn’t work…
hm.
I figured out that the .lookAt property is not quite the same as a lookAt-Constraint.
The help told me do this[1]:
Foo = Selection as array
AddListController Foo[1] "Rotation" "Rotation_List"
lst=Foo[1].rotation.controller
showInterfaces lst
lookatCnstr=LookAt_Constraint()
lookatCnstr.appendTarget $Box02 100
lst.available.controller=lookatCnstr
lst.delete 1
To test it, do this:
create two boxes
select Box01
run the script
to apply this to many objects you have to iterate through an array …
Edited: What is #($)? looks perlish … $_ …
Georg
[1] [color=white]LookAt_Constraint : RotationController
[/color][color=white]List Controllers
[/color][color=white]Position_Constraint : PositionController[/color]
Hmm, it works great for single object and works flawlessly, however when I select multiple objects and try to apply it, it only works on one of the selected objects… is there a way to make it so that if i selected several objects it would work on all of them?
as I said:
you will have to iterate through one or more arrays.
have a look at [color=white]Array Values.
And remember: “for i in foo” is your friend.
Georg
[b][/b][/color]
all righty, I’ll give this a try when I get home… arrg. Sorry I just started messing around with scripts today… <: (
to iterate over your selection try one of the following:
for i=1 to selection.count do (
print selection[i].name
)
to access one of your objects in the first loop you have to use selection[i], selection is a global array with the selected objects and “i” will be the current iteration of the loop, this method is useful when you need a number insider your loop, for example to assign a name with a number to the selected objects use “selection[i].name = (“blabla”+i)”
for i in selection do (
print i.name
)
does the same as above…
here “i” will actually be a reference to one of your objects… so if you have 3 sphere’s selected, the first time the loop is run you can use i.size to change the size of the first sphere
Just a note that is it generally safer to snapshot the selection first.
Some operations on the current object might change the scene selection and then the script would fail. So it is a better practice to say
theSel = selection as array
for i in theSel do...