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 CLOSED
 
Thread Tools Search this Thread Display Modes
  11 November 2013
getting access to the live selection via python

Hey,

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():
LiveSelektion[c4d.MDATA_SELECTLIVE_VISIBLE]


if __name__=='__main__':
main()
 
  11 November 2013
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.
 
  11 November 2013
Hey,

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

if td[c4d.MDATA_SELECTLIVE_VISIBLE]:

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.

td[c4d.MDATA_SELECTLIVE_VISIBLE] = False
else:
td[c4d.MDATA_SELECTLIVE_VISIBLE] = True

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.

Anna




and in the next part
 
  11 November 2013
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.
 
  11 November 2013
thanks a lot for your explanation That was very helpful

Have a nice weekend

Anna
 
  11 November 2013
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 01:58 AM.


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