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;
Definition: c4d_basedocument.h:461

Define two functions to allocate and free the session data:

Bool AllocPickSession()
{
pickSessionData = NewObj(PickSessionDataStruct);
return pickSessionData!=nullptr;
}
void FreePickSession()
{
DeleteObj(pickSessionData);
}
maxon::Bool Bool
Definition: ge_sys_math.h:51
#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)
{
doc->StopPickSession(true);
pickSessionData->multi = true;
pickSessionData->callback = pickSessionCallBack;
doc->StartPickSession(pickSessionData);
}
const char * doc
Definition: pyerrors.h:226
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:463
Bool multi
Set to true for multi-pick sessions. Usually a pick session ends when something is selected....
Definition: c4d_basedocument.h:465

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++)
{
if (atom && atom->IsInstanceOf(Obase))
{
if (ob)
GePrint(ob->GetName());
}
}
}
Py_ssize_t i
Definition: abstract.h:645
PyObject * ob
Definition: abstract.h:721
PyCompilerFlags * flags
Definition: ast.h:14
void GePrint(const maxon::String &str)
Int32 GetCount() const
Definition: c4d_baselist.h:1827
C4DAtom * GetIndex(Int32 idx) const
Definition: c4d_baselist.h:1842
Definition: c4d_baseobject.h:248
Definition: c4d_baselist.h:1521
maxon::Int32 Int32
Definition: ge_sys_math.h:56
#define atom
Definition: graminit.h:72
#define Obase
Base object - BaseObject.
Definition: ge_prepass.h:1090
AtomArray * active
Filled with the picked objects.
Definition: c4d_basedocument.h:462

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