Digital humans the art of the digital double
Ever wanted to know how digital doubles are created in the movie industry? This course will give you an insight into how it's done.
# 1 10-08-2013 , 05:24 AM
Registered User
Join Date: Aug 2013
Posts: 3

MEL for delete by history of an object.

hey there.
I wanted to know if it is possible to write a MEL or Python script, to delete any selected objects history(and not the script editors history), and freeze tranformation.

This will help me when i make GUI controllers and i do not have to select each object and go into the menues and do a lengthy set of procedure each and every time.

If anyone could help, please do.

Aaronuser added image

# 2 10-08-2013 , 10:09 AM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
If you turn on History>Echo All Commands in the Script Editor you'll see the MEL commands for those actions whenever you run them.


Code:
DeleteHistory;
CenterPivot;
If you want to do this for the objects you have selected, it's easy.
Code:
//Store list of the selected objects in a string array
string $selection[] = `ls -sl`;


//For every item in that list...
for($obj in $selection){

//Delete history and center pivot
DeleteHistory;
CenterPivot;


}


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
# 3 13-08-2013 , 12:11 PM
Registered User
Join Date: Aug 2013
Posts: 3

Thanks!

Thank you so much!
It worked!

Thanks,
Aaron.user added image

# 4 15-10-2014 , 10:38 PM
MrYeti's Avatar
Lifetime Member
Join Date: Feb 2013
Location: Down Under
Posts: 245
Bumping an old thread here, I'm wondering if there's a way to delete an objects history in Python.


Cheers, the Yeti.
# 5 16-10-2014 , 01:32 AM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
Yep! Using the "delete" command. This code deletes the construction history on all selected objects.

Code:
import maya.cmds as mc

selection = mc.ls(sl = 1)
for obj in selection:
	mc.delete(obj , ch = 1)
I just realized in the previous MEL I posted that I added center pivot instead of freeze transformations lol. I just don't know anymore, smh.


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
# 6 16-10-2014 , 02:18 AM
MrYeti's Avatar
Lifetime Member
Join Date: Feb 2013
Location: Down Under
Posts: 245
Thanks Gen, I found a way to do it using the command (constructionHistory = False) at the creation of the object but I don't know if this is a good way to do it.


Cheers, the Yeti.
# 7 16-10-2014 , 12:58 PM
EduSciVis-er
Join Date: Dec 2005
Location: Toronto
Posts: 3,374
You probably want to keep construction history on, as it will allow you to modify various operations after the fact. I would then delete construction history at certain points in the process once you're sure you don't want to dig into the history.

# 8 16-10-2014 , 08:50 PM
MrYeti's Avatar
Lifetime Member
Join Date: Feb 2013
Location: Down Under
Posts: 245
Thanks for that tip Stwert, it was okay for what I was doing (creating a control for a rig) but I thought it might not be best practice to do it for other things.


Cheers, the Yeti.
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads