Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:dotnetmovepointobjects [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Moving Point Objects =====
 +a non-uniform move sample is also available [[developer:​rhinocommonsamples:​dotnetmovepointobjectsnonuniform|here]]
 +===== C# =====
 +<code c#>
 +public class MovePointsCommand : Rhino.Commands.Command
 +{
 +  public override string EnglishName
 +  {
 +    get { return "​csMovePoints";​ }
 +  }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    ObjRef[] obj_refs;
 +    var rc = RhinoGet.GetMultipleObjects(
 +      "​Select points to move", false, ObjectType.Point,​ out obj_refs);
 +    if (rc != Result.Success || obj_refs == null)
 +      return rc;
 +
 +    var gp = new GetPoint();
 +    gp.SetCommandPrompt("​Point to move from"​);​
 +    gp.Get();
 +    if (gp.CommandResult() != Result.Success)
 +      return gp.CommandResult();​
 +    var start_point = gp.Point();
 +
 +    gp.SetCommandPrompt("​Point to move to");
 +    gp.SetBasePoint(start_point,​ false);
 +    gp.DrawLineFromPoint(start_point,​ true);
 +    gp.Get();
 +    if (gp.CommandResult() != Result.Success)
 +      return gp.CommandResult();​
 +    var end_point = gp.Point();
 +
 +    var xform = Transform.Translation(end_point - start_point);​
 +
 +    foreach (var obj_ref in obj_refs)
 +    {
 +      doc.Objects.Transform(obj_ref,​ xform, true);
 +    }
 +
 +    doc.Views.Redraw();​
 +    return Result.Success;​
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class MovePointsCommand
 +  Inherits Rhino.Commands.Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbMovePoints"​
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim obj_refs As ObjRef()
 +    Dim rc = RhinoGet.GetMultipleObjects(
 +      "​Select points to move", False, ObjectType.Point,​ obj_refs)
 +    If rc <> Result.Success OrElse obj_refs Is Nothing Then
 +      Return rc
 +    End If
 +
 +    Dim gp = New GetPoint()
 +    gp.SetCommandPrompt("​Point to move from")
 +    gp.[Get]()
 +    If gp.CommandResult() <> Result.Success Then
 +      Return gp.CommandResult()
 +    End If
 +    Dim start_point = gp.Point()
 +
 +    gp.SetCommandPrompt("​Point to move to")
 +    gp.SetBasePoint(start_point,​ False)
 +    gp.DrawLineFromPoint(start_point,​ True)
 +    gp.[Get]()
 +    If gp.CommandResult() <> Result.Success Then
 +      Return gp.CommandResult()
 +    End If
 +    Dim end_point = gp.Point()
 +
 +    Dim xform = Transform.Translation(end_point - start_point)
 +
 +    For Each obj_ref As ObjRef In obj_refs
 +      doc.Objects.Transform(obj_ref,​ xform, True)
 +    Next
 +
 +    doc.Views.Redraw()
 +    Return Result.Success
 +  End Function
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +from Rhino import *
 +from Rhino.DocObjects import *
 +from Rhino.Commands import *
 +from Rhino.Input import *
 +from Rhino.Input.Custom import *
 +from Rhino.Geometry import *
 +from scriptcontext import doc
 +
 +def RunCommand():​
 +  rc, obj_refs = RhinoGet.GetMultipleObjects(
 +    "​Select points to move", False, ObjectType.Point)
 +  if rc <> Result.Success or obj_refs == None:
 +    return rc
 +
 +  gp = GetPoint()
 +  gp.SetCommandPrompt("​Point to move from")
 +  gp.Get()
 +  if gp.CommandResult() <> Result.Success:​
 +    return gp.CommandResult()
 +  start_point = gp.Point()
 +
 +  gp.SetCommandPrompt("​Point to move to")
 +  gp.SetBasePoint(start_point,​ False)
 +  gp.DrawLineFromPoint(start_point,​ True)
 +  gp.Get()
 +  if gp.CommandResult() <> Result.Success:​
 +    return gp.CommandResult()
 +  end_point = gp.Point()
 +
 +  xform = Transform.Translation(end_point - start_point)
 +
 +  for obj_ref in obj_refs:
 +    doc.Objects.Transform(obj_ref,​ xform, True)
 +
 +  doc.Views.Redraw()
 +  return Result.Success
 +  ​
 +if __name__ == "​__main__":​
 +  RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/dotnetmovepointobjects.txt ยท Last modified: 2015/09/14 (external edit)