McNeel Wiki
How To: Copy a CRhinoObject Object
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
DeveloperC++, .NET
SummaryDemonstrates how to make a copy of a CRhinoObject-derived object.

Question

I want to take a constant CRhinoObject, make a copy of it, and add the copy to the document. What is the correct way to do this?

C++

  const CRhinoObject* object = ..... // some object
  CRhinoObject* duplicate = object->Duplicate();
  if( duplicate )
  {
    if( context.m_doc.AddObject(duplicate) )
      context.m_doc.Redraw;
    else
      delete duplicate;
  }

VB.NET (Rhino 4)

  Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext)_
    As IRhinoCommand.result


    Dim go As New MRhinoGetObject()
    go.GetObjects(1, 1)


    If (go.CommandResult() <> IRhinoCommand.result.success) Then Return go.CommandResult()


    Dim objref As MRhinoObjRef = go.Object(0)
    Dim base_object As IRhinoObject = objref.Object()
    Dim duplicate As MRhinoObject = base_object.DuplicateRhinoObject()
    If (duplicate IsNot Nothing) Then
      If (context.m_doc.AddObject(duplicate)) Then
        context.m_doc.Redraw()
      End If
    End If
  End Function

C# (Rhino 4)

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    MRhinoGetObject go = new MRhinoGetObject();
    go.GetObjects(1, 1);
    if(go.CommandResult() != IRhinoCommand.result.success)
      return go.CommandResult();


    MRhinoObjRef objref = go.Object(0);
    IRhinoObject base_object = objref.Object();
    MRhinoObject duplicate = base_object.DuplicateRhinoObject();
    if(duplicate != null)
    {
      if(context.m_doc.AddObject(duplicate))
        context.m_doc.Redraw();
    }
    return IRhinoCommand.result.success;
  }
rename · changes · history · subscriptions · lost and found · references · file upload