/// <summary> /// Sets the viewport in rhino /// </summary> /// <param name="view">the name of the view</param> /// <param name="displayType">the display type, wireframe, shaded etc</param> public static void setViewport(String view, String displayType) { //-------Set viewport to specific view and maximize it & set display type-------- Rhino.DocObjects.Tables.NamedViewTable nvt = Rhino.RhinoDoc.ActiveDoc.NamedViews; Rhino.DocObjects.Tables.ViewTable vt = Rhino.RhinoDoc.ActiveDoc.Views; Rhino.Display.RhinoView[] rvs = vt.GetViewList(true, false); List <Rhino.Display.RhinoView> st = rvs.ToList(); List <String> viewList = new List <String>(); int viewCount = 0; foreach (Rhino.Display.RhinoView v in st) { if (v.ActiveViewport.Name == view) { Rhino.Display.RhinoViewport rvp = rvs[viewCount].ActiveViewport; rvs[viewCount].Maximized = true; } viewCount++; } var type = Rhino.Display.DisplayModeDescription.FindByName(displayType); Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.DisplayMode = type; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { bool update = false; DA.GetData(0, ref update); //Extract Named viewports list Rhino.DocObjects.Tables.NamedViewTable nV = Rhino.RhinoDoc.ActiveDoc.NamedViews; // return if list is empty if (nV.Count == 0) { return; } DataTree <String> camData = new DataTree <String>(); //camData.AddRange( new string[]{"name", "lens", "P.X", "P.Y", "P.Z", "H", "P", "B"}, new GH_Path(0)); ViewportInfo vp; List <String> nVData; Vector3d dir, up; double H, P, B; for (int i = 0; i < nV.Count; i++) { nVData = new List <String>(); // name nVData.Add(nV[i].Name); vp = nV[i].Viewport; // lens nVData.Add(Math.Round(vp.Camera35mmLensLength, 1).ToString()); // P.X, P.Y, P.Z (in Cinema 4D Y is the up-axis, so X and Y coordinates are swapped) nVData.Add(Math.Round(vp.CameraLocation.X, 3).ToString()); nVData.Add(Math.Round(vp.CameraLocation.Z, 3).ToString()); nVData.Add(Math.Round(vp.CameraLocation.Y, 3).ToString()); dir = vp.CameraDirection; up = vp.CameraUp; // H (Heading) Vector3d flatDir = new Vector3d(dir.X, dir.Y, 0); H = Vector3d.VectorAngle(Vector3d.XAxis, flatDir, Plane.WorldXY); H = Math.Round((180 / Math.PI) * H - 90, 3); nVData.Add(Convert.ToString(H)); // P (Pitch) Vector3d invDir = new Vector3d(-dir.X, -dir.Y, -dir.Z); P = Vector3d.VectorAngle(invDir, Vector3d.ZAxis); P = Math.Round((180 / Math.PI) * P - 90, 3); nVData.Add(Convert.ToString(P)); // B (Bank) Vector3d flatRot = Vector3d.CrossProduct(Vector3d.ZAxis, dir); B = Vector3d.VectorAngle(up, flatRot); B = Math.Round((180 / Math.PI) * B - 90, 3); nVData.Add(Convert.ToString(B)); camData.AddRange(nVData, new GH_Path(i)); } // update if you add new named views to Rhino if (update) { ExpireSolution(true); } DA.SetDataTree(0, camData); }