How to get and move vertices of mesh edges

Hi everybody,

I need to know hot to get and move the vertices of a selected mesh edge. Although it seems an easy task I could not get them. I made an attempt but the indices of the selected edge and the mesh topology edge seem not to match…

CRhinoObjectIterator it(CRhinoObjectIterator::undeleted_objects, CRhinoObjectIterator::active_and_reference_objects);
	it.EnableVisibleFilter(TRUE);
	for (CRhinoObject* pObject = it.First(); pObject; pObject = it.Next()) {
		ON_SimpleArray<ON_COMPONENT_INDEX> subidxs;
		pObject->GetSelectedSubObjects(subidxs);
		for(int su = 0; su < subidxs.Count(); su++)
		if (subidxs[su].m_type == ON_COMPONENT_INDEX::meshtop_edge) {
			const ON_Mesh* mesh = ON_Mesh::Cast(pObject->Geometry());
			ON_SimpleArray<ON_2dex> edges;
			mesh->GetMeshEdges(edges);
			ON_3dPoint vert1 = mesh->m_V[edges[subidxs[su].m_index].i];
			ON_3dPoint vert2 = mesh->m_V[edges[subidxs[su].m_index].j];
			vert1.Transform(translateXform);
			vert2.Transform(translateXform);
		        mesh.SetVertex(edges[idx].i, vert1);
	                mesh.SetVertex(edges[idx].j, vert2)
		}
	}

Hi @gennaro,

Here is an alternate approach for getting select mesh edges:

CRhinoGetObject go;
go.SetCommandPrompt(L"Select mesh edges");
go.SetGeometryFilter(CRhinoGetObject::meshedge_filter);
go.EnablePreSelect(TRUE);
go.EnablePostSelect(FALSE);
go.GetObjects(1, 0);
if (go.CommandResult() == CRhinoCommand::success)
{
  for (int i = 0; i < go.ObjectCount(); i++)
  if (CRhinoGet::object == go.Result())
  {
    const CRhinoObjRef& obj_ref = go.Object(i);
    const ON_MeshComponentRef* mesh_ref = obj_ref.MeshComponentRef();
    if (nullptr != mesh_ref)
    {
      ON_wString str;
      ON_UuidToString(obj_ref.ObjectUuid(), str);
      RhinoApp().Print(L"Object id: %s, Edge index: %i.\n", 
        static_cast<const wchar_t*>(str),
        mesh_ref->MeshTopologyEdgeIndex());
    }
  }
}

Also, when process, if a mesh has more than one edge selected, transform them all at once.

– Dale