Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Register
    • Login

    checking if an object is selected

    PYTHON Development
    0
    4
    787
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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'
              
          else:
              print 'an object is already selected'
          
      if __name__=='__main__':
          main()
        
      
      
      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

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

        try BaseDocument.GetActiveObjects()

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

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

          Hello,

          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(sceneObject.GetName())  
                print("Object selected")  
              
            sceneObject = sceneObject.GetNext()  
          

          best wishes,
          Sebastian

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

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

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post