Method 1 - The Short Way
CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
{
CRhinoGetObject go;
go.SetCommandPrompt( L"Select brep" );
go.SetGeometryFilter( ON::brep_object );
go.GetObjects(1,1);
if( go.CommandResult() != success )
return go.CommandResult();
CRhinoObjRef ref = go.Object(0);
// Simple translation transformation
ON_Xform xform;
xform.Translation( ON_3dVector(18,-18,-25) );
context.m_doc.TransformObject( ref, xform );
context.m_doc.Redraw();
return success;
}
Method 2 - The Long Way
CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
{
CRhinoGetObject go;
go.SetCommandPrompt( L"Select brep" );
go.SetGeometryFilter( ON::brep_object );
go.GetObjects(1,1);
if( go.CommandResult() != success )
return go.CommandResult();
const CRhinoObjRef& ref = go.Object(0);
const CRhinoObject* obj = ref.Object();
if( !obj )
return failure;
const ON_Brep* brep = ref.Brep();
if( !brep )
return failure;
ON_Brep* dupe = brep->Duplicate();
if( !dupe )
return failure;
// Simple translation transformation
ON_Xform xform;
xform.Translation( ON_3dVector(18,-18,-25) );
if( !dupe->Transform( xform ) )
{
RhinoApp().Print( L"Unable to transform object.\n" );
delete dupe;
return failure;
}
ON_3dmObjectAttributes attribs = obj->Attributes();
context.m_doc.AddBrepObject( *dupe, &attribs );
// Since CRhinoDoc::AddBrepObject() make a copy of the input
// brep, we are responsible for deleting the original. Otherwise
// we will leak memory;
delete dupe;
// Delete the selected object
context.m_doc.DeleteObject( ref );
context.m_doc.Redraw();
return success;
}
Method 1 - The Short Way
Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
As IRhinoCommand.result
Dim go As New MRhinoGetObject()
go.SetCommandPrompt("Select brep")
go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object _
Or IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object)
go.GetObjects(1, 1)
If (go.CommandResult() <> IRhinoCommand.result.success) Then
Return go.CommandResult()
End If
' Simple translation transformation
Dim xform As New OnXform()
xform.Translation(18, -18, -25)
Dim objref As MRhinoObjRef = go.Object(0)
context.m_doc.TransformObject(objref, xform)
context.m_doc.Redraw()
Return IRhinoCommand.result.success
End Function
Method 2 - The Long Way
Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
As IRhinoCommand.result
Dim go As New MRhinoGetObject()
go.SetCommandPrompt("Select brep")
go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object Or _
IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object)
go.GetObjects(1, 1)
If (go.CommandResult() <> IRhinoCommand.result.success) Then
Return go.CommandResult()
End If
Dim objref As MRhinoObjRef = go.Object(0)
Dim obj As IRhinoObject = objref.Object()
If (obj Is Nothing) Then Return IRhinoCommand.result.failure
Dim brep As IOnBrep = objref.Brep()
If (brep Is Nothing) Then Return IRhinoCommand.result.failure
Dim dupe As New OnBrep(brep)
' Simple translation transformation
Dim xform As New OnXform()
xform.Translation(18, -18, -25)
If (Not dupe.Transform(xform)) Then
RhUtil.RhinoApp().Print("Unable to transform object." + vbCrLf)
Return IRhinoCommand.result.failure
End If
Dim attribs As IOn3dmObjectAttributes = obj.Attributes()
context.m_doc.AddBrepObject(dupe, attribs)
' Delete the selected object
context.m_doc.DeleteObject(objref)
context.m_doc.Redraw()
Return IRhinoCommand.result.success
End Function
Method 1 - The Short Way
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
{
MRhinoGetObject go = new MRhinoGetObject();
go.SetCommandPrompt("Select brep");
go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object
| IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object);
go.GetObjects(1, 1);
if(go.CommandResult() != IRhinoCommand.result.success)
return go.CommandResult();
// Simple translation transformation
OnXform xform = new OnXform();
xform.Translation(18, -18, -25);
MRhinoObjRef objref = go.Object(0);
context.m_doc.TransformObject(ref objref, xform);
context.m_doc.Redraw();
return IRhinoCommand.result.success;
}
Method 2 - The Long Way
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
{
MRhinoGetObject go = new MRhinoGetObject();
go.SetCommandPrompt("Select brep");
go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object
| IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object);
go.GetObjects(1, 1);
if(go.CommandResult() != IRhinoCommand.result.success)
return go.CommandResult();
MRhinoObjRef objref = go.Object(0);
IRhinoObject obj = objref.Object();
if(obj == null)
return IRhinoCommand.result.failure;
IOnBrep brep = objref.Brep();
if(brep == null)
return IRhinoCommand.result.failure;
OnBrep dupe = new OnBrep(brep);
// Simple translation transformation
OnXform xform = new OnXform();
xform.Translation(18, -18, -25);
if(!dupe.Transform(xform))
{
RhUtil.RhinoApp().Print("Unable to transform object.\n");
return IRhinoCommand.result.failure;
}
IOn3dmObjectAttributes attribs = obj.Attributes();
context.m_doc.AddBrepObject(dupe, attribs);
// Delete the selected object
context.m_doc.DeleteObject(objref);
context.m_doc.Redraw();
return IRhinoCommand.result.success;
}