Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:duplicateobject [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Clone (Copy, Duplicate) a Rhino Object =====
 +
 +===== C# =====
 +<code c#>
 +public class DuplicateObjectCommand : Command
 +{
 +  public override string EnglishName { get { return "​csDuplicateObject";​ } }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    ObjRef obj_ref;
 +    var rc = RhinoGet.GetOneObject(
 +      "​Select object to duplicate",​ false, ObjectType.AnyObject,​ out obj_ref);
 +    if (rc != Result.Success)
 +      return rc;
 +    var rhino_object = obj_ref.Object();​
 +
 +    var geometry_base = rhino_object.DuplicateGeometry();​
 +    if (geometry_base != null)
 +      if (doc.Objects.Add(geometry_base) != Guid.Empty)
 +        doc.Views.Redraw();​
 +
 +    return Result.Success;​
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class DuplicateObjectCommand
 +  Inherits Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbDuplicateObject"​
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim obj_ref As ObjRef = Nothing
 +
 +    Dim rc = RhinoGet.GetOneObject(
 +      "​Select object to duplicate",​ False, ObjectType.AnyObject,​ obj_ref)
 +    If rc <> Result.Success Then
 +      Return rc
 +    End If
 +    Dim rhino_object = obj_ref.[Object]()
 +
 +    Dim geometry_base = rhino_object.DuplicateGeometry()
 +    If geometry_base IsNot Nothing Then
 +      If doc.Objects.Add(geometry_base) <> Guid.Empty Then
 +        doc.Views.Redraw()
 +      End If
 +    End If
 +
 +    Return Result.Success
 +  End Function
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +from System import *
 +from Rhino import *
 +from Rhino.Commands import *
 +from Rhino.DocObjects import *
 +from Rhino.Input import *
 +from scriptcontext import doc
 +
 +def RunCommand():​
 +  ​
 +  rc, obj_ref = RhinoGet.GetOneObject(
 +    "​Select object to duplicate",​ False, ObjectType.AnyObject)
 +  if rc <> Result.Success:​
 +    return rc
 +  rhino_object = obj_ref.Object()
 +
 +  geometry_base = rhino_object.DuplicateGeometry()
 +  if geometry_base <> None:
 +    if doc.Objects.Add(geometry_base) <> Guid.Empty:
 +      doc.Views.Redraw()
 +
 +  return Result.Success
 +
 +if __name__ == "​__main__":​
 +  RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/duplicateobject.txt ยท Last modified: 2015/09/14 (external edit)