How to move a point (C++)

Hello there,

I’ve to create a Rhinoceros plugin for work. So i’m trying to get used to manipulate object though SDK.
My actual objective is simply to move a point by adding values to his position.

So my problem is that I cannot find a way to:
-modify the getted point
-print a new point

Let’s see what my code looks like :

CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
{
// How much i want to move the point …
double xMove = 1.0;
double yMove = 1.0;
double zMove = 1.0;
.
CRhinoGetObject second;
second.SetCommandPrompt( L"Select a point" );
.
CRhinoGet::result something = second.GetObjects(1, 1);
if(second.CommandResult() != CRhinoCommand::success) return second.CommandResult();
.
.
const CRhinoObject* obj = second.Object(0).Object();
if(!obj) return CRhinoCommand::failure;
.
const ON_Point& pt = CRhinoPointObject::Cast(obj)->Point();
.
.
ON_Point newOne(pt.point.x + xMove, pt.point.y + yMove, pt.point.z + zMove); // new location
.
// would like do to something like CRhinoPointObject::Cast(obj)->SetPoint(newOne);
// but try to create new point :
CRhinoPointObject testytest;
if(!testytest.IsValid()) ::RhinoApp().Print(L"Oops! “); // print this … Don’t understand why
.
ON_UUID uuid = testytest.Attributes().m_uuid;
ON_UuidToString( uuid, str );
::RhinoApp().Print(L"ID: "%s", “, str); // give 000000000…
.
testytest.SetPoint(newOne); // seems work because:
::RhinoApp().Print(L” position: ‘%.2f’, ‘%.2f’, ‘%.2f’.\n”,
newOne.point.x, newOne.point.y, newOne.point.z); // give new position
.
// tried:
// testytest.CopyFrom(CRhinoPointObject::Cast(obj));
// testytest.SetPoint(newOne);
.
.
// do nothing ?
// testytest.Draw(second.View()->ActiveViewport());
// ON_Xform pff;
// second.View()->ActiveViewport().DrawRhinoObject(&testytest, pff);
// testytest.Draw(second.View()->ActiveViewport());
.
context.m_doc.Redraw(); // assume i have to do this at the end
.
return CRhinoCommand::success;
}

Thank you in advance

Almost do the trick :smile:

How about something like this:

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  CRhinoGetObject go;
  go.SetCommandPrompt(L"Select points to move");
  go.SetGeometryFilter(CRhinoGetObject::point_object);
  go.EnableSubObjectSelect(FALSE);
  go.GetObjects(1, 0);
  if (go.CommandResult() != CRhinoCommand::success)
    return go.CommandResult();

  for (int i = 0; i < go.ObjectCount(); i++)
  {
    const CRhinoObjRef& obj_ref = go.Object(i);
    const ON_Point* point_obj = obj_ref.Point();
    if (0 != point_obj)
    {
      ON_3dPoint point = point_obj->point;
      point.x += 1.0;
      point.y += 1.0;
      point.z += 1.0;
      context.m_doc.ReplaceObject(obj_ref, point);
    }
  }
  context.m_doc.Redraw();

  return CRhinoCommand::success;
}