Notifications
Clear all

[Closed] Help with script please

I am new to max script and I want to select a heirarchy of objects that have constraints on them…I have had some luck but have a problem that I can’t quite resolve. Here is my script.

fn selectAllChildren =
(
for obj in selection do
(
if obj.children != undefined do
(
selectmore obj.children
)
)
)
selectAllChildren()
MyBones = selection
fn DelConstraint =
(
for each in selection do
(
each.pos.controller.delete 2
each.rotation.controller.delete 2
)
)

DelConstraint()

So if all the objects have *_list() controlllers it works great but if one of the objects in the heirarchy does not have constraints on it then the script throws and error.

I appended the script with an if statement like this

fn DelConstraint =
(
for each in selection do
(
if each.position.controller != Position_XYZ do
(
each.pos.controller.delete 2
each.rotation.controller.delete 2
)
)
)
DelConstraint()

But this does nothering to solve the problem. I am looking for a way to either cull any objects from my selection that do not have position or rotation constraints or those that do not have list controllers. any help would be appreciated.

Thanks

3 Replies

I don’t quite understand the problem but I can help optimize your code
also put code in [ code ] brackets for easier reading and the try()catch() should fix any errors and will spit out print code in the listener to show you what objects are causing errors, really you should figure out why they are causing errors and if/then check for them instead


 fn selectAllChildren objs = ( 
 	selectmore (for o in objs where o.children != undefined collect o)
 )
 
 selectAllChildren (selection as array)
 
 MyBones = getCurrentSelection() -- copies the current selection into an array
 
 fn DelConstraint objs = (
 	if objs.count != 0 then (
 		for each in obj do (
 			try ( 
 				each.pos.controller.delete 2
 				each.rotation.controller.delete 2
 			) catch ( format " Problem with obj: % " each.name )
 		)
 	)
 )
 
 DelConstraint (selection as array)
 
 -- I converted all functions to have a simple array variable so you can run the functions across different selections instead of just the current one
 

Hey MoonDoggle…
Thanks so much…I think the way my code was constructed it was looking at the Deleteconstraint function as an absolute and when the script found the position_xyz instead of the list controller it threw the exception.

Also I am a newb and didn’t know about certain syntax like “try” and “collect”. Just looking at your syntax I’ve learned alot and it works great thanks.

Always glad to help! Keep posting.