Site Tools

Sample: Showing Dynamic Object Transformations


public class GetTranslation : GetTransform
  public override Transform CalculateTransform(RhinoViewport viewport, Point3d point)
    var xform = Transform.Identity;
    Point3d base_point;
    if (TryGetBasePoint(out base_point))
      var v = point - base_point;
      if (!v.IsZero)
        xform = Transform.Translation(v);
        if (!xform.IsValid)
          xform = Transform.Identity;
    return xform;
public class RhinoGetTransformCommand : TransformCommand
  public RhinoGetTransformCommand()
    // simple example of handling the BeforeTransformObjects event
    RhinoDoc.BeforeTransformObjects += RhinoDocOnBeforeTransformObjects;
  private void RhinoDocOnBeforeTransformObjects(object sender, RhinoTransformObjectsEventArgs ea)
    RhinoApp.WriteLine("Transform Objects Count: {0}", ea.ObjectCount);
  public override string EnglishName { get { return "csGetTranslation"; } }
  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    var list = new Rhino.Collections.TransformObjectList();
    var rc = SelectObjects("Select objects to move", list);
    if (rc != Rhino.Commands.Result.Success)
      return rc;
    var gp = new GetPoint();
    gp.SetCommandPrompt("Point to move from");
    if (gp.CommandResult() != Result.Success)
      return gp.CommandResult();
    var gt = new GetTranslation();
    gt.SetCommandPrompt("Point to move to");
    gt.SetBasePoint(gp.Point(), true);
    gt.DrawLineFromPoint(gp.Point(), true);
    if (gt.CommandResult() != Result.Success)
      return gt.CommandResult();
    var xform = gt.CalculateTransform(gt.View().ActiveViewport, gt.Point());
    TransformObjects(list, xform, false, false);
    return Result.Success;


Public Class GetTranslation
  Inherits GetTransform
  Public Overrides Function CalculateTransform(viewport As RhinoViewport, point As Point3d) As Transform
    Dim xform = Transform.Identity
    Dim base_point As Point3d
    If TryGetBasePoint(base_point) Then
      Dim v = point - base_point
      If Not v.IsZero Then
        xform = Transform.Translation(v)
        If Not xform.IsValid Then
          xform = Transform.Identity
        End If
      End If
    End If
    Return xform
  End Function
End Class
Public Class RhinoGetTransformCommand
  Inherits TransformCommand
  Public Sub New()
    ' simple example of handling the BeforeTransformObjects event
    AddHandler RhinoDoc.BeforeTransformObjects, AddressOf RhinoDocOnBeforeTransformObjects
  End Sub
  Private Sub RhinoDocOnBeforeTransformObjects(sender As Object, ea As RhinoTransformObjectsEventArgs)
    RhinoApp.WriteLine("Transform Objects Count: {0}", ea.ObjectCount)
  End Sub
  Public Overrides ReadOnly Property EnglishName() As String
      Return "vbGetTranslation"
    End Get
  End Property
  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
    Dim list = New Rhino.Collections.TransformObjectList()
    Dim rc = SelectObjects("Select objects to move", list)
    If rc <> Rhino.Commands.Result.Success Then
      Return rc
    End If
    Dim gp = New GetPoint()
    gp.SetCommandPrompt("Point to move from")
    If gp.CommandResult() <> Result.Success Then
      Return gp.CommandResult()
    End If
    Dim gt = New GetTranslation()
    gt.SetCommandPrompt("Point to move to")
    gt.SetBasePoint(gp.Point(), True)
    gt.DrawLineFromPoint(gp.Point(), True)
    If gt.CommandResult() <> Result.Success Then
      Return gt.CommandResult()
    End If
    Dim xform = gt.CalculateTransform(gt.View().ActiveViewport, gt.Point())
    TransformObjects(list, xform, False, False)
    Return Result.Success
  End Function
End Class
d Namespace
developer/rhinocommonsamples/rhinogettransform.txt ยท Last modified: 2014/08/29 by