GH - Set Plane to View

Hi all, does anyone was able to set the plane of a view withing GH. I tried with a basic definition in Python, it works but it freezes grasshopper once completed. I attached the definition, thanks in advance.

import rhinoscriptsyntax as rs

if x :
sc.doc = rc.RhinoDoc.ActiveDoc
rs.CurrentView
rs.Command(“_cplane view”)
sc.doc = ghdoc

#Python
import Rhino
if (reset):
    vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport
    origin = vp.CameraTarget
    xDir = vp.CameraX
    yDir = vp.CameraY
    pl = Rhino.Geometry.Plane(origin, xDir, yDir)
    vp.SetConstructionPlane(pl)
//CS
private void RunScript(bool reset, ref object A)
{
  if (!reset) return;
  var vp = RhinoDocument.Views.ActiveView.ActiveViewport;
  var origin = vp.CameraTarget;
  var xDir = vp.CameraX;
  var yDir = vp.CameraY;
  var pl = new Plane(origin, xDir, yDir);
  vp.SetConstructionPlane(pl);
}

SetConstructPlane.gh (4.7 KB)

3 Likes

Thank you!

hi @Mahdiyar awesome! if Iam in a “Perspective View” after define a CPlane with SetConstructionPlane method, I’d like to save this view with a “name”, how can I do it?
Then I’d like to return to my initial plane settings of my “Perspective View”? Please, any help will be appreciated, thanks!
T.

#Python
import Rhino
if (reset):
    vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport
    origin = vp.CameraTarget
    xDir = vp.CameraX
    yDir = vp.CameraY
    initPl = vp.ConstructionPlane().Clone()
    pl = Rhino.Geometry.Plane(origin, xDir, yDir)
    vp.SetConstructionPlane(pl)
    Rhino.RhinoDoc.ActiveDoc.NamedViews.Add(name, vp.Id)
    vp.SetConstructionPlane(initPl)
//C#
private void RunScript(bool reset, string name, ref object A)
{
  if (!reset) return;
  var vp = RhinoDocument.Views.ActiveView.ActiveViewport;
  var origin = vp.CameraTarget;
  var xDir = vp.CameraX;
  var yDir = vp.CameraY;
  var initPl = vp.ConstructionPlane().Clone();
  var pl = new Plane(origin, xDir, yDir);
  vp.SetConstructionPlane(pl);
  RhinoDocument.NamedViews.Add(name, vp.Id);
  vp.SetConstructionPlane(initPl);
}

SetConstructPlane.gh (6.2 KB)

2 Likes