PDA

View Full Version : How can I improve this script?


em3
06-13-2011, 09:27 PM
I have written a script that copies one object in a scene and renames it..which is great.

The problem is I think it's bloated. I had to add the count check because it loops endlessly if I don't. How can this be optimized?


(
a = objects.count
i=1
for o in objects do
(
if i <= a do
(
select o
myName = o.name
b = copy o
b.name="Copy_" + myName
i+=1
)
)
)


Thanks!

denisT
06-13-2011, 09:50 PM
I have written a script that copies one object in a scene and renames it..which is great.

The problem is I think it's bloated. I had to add the count check because it loops endlessly if I don't. How can this be optimized?


(
a = objects.count
i=1
for o in objects do
(
if i <= a do
(
select o
myName = o.name
b = copy o
b.name="Copy_" + myName
i+=1
)
)
)


Thanks!


copies = for node in (objects as array) collect (copy node name:("Copy_" + node.name))


it does do what you want and collects all new copies...

other way to do it is to use clone method... see mxs help -> Collapse and Clone Nodes

em3
06-13-2011, 09:55 PM
damn...you are the master, denisT. Thanks man.

Thanks for tip on Collapse as well. It looks like there is some awesome stuff in there!

Cheers

CGTalk Moderation
06-13-2011, 09:55 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.