THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/09/2012 at 03:20, xxxxxxxx wrote:
Hi,
Here's a simple example of using PickSessionDataStruct to handle a picking session.
First, declare a static variable for the picking session:
static PickSessionDataStruct *picksession;
Define 2 functions to allocate and free the picking session:
Bool AllocPickSession()
{
picksession = gNew PickSessionDataStruct;
return picksession!=NULL;
}
void FreePickSession()
{
gDelete(picksession);
}
In PluginStart() (in the Main.cpp of the plugin) call AllocPickSession() and in PluginEnd() call FreePickSession().
Then the picking session can be initialized and started:
if (picksession)
{
doc->StopPickSession(TRUE); // If there's another picking session currently in process, stop it
picksession->multi = TRUE;
picksession->callback = pickSessionCallBack;
doc->StartPickSession(picksession);
}
I tested this code in MenuTest::Execute() in the SDK examples but it can also be put when a button is pushed, a tool is executed etc.
I initialized PickSessionDataStruct::multi to TRUE (default to FALSE) to start a multi-object picking session.
The picking session callback can be defined like this:
void pickSessionCallBack(LONG flags, const PickSessionDataStruct *psd)
{
for (LONG 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 picking session is ended; in it I just print the name of the objects that were picked.