PDA

View Full Version : Clone item, replace, reset, parent...



raw-m
01-25-2014, 06:35 AM
I can't be the only one who has done this so hoping someone can point me to a script that already exists (done a search, have come close but not quite...).

I've been animating a few objects now and it's got to a point that I realise I should really have created a null first, parented my object to it and animated the null (mainly because of rotation issues).

So anyone found a script that:
Clones my object,
Replaces the clone with a null
Zeros out the moves/rots/scales etc. of the original item
Parents the original item to the null

Ideally, all in one click? Perhaps the ability to rename the null, but not crucial (I'm not that lazy!).

jeric_synergy
01-25-2014, 09:26 AM
:looks left: looks right: Well, if you don't find one, I'd say this is an excellent starter script. No math, simple goal, no interactivity. A good chance to get one's feet wet with Python.

If you insist in doing it in LScript, that [email protected] macro recorder we have might be a good start.

Hey, do we have a Python equivalent (a recorder that is)?

dee
01-25-2014, 09:33 AM
Here's a small script that does this with all selected objects. It adds a "null_" before the object name as Null name. You can change that in the nullName variable. This is my first lscript. :)


@warnings

generic
{
myscene=Scene();
myobjs=Scene().getSelect();

i=1;
while(i<=myobjs.size())
{
obj=myobjs[i].id;
nullName = "null_"+myobjs[i].name;
SelectItem(obj);
Clone(1);
ReplaceWithNull(nullName);
curNull = Scene().firstSelect();
SelectItem(obj);
Position(0, 0, 0);
Rotation(0, 0, 0);
Scale(1, 1, 1);
ParentItem(curNull.name);
i++;
}
}

ernpchan
01-25-2014, 09:38 AM
Good one dee.

I made a script that does the opposite. It adds a child null to the selected.

jeric_synergy
01-25-2014, 09:43 AM
ernpchan, does it work with multiple selected items?

ernpchan
01-25-2014, 09:53 AM
ernpchan, does it work with multiple selected items?
Yeah.

Gives you the option to name the child null outright or add a pre/post suffix based on the selected object name.

jeric_synergy
01-25-2014, 09:54 AM
Cool. --On a side note, you say "objects" and I say "items"-- will it work on Cameras, Lights, and Bones?

ernpchan
01-25-2014, 10:00 AM
Cool. --On a side note, you say "objects" and I say "items"-- will it work on Cameras, Lights, and Bones?

Yes, would be silly not to. :D

jeric_synergy
01-25-2014, 10:14 AM
Indeed it would, but IIRC correctly theres a few native functions that should work on any item, but don't. Don't recall which ones though.

raw-m
01-25-2014, 10:29 AM
Here's a small script that does this with all selected objects. It adds a "null_" before the object name as Null name. You can change that in the nullName variable. This is my first lscript. :)


@warnings

generic
{
myscene=Scene();
myobjs=Scene().getSelect();

i=1;
while(i<=myobjs.size())
{
obj=myobjs[i].id;
nullName = "null_"+myobjs[i].name;
SelectItem(obj);
Clone(1);
ReplaceWithNull(nullName);
curNull = Scene().firstSelect();
SelectItem(obj);
Position(0, 0, 0);
Rotation(0, 0, 0);
Scale(1, 1, 1);
ParentItem(curNull.name);
i++;
}
}

Great start, very much appreciated! Just need to reset and kill all the keys on the original object when it's parented to the null. Can you do it? :D

dee
01-25-2014, 11:13 AM
Great start, very much appreciated! Just need to reset and kill all the keys on the original object when it's parented to the null. Can you do it? :D

No, but after running the script you could select all the objects and run Blochi's Keyframe Killer or any other keyframe deleting plugin.
http://www.blochi.com/gfx/lscripts_en.html

raw-m
01-25-2014, 11:37 AM
No problem, thanks for getting the ball rolling.

jeric_synergy
01-25-2014, 11:43 AM
Scripters: is there a way to CHAIN lscripts so that we could have a tinker-toy approach to making new scripts?

raw-m, check LSCRIPT COMMANDER to see if you can cobble those two scripts together to do what you want.

dee
01-26-2014, 09:59 AM
Here's a new version. It deletes the keyframes of the original now and has a requester where you can fill in a prefix. If Keep Object Name is unchecked the prefix will be the name.

Rename .txt to .ls and enjoy!

raw-m
01-26-2014, 10:11 AM
Cheers dee, you're a genius! Will test it when I get home.

raw-m
02-20-2014, 03:36 AM
Dee, just thought I'd thank you again, it turns out this script is fantastically useful for getting stuff into AE! Just batch selected 60 files, ran the script and sent the null data through in a breeze :D.

There is one little feature request (I'm not sure it's even possible), is there any way to automatically select the newly created nulls after the script as run, rather than the source objects? :thumbsup:

dee
02-20-2014, 11:32 AM
Thanks, I'm glad you like it. :) Here's version 2 which selects the created nulls.

Rename to .ls.

http://forums.newtek.com/attachment.php?attachmentid=120280&d=1392921057

raw-m
02-20-2014, 11:36 AM
Genius :thumbsup::thumbsup::thumbsup:

raw-m
05-11-2015, 08:08 AM
Hi dee. Sorry to bring this back from the dead!

This is still incredibly useful for getting object data in to AE. Just one little feature request, pretty please :D

The reset of the position, rotation and scale of original and deleting of keyframes only happens at frame 0 - there's still the original keys later in the timeline. Anyway to kill ALL the keys on the position, rotation and scale in the timeline before resetting and parenting to the null?

ernpchan
05-11-2015, 11:41 AM
Definitely possible via scripting. In the meantime you could use one of the various keyframe scripts on lwplugindb.com to clear out the keyframes.

daforum
05-11-2015, 12:34 PM
Dee, just thought I'd thank you again, it turns out this script is fantastically useful for getting stuff into AE! Just batch selected 60 files, ran the script and sent the null data through in a breeze :D.


Mark, can you show this in action?

raw-m
05-14-2015, 04:23 AM
Sorry missed these.

Thanks ernpchan - it's simple enough to do in the GE or with Motify, but I'm lazy!

daforum - great idea, I'll try and knock something up later today/this week :D

raw-m
05-14-2015, 05:44 AM
https://www.youtube.com/watch?v=BZtzgoFemlE


https://www.youtube.com/watch?v=BZtzgoFemlE

daforum
05-20-2015, 05:34 AM
Cool! Thanks Mark for doing this ( for everyone!! )
Good use of a great script.
:)