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

    Can't work out BaseDocument.StartPickSession

    Cinema 4D SDK
    python r21
    2
    7
    1.1k
    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.
    • G
      Graeme
      last edited by Graeme

      I want to do something very simple: Enter into a pick session & return the 1st object picked, ending the session & storing the object reference. I don't need a multi-pick session.
      Here's my code:

      def OnPick(flags, active, multi):
          if flags & c4d.PICKSESSION_FLAG_CANCELED:
              print "User cancel"
              doc.StopPickSession(cancel = True)
          else:
              doc.StopPickSession(cancel = False)
          print "active: ", active
      
      def main():
          doc = documents.GetActiveDocument()
          doc.StartPickSession(OnPick, multi=False)
      

      This seems to work & 'active' contains the picked object.
      But I can't return any reference to the object in 'active'
      as soon as I try to read it into a variable, or return it I get AttributeError: 'function' object has no attribute 'function'.

      I'm afraid I just don't understand how pick sessions are supposed to work.
      Any help would be very appreciated.

      1 Reply Last reply Reply Quote 0
      • G
        Graeme
        last edited by Graeme

        Any ideas anyone ?
        I can't find an example anywhere on the internet for how a pick session works, except for one plugin cafe post, which is how I got as far as I have.

        1 Reply Last reply Reply Quote 0
        • M
          m_adam
          last edited by

          Hi @Graeme first of all, we process and answers question each days during the working week, so it's not necessary to bump a topic, this will not accelerate our answers.

          Regarding your issue, PickSession is an async task, meaning, this will not block the current execution flow. So there is no real way to catch in the main method the result just after the StartPickingSession.

          So the solution is on the OnPick either you do what you expect to do, or you reroute the data to where you want.
          Here an example

          import c4d
          
          
          def OnPick(flags, active, multi):
              if flags & c4d.PICKSESSION_FLAG_CANCELED:
                  doc.StopPickSession(cancel=True)
          
              main(active)
              
              
          def main(pickedObjects=None):
              doc = c4d.documents.GetActiveDocument()
              
              if pickedObjects is None:
                  doc.StartPickSession(OnPick, multi=False)
          
              else:
                  print(pickedObjects)
                  doc.StopPickSession(cancel=False)
          
          
          if __name__=='__main__':
              main()
          
          

          If you have any questions, feel free to ask.
          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 0
          • G
            Graeme
            last edited by Graeme

            Thanks Maxime, I'll process this & see if I can work it out.
            Thanks for the example.

            1 Reply Last reply Reply Quote 0
            • G
              Graeme
              last edited by

              So trying this out, there are a couple of problems:

              1. Once I have run the script & picked an object, it 'remembers' it & if I run the script again, pickedObjects contains the object I picked in that previous session. I want the selection to be cleared each time
              2. If I revert my scene to saved, run the script & press escape to cancel the pick session, it reliably hangs Cinema 4D - is there some kind of clean-up I need to be performing or msg to send ?

              Thanks for your help.

              1 Reply Last reply Reply Quote 0
              • M
                m_adam
                last edited by

                1. I'm not able to reproduce or I don't understand your problem.
                  Just to be sure you execute the script within the script manager?

                2. Same here I'm not able to reproduce on which version are you?

                Cheers,
                Maxime.

                MAXON SDK Specialist

                Development Blog, MAXON Registered Developer

                1 Reply Last reply Reply Quote 0
                • M
                  m_adam
                  last edited by

                  Without a further reply from you until tomorrow I will consider and mark this topic as solved, but feel free to open it again if you have more information.

                  Cheers,
                  Maxime.

                  MAXON SDK Specialist

                  Development Blog, MAXON Registered Developer

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