Hi everyone is it possible to pick a sub object with Ctrl + shift + click from a simple CRhinoGetObject ?
what i want is a to pick a list of ON_SubDVertex… for doing some math on them… i got a compiling code but still unable to pick a SubVertex sub object from viewport thanks.
that’s in C++ of course.
Hi @JulienPoivret,
Perhaps something like this?
CRhinoCommand::result CCommandTest::RunCommand(
const CRhinoCommandContext& context
)
{
CRhinoGetObject go;
go.SetGeometryFilter(CRhinoObject::meshvertex_filter);
go.SetCommandPrompt(L"Select vertices");
go.GetObjects(1, 0);
if (go.CommandResult() != CRhinoCommand::success)
return go.CommandResult();
const int object_count = go.ObjectCount();
for (int i = 0;i < object_count; i++)
{
const CRhinoObjRef& object_ref = go.Object(i);
const ON_SubDComponentRef* pSubDVertRef = object_ref.SubDComponentRef();
if (nullptr != pSubDVertRef)
{
const ON_SubDVertex* pSubDVertex = pSubDVertRef->Vertex();
if (nullptr != pSubDVertex)
{
const CRhinoSubDObject* pSubDObject = CRhinoSubDObject::Cast(object_ref.Object());
if (nullptr != pSubDObject)
{
const ON_SubD* subd = &pSubDObject->SubD();
if (ON_UNSET_UINT_INDEX != pSubDVertex->VertexId() && nullptr != subd)
{
// TODO...
}
}
}
continue;
}
}
return CRhinoCommand::success;
}
– Dale
Thank you ! that what i need !
One more question it is possible to modify those subDvertex or are they just constant ?
what i would love is to modify those vertex ?
that a shame that the provided return value of the api are most of the time constants pointers why that ? i pretty sure that i missing something about this a logic api or something…
i’m keeping digging in the API but an advice would be helpful… ref are use full when you can modify them… no point to make copy no ?
Hi @JulienPoivret,
To modify document geometry:
- Get the Rhino object
- Get the object’s geometry
- Make a copy of the object’s geometry
- Modify the geometry copy
- Replace the original with the copy using
CRhinoDoc::ReplaceObject
.
Does this help?
– Dale
if you take a quick look in the sample code bellow ptlist is a ON_SubDVertexArray
but i only found read only method for that class …
Reading point is fine but what i missing for giving back value on my subD vertex ?
- is there a fancy system of memory cache with update system?
- the key is to duplicate the object so did i do it correctly there ?
so at this time i fail on point 4 of your directive i guess are we all right with that ?
And thank you, for your help sincerely, you are amazing to help me with that api.
go.SetCommandPrompt(L"Select the SubD ! ");
go.SetGeometryFilter(CRhinoObject::subd_object);
res = go.GetObjects(1, 1);
if (res == CRhinoGet::object)
{
CRhinoObjRef& obj_ref = go.Object(0);
ON_Geometry* geom = obj_ref.Object()->Geometry()->Duplicate();
ON_SubD* ModifiableSubD = ON_SubD::Cast(geom);
ON_SubDVertexArray ptlist = ModifiableSubD->VertexArray();
for (size_t i = 0; i < ptlist.VertexCount(); i++)
{
ON_3dPoint pt;
pt.x = ptlist[i]->SubdivisionPoint().x;
pt.y = ptlist[i]->SubdivisionPoint().y;
pt.z = ptlist[i]->SubdivisionPoint().z + 10;
context.m_doc.AddPointObject(pt);
}
delete geom;
i have updated the code (a bit) with the step 5 of @dale procedure completed (i have compiled the code and the subD is well replaced in the document. so that one step beyond…)
So the problem is now surrounded at step 4 → how to modify those vertex values of the ON_SubD* object ?
when i dereference this pointer i can’t see any method providing me a non constant ON_3dpoint that make me nut ! what i need there is the API correct class method() for doing my math more fun than just an addition on a Z value…
the Code for clarity:
go.SetCommandPrompt(L"Select the SubD ! ");
go.SetGeometryFilter(CRhinoObject::subd_object);
res = go.GetObjects(1, 1);
if (res == CRhinoGet::object)
{
CRhinoObjRef& obj_ref = go.Object(0);
ON_Geometry* geom = obj_ref.Object()->Geometry()->Duplicate();
ON_SubD* ModifiableSubD = ON_SubD::Cast(geom);
/*
from there i just want to modify vertex of this "ModifiableSubD" (if possible)
like for instance just offseting the Z vallue of each vertex.
*/
ON_SubDVertexArray ptlist = ModifiableSubD->VertexArray();
for (size_t i = 0; i < ptlist.VertexCount(); i++)
{
ON_3dPoint pt;
pt.x = ptlist[i]->SubdivisionPoint().x;
pt.y = ptlist[i]->SubdivisionPoint().y;
pt.z = ptlist[i]->SubdivisionPoint().z + 10;
context.m_doc.AddPointObject(pt);
}
context.m_doc.ReplaceObject(obj_ref, *ModifiableSubD);
context.m_doc.Redraw();
delete geom;
even on On_SubDVertex i cannot see a way to modify every thing sim to be read only ?!
am i wrong on that point ?
( const values are fun until they betray you ! lol )
Rhino C++ API: ON_SubDVertex Class Reference (rhino3d.com)
thanks anyone for any Help !