#include <c4d_basedocument.h>
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:
Define two functions to allocate and free the session data:
Bool AllocPickSession() { pickSessionData = NewObj ( PickSessionDataStruct ); return pickSessionData!= nullptr ; } void FreePickSession() { DeleteObj (pickSessionData); }
在
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:
PickSessionDataStruct::multi
被设为
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:
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.
公共成员函数 |
|
PickSessionDataStruct () | |
~PickSessionDataStruct () |
Public Attributes |
|
AtomArray * | active |
maxon::Delegate < void( Int32 , const PickSessionDataStruct *)> | callback |
void * | userdata |
Bool | multi |
PickSessionDataStruct | ( | ) |
Constructor.
~ PickSessionDataStruct | ( | ) |
Destructor.
AtomArray * active |
Filled with the picked objects.
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 .
void* userdata |
The user data passed to the pick session callback . The caller owns the pointed user data.
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 ).