SelectionChanger example [SOLVED]

On 30/06/2015 at 12:09, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R16 
Platform:      Mac OSX  ; 
Language(s) :     C++  ;

---------
Hi,

I need to convert a selection of edges in a multi-selection of objects to points.
I know I have to create modelingcommanddata for this.
Here is what I've got so far:

  
ModelingCommandData cd;  
cd.doc = doc;  
cd.arr = selection;  

But how do I assign the left, right and tolerance??
https://developers.maxon.net/docs/Cinema4DCPPSDK/html/group___m_d_a_t_a___c_o_n_v_e_r_t_s_e_l_e_c_t_i_o_n.html

Left should be edges, right points and tolerance false.
Thanks in advance for your help and time!
Greetings,
Casimir Smets

On 30/06/2015 at 14:10, xxxxxxxx wrote:

I would think that you set the three parameters for the MCOMMAND_CONVERTSELECTION call in a BaseContainer that is attached to the ModelingCommandData bc field.

BaseContainer bc;
bc.SetInt32(MDATA_CONVERTSELECTION_LEFT, 1);  // From Edges
bc.SetInt32(MDATA_CONVERTSELECTION_RIGHT, 0); // To Points
bc.SetBool(MDATA_CONVERTSELECTION_TOLERANT, false);
ModelingCommandData cd;
cd.doc = doc;
cd.arr = selection;
cd.bc = &bc;
// Etc.

On 01/07/2015 at 01:50, xxxxxxxx wrote:

Hi Robert!

Yeah, I thought it to be something like that.
I've tested the following code, but it doesn't work:

  
BaseContainer bc;  
bc.SetInt32(MDATA_CONVERTSELECTION_LEFT, 1);  
bc.SetInt32(MDATA_CONVERTSELECTION_RIGHT, 0);  
bc.SetBool(MDATA_CONVERTSELECTION_TOLERANT, false);  
ModelingCommandData cd;  
cd.doc = doc;  
cd.arr = selection;  
cd.bc = &bc;  
if (!SendModelingCommand(MCOMMAND_CONVERTSELECTION, cd))  
{  
  return false;  
}  
EventAdd();  

I do this inside a CommandData/GeDialog plugin, inside Command of the dialog, when a button is pressed.

Does somebody have any idea what could be wrong?

Thanks in advance for your help and time!
Greetings,
Casimir Smets

On 01/07/2015 at 04:44, xxxxxxxx wrote:

Hi Casimir,

you could also check the SelectionChanger class. Maybe it helps.

On 01/07/2015 at 05:02, xxxxxxxx wrote:

Hi Andreas,

Thanks for your answer!
That looks like something I could use!
I will definately look into this 😄

Greetings,
Casimir Smets

On 01/07/2015 at 08:25, xxxxxxxx wrote:

Hi,

I have one problem: I can't get the selected points.
If I try:

  
if (!selectionChanger->GetPoints())  
{  
  GePrint("The selection changer couldn't get the selected points!");  
}  

the console prints out my GePrint...

Here is my relevant code:

  
AutoAlloc<AtomArray> selection;  
if (!selection) return false;  
Vector globalModelingAxis = doc->GetHelperAxis()->GetMg().off;  
Vector projection = newPosition;  
if (setX == true)  
  projection.x = newPosition.x - globalModelingAxis.x;  
if (setY == true)  
  projection.y = newPosition.y - globalModelingAxis.y;  
if (setZ == true)  
  projection.z = newPosition.z - globalModelingAxis.z;  
                    
AutoAlloc<SelectionChanger> selectionChanger;  
for (Int32 x = 0; x < selection->GetCount(); x++)  
{  
   GePrint("Inside the object iteration!");  
   PolygonObject *opPoly = static_cast<PolygonObject*>(selection->GetIndex(x));  
   if (!opPoly) return false;  
   GePrint("Inside the object iteration - first return!");  
   BaseSelect *edgeSelection = opPoly->GetEdgeS();  
   if (!edgeSelection) return false;  
   GePrint("Inside the object iteration - second return!");  
   if (!selectionChanger->InitFromSelection(edgeSelection, Medges))  
   {  
        GePrint("The selection changer didn't initialize!");  
        return false;  
   }  
   else  
   {  
       GePrint("The selection changer did initialize!");  
   }  
   if (!selectionChanger->GetPointS())  
   {  
       GePrint("The selection changer couldn't get the selected points!");  
   }  
   BaseSelect *pointSelection = selectionChanger->GetPointS();  
   if (!pointSelection) return false;  
   GePrint("Inside the object iteration - third return!");  
   Vector *points = opPoly->GetPointW();  
   if (!points) return false;  
   GePrint("Inside the object iteration - END!");  
   for (Int32 y = 0; y < opPoly->GetPointCount(); y++)  
   {  
       if (pointSelection->IsSelected(y))  
       {  
           GePrint("The point from edge is selected!");  
           points[y] = points[y] + projection;  
       }  
  }  
  opPoly->Message(MSG_UPDATE);  
}  

I hope somebody can help!

With kind regards,
Casimir Smets

On 03/07/2015 at 05:04, xxxxxxxx wrote:

Hi,

you forgot to pass the object when initializing the SelectionChanger.
This:

if (!selectionChanger->InitFromSelection(edgeSelection, Medges))

has to be:

if (!selectionChanger->InitFromSelection(edgeSelection, Medges, opPoly))

On 03/07/2015 at 06:06, xxxxxxxx wrote:

Hi Andreas,

Thanks for your answer! That did the trick!

You can mark this thread as solved!

Greetings,
Casimir Smets

On 03/07/2015 at 06:25, xxxxxxxx wrote:

Hi,

One last thing, could you please change the name to something like this: SelectionChanger example.

Thank you very much!
Greetings,
Casimir Smets

On 03/07/2015 at 06:26, xxxxxxxx wrote:

Good thought 🙂