Creating a Pick Session
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/08/2012 at 13:55, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13
Platform: Windows ;
Language(s) : C++ ;---------
I'm having difficulty getting a pick session to work. I want to run a command from the menu and have it start a pick session, you pick an object and then it completes running the command. Right now I've got the pick session starting but once you click an object cinema crashes.I found the examples in the documentation under "PickSessionDataStruct" but I think that mostly applies to custom GUIs.
Could someone post an example of how to properly handle a pick session? I would be very grateful.
- Carter
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/08/2012 at 01:04, xxxxxxxx wrote:
You should consider calling ViewportSelect::PickObject() static method. This method is easier to handle and setup than PickSessionDataStruct.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/08/2012 at 10:48, xxxxxxxx wrote:
I hadn't thought about using ViewportSelect. Unfortunately I'd also have to check for selection changes in the object manager if the user chose to select that way.
I've found a different way to approach what I wanted to do so it doesn't look like I really need the pick session anymore but if someone has an example I'm still curious how to do it.
-
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.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/09/2012 at 09:22, xxxxxxxx wrote:
Hi Yannick,
I'm having a hard time applying your code.
If I create the static PickSessionDataStruct *picksession variable and the methods in the MenuTest.cpp file. I get undefined errors when calling to them from the PluginStart() & PluginEnd() functions in the Main.cpp file.
If I create the static PickSessionDataStruct *picksession variable and methods in the Main.cpp. I can't seem to call the callback method correctly in the MenuTest.cpp file.Quote:
"In PluginStart() (in the Main.cpp of the plugin) call AllocPickSession() and in PluginEnd() call FreePickSession()."AFAIK. In C++ we can't call to a function from one .cpp file, to another .cpp file. So that is making me think that the code you posted all needs to go in the Main.cpp file. But that's not the way you've written it. And when I try to do that I can't get it to work.
See what I mean?Could you possibly post the MenuTest plugin's Main.cpp & MenuTest.cpp with this code in it?
That would help clear up where everything needs to go.Thanks,
-ScottA -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/09/2012 at 12:28, xxxxxxxx wrote:
Hi,
You just need to forward declare AllocPickSession() and FreePickSession() at the beginning of Main.cpp like the Register*() functions.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/09/2012 at 13:39, xxxxxxxx wrote:
That got it working.
Thank you,
-ScottA