Can't work out BaseDocument.StartPickSession

  • 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)
            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.

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

  • 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:
    def main(pickedObjects=None):
        doc = c4d.documents.GetActiveDocument()
        if pickedObjects is None:
            doc.StartPickSession(OnPick, multi=False)
    if __name__=='__main__':

    If you have any questions, feel free to ask.

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

  • 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. 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?


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


Log in to reply