PickSessionDataStruct Struct Reference

#include <c4d_basedocument.h>

Detailed Description

A pick session allows to select objects in the viewport or in the Object Manager.
An example of pick session is the way objects are selected for a link field pressing its interrogation's button.
A session is usually started with BaseDocument::StartPickSession() and can be ended by the developer with BaseDocument::StopPickSession().
First, declare a static variable for the pick session data:

static PickSessionDataStruct* pickSessionData = nullptr;
Definition: c4d_basedocument.h:455

Define two functions to allocate and free the session data:

Bool AllocPickSession()
pickSessionData = NewObj(PickSessionDataStruct);
return pickSessionData!=nullptr;
void FreePickSession()
maxon::Bool Bool
Definition: ge_sys_math.h:55
#define DeleteObj(obj)
Definition: newobj.h:159
#define NewObj(T,...)
Definition: newobj.h:108

In PluginStart() (usually defined in the Main.cpp of the plugin) call AllocPickSession() and in PluginEnd() call FreePickSession().
Do not forget to forward declare AllocPickSession() and FreePickSession() at the beginning of Main.cpp. (Otherwise linking errors are raised by the compiler.)
Then the pick data can be initialized and the session started:

if (pickSessionData)
pickSessionData->multi = true;
pickSessionData->callback = pickSessionCallBack;
maxon::Delegate< void(Int32, const PickSessionDataStruct *)> callback
The pick session callback. The arguments are the flags and the populated PickSesionDataStruct with an...
Definition: c4d_basedocument.h:457
Bool multi
Set to true for multi-pick sessions. Usually a pick session ends when something is selected....
Definition: c4d_basedocument.h:459

PickSessionDataStruct::multi is set to true to start a multi-object pick session. It is also possible to assign custom data to PickSessionDataStruct::userdata for use in the pick session callback.
Finally, the callback can be defined like this:

void pickSessionCallBack(Int32 flags, const PickSessionDataStruct *psd)
for (Int32 i=0; i<psd->active->GetCount(); i++)
C4DAtom* atom = psd->active->GetIndex(i);
if (atom && atom->IsInstanceOf(Obase))
BaseObject *ob = (BaseObject*)atom;
if (ob)
void GePrint(const maxon::String &str)
Int32 GetCount() const
Definition: c4d_baselist.h:1649
C4DAtom * GetIndex(Int32 idx) const
Definition: c4d_baselist.h:1664
String GetName() const
Definition: c4d_baselist.h:2348
Definition: c4d_baseobject.h:225
Definition: c4d_baselist.h:1362
Bool IsInstanceOf(Int32 id) const
Definition: c4d_baselist.h:1403
maxon::Int32 Int32
Definition: ge_sys_math.h:60
#define Obase
Base object - BaseObject.
Definition: ge_prepass.h:1026
AtomArray * active
Filled with the picked objects.
Definition: c4d_basedocument.h:456

The callback is called when the pick session has ended. PickSessionDataStruct::active holds the list of picked objects. In this example, the name of the selected object(s) during the pick session is printed to the console.

Drag&Drop is handled automatically for an AtomArray by this functionality.
If GeUserArea::HandleMouseDrag() is used with an AtomArray, all the objects in the array are pickable. There is no additional work needed.

Public Member Functions

 PickSessionDataStruct ()
 ~PickSessionDataStruct ()

Public Attributes

maxon::Delegate< void(Int32, const PickSessionDataStruct *)> callback
void * userdata
Bool multi

Constructor & Destructor Documentation

◆ PickSessionDataStruct()


◆ ~PickSessionDataStruct()


Member Data Documentation

◆ active

AtomArray* active

Filled with the picked objects.

◆ callback

maxon::Delegate<void(Int32, const PickSessionDataStruct*)> callback

The pick session callback. The arguments are the flags and the populated PickSesionDataStruct with any selected objects linked in the active AtomArray.

◆ userdata

void* userdata

The user data passed to the pick session callback. The caller owns the pointed user data.

◆ multi

Bool multi

Set to true for multi-pick sessions. Usually a pick session ends when something is selected. With a multi-pick session it ends when the user terminates it (ESC or double-click).