CGTalk > Software Specific Forums > Maxon Cinema 4D
To minimize the ads you see on this page create a CGTalk account and log in HERE
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 10-04-2012, 05:28 PM   #1
ricksilliker
Veteran
 
ricksilliker's Avatar
portfolio
Rick Silliker
Technical Artist
Freelance
Burbank, USA
 
Join Date: Aug 2010
Posts: 55
Send a message via AIM to ricksilliker
parent command

Hi All,

So I have have been running through the help docs for the sdk, and I cannot seem to find any sort of parent function for python. I have a feeling it is GeListNode.InsertUnder(), but I cannot seem to get it to work for the life of me. Mostly because I am having a hard time understanding the help docs and their descriptions. Here is my simple script so far. (Trying to group objects).

Quote:
import c4d

#===================

def groupIt(doc, op):
doc.SetActiveObject(op)

xName = c4d.BaseList2D.GetName(x) #gather obj name
drive = c4d.BaseObject(c4d.Onull) #create drive null
doc.InsertObject(drive) #insert drive null

drive[c4d.ID_BASELIST_NAME] = xName + "_DRIVE" #name drive null

c4d.GeListNode.InsertUnder(drive(x)) #parent object under drive null

if __name__=='__main__':
doc = c4d.documents.GetActiveDocument()
selected = doc.GetActiveObjects(0)

for x in selected:
groupIt(doc, x)
c4d.EventAdd()


Any assistance or push in the right direction would be great.

Rick
 
Old 10-04-2012, 08:41 PM   #2
Horganovski
Freelance Animator/Rigger
 
Horganovski's Avatar
portfolio
Brian Horgan
Graphite9
Dublin, Ireland
 
Join Date: Apr 2007
Posts: 4,790
In my humble opinion the Python docs leave a lot to be desired, it's almost a case where you have to know the answer already to be able to find it, heh.

'Insert under' is what you need in this case though. The tricky thing is that the command doesn't take the coordinates of the new parent object into account though, so if you just drop an object under a new object that's in a new position the child ends up moving as it maintains whatever local coordinates it has but they are now relative to its new parent (why there's not a simple flag for the InsertUnder command to handle this is beyond me). What I've done to work around this is to store the current world position of the object first, then parent it, then restore that world position again.

Code:
def Reparent(child,parent): mat = child.GetMg() # Record the current location doc.AddUndo(c4d.UNDOTYPE_CHANGE, child) child.InsertUnder(parent) child.SetMg(mat)

I guess the forum will eat this code, but there's only one indentation so it should be easy to fix.

Cheers,
Brian
 
Old 10-04-2012, 08:41 PM   #3
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 04:56 PM.


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