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
    • Login

    Adding to document selection issue

    PYTHON Development
    0
    7
    1.2k
    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 15/01/2016 at 08:48, xxxxxxxx wrote:

      Hey all,

      I'm having a weird issue. I'm trying to make a custom selection in a specific order, but when using the call doc.SetActiveObject(o, c4d.SELECTION_ADD), it doesn't add properly..

      For an example, make 4 objects in your document named "1", "2", "3", and "4". Now run this script.

      def main() :
          
          for index, name in enumerate([2,1,4,3]) : # Random order for testing
              obj = doc.SearchObject(str(name))
              if index == 0:
                  doc.SetActiveObject(obj, c4d.SELECTION_NEW) # new selection for the first object
                  continue
              doc.SetActiveObject(obj, c4d.SELECTION_ADD)
              
          c4d.EventAdd()

      newSelection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
          print [o.GetName() for o in newSelection] # print new selection. It's wrong

      if __name__=='__main__':
          main()

      It's just a random order, and not the order I want. Any ideas?

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

        On 18/01/2016 at 02:29, xxxxxxxx wrote:

        Hello,

        objects are typically selected in the Object Manager. The Object Manager does take care that certain internal caches are updated when the object selection is changed.

        You can force the update of these caches by calling GetActiveObject() while you change the selection:

          
        for index, name in enumerate([4,1,3,2]) : # Random order for testing  
             obj = doc.SearchObject(str(name))  
               
              doc.GetActiveObject()     
                
              if index == 0:  
                      doc.SetSelection(obj, c4d.SELECTION_NEW) # new selection for the first object  
                      continue  
              doc.SetSelection(obj, c4d.SELECTION_ADD)  
        

        Best wishes,
        Sebastian

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

          On 29/01/2016 at 10:00, xxxxxxxx wrote:

          Hello,

          was your question answered?

          Best wishes,
          Sebastian

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

            On 04/09/2016 at 01:53, xxxxxxxx wrote:

            Hello

            I think the question is not completely answered -

            your code work but it will not hold the right order of the selection.

            this will select the objects from 1-4 but when you call - doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER) the order will not  be 1-4

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

              On 04/09/2016 at 01:58, xxxxxxxx wrote:

              Add 4 Null Objects in a document and run

              import c4d
              from c4d import gui
              #Welcome to the world of Python
                
                
              def main() :
                  mylist = doc.GetObjects()
                  i=0
                  print "-save-"
                  for node in mylist:
                      print node.GetName()
                      if i == 0:
                          doc.SetActiveObject(node, mode=c4d.SELECTION_NEW)
                      else:
                          doc.SetActiveObject(node, mode=c4d.SELECTION_ADD)
                      i +=1
                  c4d.EventAdd()
                  
                  print "-get-"
                  
                  getlist = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
                  for node in getlist:
                      print node.GetName()
                
              if __name__=='__main__':
                  main()
                
              
              

              result is 
              -save-
              4
              3
              2
              1
              -get-
              2
              4
              3
              1

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

                On 04/09/2016 at 23:49, xxxxxxxx wrote:

                Hello,

                as I said and showed in my post above, you have to call GetActiveObject() inside your selection loop.

                Best wishes,
                Sebastian

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

                  On 05/09/2016 at 01:31, xxxxxxxx wrote:

                  Hey Sebastian,

                  sorry - you are absolut right - thanks - that helps alot

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