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().
Example:
First, declare a static variable for the pick session data:

static PickSessionDataStruct* pickSessionData = nullptr;

Define two functions to allocate and free the session data:

Bool AllocPickSession()
{
pickSessionData = NewObj(PickSessionDataStruct);
return pickSessionData!=nullptr;
}
void FreePickSession()
{
DeleteObj(pickSessionData);
}

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)
{
doc->StopPickSession(true);
pickSessionData->multi = true;
pickSessionData->callback = pickSessionCallBack;
doc->StartPickSession(pickSessionData);
}

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)
GePrint(ob->GetName());
}
}
}

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.

Note
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

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

Constructor & Destructor Documentation

◆ PickSessionDataStruct()

Constructor.

◆ ~PickSessionDataStruct()

Destructor.

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