Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:addnamedview [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Add Named View =====
 +
 +===== C# =====
 +<code c#>
 +public static Rhino.Commands.Result AddNamedView(Rhino.RhinoDoc doc)
 +{
 +  Rhino.Display.RhinoView view;
 +  Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetView("​Select view to adjust",​ out view);
 +  if (rc != Rhino.Commands.Result.Success)
 +    return rc;
 +
 +  Rhino.Geometry.Point3d location;
 +  rc = Rhino.Input.RhinoGet.GetPoint("​Camera Location",​ false, out location);
 +  if (rc != Rhino.Commands.Result.Success)
 +    return rc;
 +
 +  Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();​
 +  gp.SetCommandPrompt("​Look At Location"​);​
 +  gp.DrawLineFromPoint(location,​ false);
 +  gp.Get();
 +  if (gp.CommandResult() != Rhino.Commands.Result.Success)
 +    return gp.CommandResult();​
 +  Rhino.Geometry.Point3d lookat = gp.Point();
 +  ​
 +  string name = view.ActiveViewport.Name;​
 +  rc = Rhino.Input.RhinoGet.GetString("​Name",​ true, ref name);
 +  if (rc != Rhino.Commands.Result.Success)
 +    return rc;
 +
 +  Rhino.Display.RhinoViewport vp = view.ActiveViewport;​
 +  // save the current viewport projection
 +  vp.PushViewProjection();​
 +  vp.CameraUp = Rhino.Geometry.Vector3d.ZAxis;​
 +  vp.SetCameraLocation(location,​ false);
 +  vp.SetCameraDirection(lookat - location, true);
 +  vp.Name = name;
 +
 +  doc.NamedViews.Add(name,​ vp.Id);
 +  view.Redraw();​
 +  return Rhino.Commands.Result.Success;​
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Shared Function AddNamedView(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result
 +  Dim view As Rhino.Display.RhinoView = Nothing
 +  Dim rc As Rhino.Commands.Result = Rhino.Input.RhinoGet.GetView("​Select view to adjust",​ view)
 +  If rc <> Rhino.Commands.Result.Success Then
 +    Return rc
 +  End If
 +
 +  Dim location As Rhino.Geometry.Point3d
 +  rc = Rhino.Input.RhinoGet.GetPoint("​Camera Location",​ False, location)
 +  If rc <> Rhino.Commands.Result.Success Then
 +    Return rc
 +  End If
 +
 +  Dim gp As New Rhino.Input.Custom.GetPoint()
 +  gp.SetCommandPrompt("​Look At Location"​)
 +  gp.DrawLineFromPoint(location,​ False)
 +  gp.Get()
 +  If gp.CommandResult() <> Rhino.Commands.Result.Success Then
 +    Return gp.CommandResult()
 +  End If
 +  Dim lookat As Rhino.Geometry.Point3d = gp.Point()
 +
 +  Dim name As String = view.ActiveViewport.Name
 +  rc = Rhino.Input.RhinoGet.GetString("​Name",​ True, name)
 +  If rc <> Rhino.Commands.Result.Success Then
 +    Return rc
 +  End If
 +
 +  Dim vp As Rhino.Display.RhinoViewport = view.ActiveViewport
 +  ' save the current viewport projection
 +  vp.PushViewProjection()
 +  vp.CameraUp = Rhino.Geometry.Vector3d.ZAxis
 +  vp.SetCameraLocation(location,​ False)
 +  vp.SetCameraDirection(lookat - location, True)
 +  vp.Name = name
 +
 +  doc.NamedViews.Add(name,​ vp.Id)
 +  view.Redraw()
 +  Return Rhino.Commands.Result.Success
 +End Function
 +</​code>​
 +===== Python =====
 +<code python>
 +import Rhino
 +import scriptcontext
 +import System.Guid
 +
 +def AddNamedView():​
 +    rc, view = Rhino.Input.RhinoGet.GetView("​Select view to adjust"​)
 +    if rc!=Rhino.Commands.Result.Success:​ return rc
 +
 +    rc, location = Rhino.Input.RhinoGet.GetPoint("​Camera Location",​ False)
 +    if rc!=Rhino.Commands.Result.Success:​ return rc
 +    ​
 +    gp = Rhino.Input.Custom.GetPoint()
 +    gp.SetCommandPrompt("​Look At Location"​)
 +    gp.DrawLineFromPoint(location,​ False)
 +    gp.Get()
 +    if gp.CommandResult()!=Rhino.Commands.Result.Success:​
 +        return gp.CommandResult()
 +    lookat = gp.Point()
 +
 +    name = view.ActiveViewport.Name
 +    rc, name = Rhino.Input.RhinoGet.GetString("​Name",​ True, name)
 +    if rc!=Rhino.Commands.Result.Success:​ return rc
 +
 +    vp = view.ActiveViewport
 +    # save the current viewport projection
 +    vp.PushViewProjection()
 +    vp.CameraUp = Rhino.Geometry.Vector3d.ZAxis
 +    vp.SetCameraLocation(location,​ False)
 +    vp.SetCameraDirection(lookat - location, True)
 +    vp.Name = name
 +    ​
 +    scriptcontext.doc.NamedViews.Add(name,​ vp.Id)
 +    view.Redraw()
 +    return Rhino.Commands.Result.Success
 +
 +if __name__=="​__main__":​
 +    AddNamedView()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/addnamedview.txt ยท Last modified: 2015/09/14 (external edit)