checking if an object is selected

On 27/07/2018 at 20:01, xxxxxxxx wrote:

Hey there,

I'm trying to make a simple script that will do two different functions depending on if an object is already selected or not selected in the current document. In the end, I'd like to just be able to select the first object if nothing is already selected otherwise I'd like it to pass and not select the first object. I've tried a bunch of ways already but this code seems to have got me the furthest way there.

Any ideas how I can do this? Thanks!

import c4d
def main() :
    currDoc = c4d.documents.GetActiveDocument()
    selection = currDoc.GetSelection()
    if selection == None:
        print 'need a selection'
        print 'an object is already selected'
if __name__=='__main__':

On 27/07/2018 at 23:02, xxxxxxxx wrote:

try BaseDocument.GetActiveObjects()

On 30/07/2018 at 01:46, xxxxxxxx wrote:


it is also possible to check if a given object is selected by checking the bit c4d.BIT_ACTIVE. The bit is accessed with BaseList2D.GetBit()

sceneObject = doc.GetFirstObject()  
while sceneObject is not None:  
  if sceneObject.GetBit(c4d.BIT_ACTIVE) :  
      print("Object selected")  
  sceneObject = sceneObject.GetNext()  

best wishes,

On 30/07/2018 at 12:21, xxxxxxxx wrote:

Thanks those all worked really well. I ended up using GetActiveObject() to make the switch