Delete Scale Tracks Only? (Python)

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 06 June 2013   #1
Delete Scale Tracks Only? (Python)

I'm trying to write a script to help with clean up on some files, I can delete ALL tracks on selected objects, but I'm trying to make it conditional so that say it will delete only Scale tracks. I can get the name of the track but when I use that in a condition to delete the scale tracks it's not working.
Might be a simple error as my Python is a little rusty. Any ideas appreciated.


 import c4d
 
 def main():
 	cycleObjects(doc.GetActiveObjects(c4d.GETACTIVEOBJ  ECTFLAGS_0))
 	c4d.EventAdd()
 
 def cycleObjects(objects):
 	for obj in objects:
 		cleanTracks(obj)	
 		if (obj.GetChildren()!= None):
 			cycleObjects(obj.GetChildren())
 
 
 def cleanTracks(object):
 	for track in object.GetCTracks():
 		trackName=track.GetName()
 		print trackName # this seems to work...
 		if (trackName=="Scale.Y"):## this part not working yet!
 			track.Remove()
    
 if __name__=='__main__':
 	main()
 


As usual the forum here is eating the code but the part I'm having trouble is the last bit, which is commented..

Cheers,
Brian
 
Old 06 June 2013   #2
Hi Brian!

A CTrack instance (which represents animation tracks in Cinema 4D) has a method called GetDescriptionID(). You can identify a track using the return value of this method.

descid = track.GetDescriptionID()
if descid[0].id == c4d.ID_BASEOBJECT_REL_SCALE:
    track.Remove()


The description ID of a Scale-Track has two components: The base ID (which is ID_BASEOBJECT_REL_SCALE) and the vector component (VECTOR_X, VECTOR_Y, VECTOR_Z). You can be more precise by checking these components as well, or, if you're aiming for a very specific track, compare description IDs directly.

scale_y = c4d.DescID(
    c4d.DescLevel(c4d.ID_BASEOBJECT_REL_SCALE),
    c4d.DescLevel(c4d.VECTOR_Y))

descid = track.GetDescriptionID()
if descid == scale_y:
    track.Remove()


-Niklas

Edit: Fixed typo in first code snippet.
__________________
Cinema 4D Plugin Developer
niklasrosenstein.com/ | Freebies | Plugins

Last edited by NiklasR : 06 June 2013 at 03:39 PM.
 
Old 06 June 2013   #3
Ok, figured it out the actual string name of the track has two spaces in it, one before the decimal point, one after it. That's not really obvious when reading the print in the Console and there's no way to copy paste from the console.. (and it's kinda silly IMO to have those spaces in there to begin with)..

anyhoo.. if you compare the track name to "Scale . X"
it works

Cheers,
Brian
 
Old 06 June 2013   #4
Originally Posted by Horganovski: anyhoo.. if you compare the track name to "Scale . X"


Change the interface language, and whoops.
__________________
Cinema 4D Plugin Developer
niklasrosenstein.com/ | Freebies | Plugins
 
Old 06 June 2013   #5
Many thanks again Niklas, those examples and clarification are very helpful, appreciated.

Cheers,
Brian
 
Old 06 June 2013   #6
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:45 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.