getting access to the live selection via python

Become a member of the CGSociety

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

Thread Tools Search this Thread Display Modes
Old 11 November 2013   #1
getting access to the live selection via python


I am having a little python problem again :( I am trying to write a little script for switching on/off the function "only select visible elements" in the live selection. So far I found the code to get access to it, but I am not sure how to carry on. Do I have to do it over a bool function? It would be great, if someone could give me a hint and help me a little bit.

Thanks a lot Anna

That's how far I am, but I never know how to carry on or actually which way to use.

import c4d
from c4d import gui
#Welcome to the world of Python

def main():

if __name__=='__main__':
Old 11 November 2013   #2
You have the correct ID but the parameter is accessed through the tool data container like this:

import c4d def main(): td = doc.GetActiveToolData() if td[c4d.MDATA_SELECTLIVE_VISIBLE]: td[c4d.MDATA_SELECTLIVE_VISIBLE] = False else: td[c4d.MDATA_SELECTLIVE_VISIBLE] = True c4d.EventAdd() if __name__=='__main__': main()

Last edited by Darter : 11 November 2013 at 01:27 PM.
Old 11 November 2013   #3

thanks a lot for your help. It works perfectly

Just that I am understanding it right. (I am still a beginner with python, so this might be beginner's questions)

If I want to get access to the ID's in python, I always have to find out in which container they are lying, haven't I? And am I right, that I can find these information in the pytohn sdk in the section c4d.documents.BaseDocument?

So with your first line,

td = doc.GetActiveToolData()

you just said, that the td is the doc.GetActiveToolData() so that it is short and I don't have to write each time, I want to use the c4d.MDATA_SELECTLIVE_VISIBLE
I don't have to write
doc.GetActiveToolData(c4d.MDATA_SELECTLIVE_VISIBLE ).

then with the next line


you are actually checking, if I am in the live selection tool.

Then you say, if it is off, it should be switch on, or the other way round.


so there is one thing I don't understand. It seems to me, that if the select only visible elements is off, it should be switched on, but what is, if it is the other way round? Meaning if it is switched on and should be switched off?

It would be nice, if you could explain it to me, only if you have time of course and thanks
a lot for your help again.


and in the next part
Old 11 November 2013   #4
No worries, glad it's working.

Properties of things like scene objects, including tags and materials, can be accessed directly. For example, instead of:
bc = cube.GetData() bc.SetBool(c4d.PRIM_CUBE_DOFILLET, True) cube.SetData(bc)

you can use:
cube[c4d.PRIM_CUBE_DOFILLET] = True

GetActiveToolData() is used to get the container so the stored value can be changed. It takes no arguments and to get the value in one line you'd use: doc.GetActiveToolData()[c4d.MDATA_SELECTLIVE_VISIBLE].

'td[c4d.MDATA_SELECTLIVE_VISIBLE]' is equivalent to 'td[c4d.MDATA_SELECTLIVE_VISIBLE] == True'. If the expression evaluates to False, the 'else' block is executed.

Last edited by Darter : 11 November 2013 at 02:06 AM.
Old 11 November 2013   #5
thanks a lot for your explanation That was very helpful

Have a nice weekend

Old 11 November 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.
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
Society of Digital Artists

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

All times are GMT. The time now is 03:11 PM.

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