RhinoDocBeforeTransformObjects Event |
Called before objects are being transformed
Namespace:
Rhino
Assembly:
RhinoCommon (in RhinoCommon.dll)
Since: 5.10
Syntax Examples using Rhino;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Commands;
using Rhino.Input.Custom;
using Rhino.Display;
namespace examples_cs
{
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()
{
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");
gp.Get();
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);
gt.AddTransformObjects(list);
gt.GetXform();
if (gt.CommandResult() != Result.Success)
return gt.CommandResult();
var xform = gt.CalculateTransform(gt.View().ActiveViewport, gt.Point());
TransformObjects(list, xform, false, false);
doc.Views.Redraw();
return Result.Success;
}
}
}
Imports Rhino
Imports Rhino.DocObjects
Imports Rhino.Geometry
Imports Rhino.Commands
Imports Rhino.Input.Custom
Imports Rhino.Display
Namespace examples_vb
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()
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
Get
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")
gp.[Get]()
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)
gt.AddTransformObjects(list)
gt.GetXform()
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)
doc.Views.Redraw()
Return Result.Success
End Function
End Class
End Namespace
See Also