/// <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) { string ID = null; if (!DA.GetData(0, ref ID)) { return; } Guid gd = new Guid(ID); if (Rhino.RhinoDoc.ActiveDoc.Objects.Find(gd) is Rhino.DocObjects.TextObject) { Rhino.DocObjects.TextObject obj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(gd) as Rhino.DocObjects.TextObject; TextEntity tx = obj.TextGeometry; Plane pln = tx.Plane; string mm = obj.DisplayText; DA.SetData(0, mm); DA.SetData(1, pln); DA.SetData(2, tx.TextHeight); DA.SetDataList(3, tx.Explode()); } else if (Rhino.RhinoDoc.ActiveDoc.Objects.Find(gd) is Rhino.DocObjects.TextDotObject) { Rhino.DocObjects.TextDotObject obj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(gd) as Rhino.DocObjects.TextDotObject; TextDot td = (TextDot)obj.Geometry; DA.SetData(0, td.Text); DA.SetData(1, td.Point); } }
public static Rhino.Commands.Result EditText(Rhino.RhinoDoc doc) { Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select text", false, Rhino.DocObjects.ObjectType.Annotation, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.DocObjects.TextObject textobj = objref.Object() as Rhino.DocObjects.TextObject; if (textobj == null) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.TextEntity textentity = textobj.Geometry as Rhino.Geometry.TextEntity; if (textentity == null) { return(Rhino.Commands.Result.Failure); } string str = textentity.Text; rc = Rhino.Input.RhinoGet.GetString("New text", false, ref str); if (rc != Rhino.Commands.Result.Success) { return(rc); } textentity.Text = str; textobj.CommitChanges(); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
/// <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) { Point3d origin = Point3d.Unset; if (!DA.GetData(0, ref origin)) { origin = new Point3d(0, 0, 0); } List <Mesh> mshP = new List <Mesh>(); if (!DA.GetDataList(1, mshP)) { return; } DataExtractor de = null; if (!DA.GetData(2, ref de)) { return; } //double roh = 1.2041; //DA.GetData(3, ref roh); //double min = -1; //double max = 1; //DA.GetData(4, ref min); //DA.GetData(5, ref max); int colourSheme = 1; DA.GetData(3, ref colourSheme); double fontsize = 0.5; DA.GetData(4, ref fontsize); Point3d zrefp = new Point3d(); if (!DA.GetData(5, ref zrefp)) { return; } string face = "Baskerville"; bool bold = false; bool italics = true; List <Mesh> mshPOUT = new List <Mesh>(); Grasshopper.DataTree <double> Ptree = new Grasshopper.DataTree <double>(); int branch = 0; //vref and pdyn should be measured at the building height... //double[] vref = de.get_velocity(0, zrefp[1] - origin[1], zrefp[2] - origin[2]); //Vector3d vrefv = new Vector3d(vref[0], vref[1], vref[2]); //double vrefl = vrefv.Length; //double pref = de.get_pressure(0, zrefp[1] - origin[1], zrefp[2] - origin[2]); //double pdyn = 0.5 * roh * Math.Pow(vrefl, 2); foreach (Mesh msh in mshP) { double[] Press = new double[msh.Faces.Count]; Color[] Cols = new Color[msh.Vertices.Count]; Mesh mshcol = new Mesh(); List <Curve> lst = new List <Curve>(); for (int u = 0; u < msh.Faces.Count; u++) { //double[] vref = de.get_velocity(0 - origin[0], msh.Vertices[u].Y - origin[1], msh.Vertices[u].Z - origin[2]); //Vector3d vrefv = new Vector3d(vref[0], vref[1], vref[2]); //double vrefl = vrefv.Length; double pref = de.get_pressure(zrefp[0] - origin[0], zrefp[1] - origin[1], zrefp[2] - origin[2]); //double pdyn = 0.5 * roh * Math.Pow(vrefl, 2); //Press[u] = de.get_pressure(msh.Vertices[u].X - origin[0], msh.Vertices[u].Y - origin[1], msh.Vertices[u].Z - origin[2]); MeshFace mFace = msh.Faces[u]; Point3d pt1 = msh.Vertices[mFace.A]; Point3d pt2 = msh.Vertices[mFace.B]; Point3d pt3 = msh.Vertices[mFace.C]; Point3d pt4 = msh.Vertices[mFace.D]; NurbsSurface faceSrf = NurbsSurface.CreateFromCorners(pt1, pt2, pt3, pt4); Point3d faceCenter = AreaMassProperties.Compute(faceSrf).Centroid; double uCoord; double vCoord; faceSrf.ClosestPoint(faceCenter, out uCoord, out vCoord); Vector3d faceNormal = faceSrf.NormalAt(uCoord, vCoord); faceNormal.Unitize(); faceNormal *= 0.01; faceCenter += faceNormal; double pFace = de.get_pressure(faceCenter.X - origin[0], faceCenter.Y - origin[1], faceCenter.Z - origin[2]); Press[u] = pFace - pref; //double[] U = de.get_velocity(faceCenter.X - origin[0], faceCenter.Y - origin[1], faceCenter.Z - origin[2]); //Vector3d Uvec = new Vector3d(U[0], U[1], U[2]); //double velocity = Uvec.Length; //Press[u] = 0.5 * 1.225 * Math.Pow(velocity, 2); //Cp[u] = (px - pref) / pdyn; Ptree.Add(Press[u], new Grasshopper.Kernel.Data.GH_Path(branch)); //Cols[u] = Utilities.GetRGB(colourSheme, Cp[u], max, min); //Cols[u] = Utilities.GetAbsoluteRGB(colourSheme, Press[u]); //mshcol.Vertices.Add(msh.Vertices[u]); //mshcol.VertexColors.SetColor(u, Cols[u]); //string strval = Math.Round(Cp[u], 2).ToString(); string strval = Math.Round(Press[u], 2).ToString(); Point3d plp = new Point3d(faceCenter.X, faceCenter.Y, faceCenter.Z); Vector3d vec = new Vector3d(-1, 0, 0); Plane pl = new Plane(plp, vec); var te = Rhino.RhinoDoc.ActiveDoc.Objects.AddText(strval, pl, fontsize, face, bold, italics); Rhino.DocObjects.TextObject txt = Rhino.RhinoDoc.ActiveDoc.Objects.Find(te) as Rhino.DocObjects.TextObject; if (txt != null) { var tt = txt.Geometry as Rhino.Geometry.TextEntity; Curve[] A = tt.Explode(); foreach (Curve crv in A) { lst.Add(crv); } } Rhino.RhinoDoc.ActiveDoc.Objects.Delete(te, true); } branch++; for (int j = 0; j < msh.Faces.Count; j++) { mshcol.Faces.AddFace(msh.Faces[j].A, msh.Faces[j].B, msh.Faces[j].C, msh.Faces[j].D); } for (int i = 0; i < msh.Vertices.Count; i++) { double vertexPress = de.get_pressure(msh.Vertices[i].X - origin[0], msh.Vertices[i].Y - origin[1], msh.Vertices[i].Z - origin[2]); Cols[i] = Utilities.GetAbsoluteRGB(colourSheme, vertexPress); mshcol.Vertices.Add(msh.Vertices[i]); mshcol.VertexColors.SetColor(i, Cols[i]); } // output Pressure numbers as text into rhino viewport DA.SetDataList(1, lst); // output coloured meshes mshPOUT.Add(mshcol); } DA.SetDataTree(2, Ptree); DA.SetDataList(0, mshPOUT); //THIS IS FROM GIULIO PIACENTINO's page... txtlines component // private void RunScript(string face, bool bold, bool italics, double size, string content, Plane pl, ref object A) //{ // if(size == 0) // size = 1; // if(!string.IsNullOrEmpty(face) && size > 0 && !string.IsNullOrEmpty(content) && // pl.IsValid) // var te = RhinoDoc.ActiveDoc.Objects.AddText(content, pl, size, face, bold, italics); // Rhino.DocObjects.TextObject txt = RhinoDoc.ActiveDoc.Objects.Find(te) as Rhino.DocObjects.TextObject; // if(txt != null) // { // var tt = txt.Geometry as Rhino.Geometry.TextEntity; // A = tt.Explode(); // } // RhinoDoc.ActiveDoc.Objects.Delete(txt, true); // RhinoDoc.ActiveDoc.Objects.Delete(te, true); // } //} }
/// <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) { Point3d origin = Point3d.Unset; if (!DA.GetData(0, ref origin)) { origin = new Point3d(0, 0, 0); } List <Mesh> mshCp = new List <Mesh>(); if (!DA.GetDataList(1, mshCp)) { return; } DataExtractor de = null; if (!DA.GetData(2, ref de)) { return; } double roh = 1.2041; DA.GetData(3, ref roh); double min = -1; double max = 1; DA.GetData(4, ref min); DA.GetData(5, ref max); int colourSheme = 1; DA.GetData(6, ref colourSheme); double fontsize = 0.5; DA.GetData(7, ref fontsize); Point3d zrefp = new Point3d(); if (!DA.GetData(8, ref zrefp)) { return; } string face = "Baskerville"; bool bold = false; bool italics = true; List <Mesh> mshCpOUT = new List <Mesh>(); Grasshopper.DataTree <double> cptree = new Grasshopper.DataTree <double>(); int branch = 0; //vref and pdyn should be measured at the building height... double[] vref = de.get_velocity(0, zrefp[1] - origin[1], zrefp[2] - origin[2]); Vector3d vrefv = new Vector3d(vref[0], vref[1], vref[2]); double vrefl = vrefv.Length; double pref = de.get_pressure(0, zrefp[1] - origin[1], zrefp[2] - origin[2]); double pdyn = 0.5 * roh * Math.Pow(vrefl, 2); foreach (Mesh msh in mshCp) { double[] Cp = new double[msh.Vertices.Count]; Color[] Cols = new Color[msh.Vertices.Count]; Mesh mshcol = new Mesh(); List <Curve> lst = new List <Curve>(); for (int u = 0; u < msh.Vertices.Count; u++) { //double[] vref = de.get_velocity(0 - origin[0], msh.Vertices[u].Y - origin[1], msh.Vertices[u].Z - origin[2]); //Vector3d vrefv = new Vector3d(vref[0], vref[1], vref[2]); //double vrefl = vrefv.Length; //double pref = de.get_pressure(0 - origin[0], msh.Vertices[u].Y - origin[1], msh.Vertices[u].Z - origin[2]); //double pdyn = 0.5 * roh * Math.Pow(vrefl, 2); double px = de.get_pressure(msh.Vertices[u].X - origin[0], msh.Vertices[u].Y - origin[1], msh.Vertices[u].Z - origin[2]); Cp[u] = (px - pref) / pdyn; cptree.Add(Cp[u], new Grasshopper.Kernel.Data.GH_Path(branch)); Cols[u] = Utilities.GetRGB(colourSheme, Cp[u], max, min); mshcol.Vertices.Add(msh.Vertices[u]); mshcol.VertexColors.SetColor(u, Cols[u]); string strval = Math.Round(Cp[u], 2).ToString(); Point3d plp = new Point3d(msh.Vertices[u].X, msh.Vertices[u].Y, msh.Vertices[u].Z); Vector3d vec = new Vector3d(-1, 0, 0); Plane pl = new Plane(plp, vec); var te = Rhino.RhinoDoc.ActiveDoc.Objects.AddText(strval, pl, fontsize, face, bold, italics); Rhino.DocObjects.TextObject txt = Rhino.RhinoDoc.ActiveDoc.Objects.Find(te) as Rhino.DocObjects.TextObject; if (txt != null) { var tt = txt.Geometry as Rhino.Geometry.TextEntity; Curve[] A = tt.Explode(); foreach (Curve crv in A) { lst.Add(crv); } } Rhino.RhinoDoc.ActiveDoc.Objects.Delete(te, true); } branch++; for (int j = 0; j < msh.Faces.Count; j++) { mshcol.Faces.AddFace(msh.Faces[j].A, msh.Faces[j].B, msh.Faces[j].C, msh.Faces[j].D); } // output Cp numbers as text into rhino viewport DA.SetDataList(1, lst); // output coloured meshes mshCpOUT.Add(mshcol); } DA.SetDataTree(2, cptree); DA.SetDataList(0, mshCpOUT); //THIS IS FROM GIULIO PIACENTINO's page... txtlines component // private void RunScript(string face, bool bold, bool italics, double size, string content, Plane pl, ref object A) //{ // if(size == 0) // size = 1; // if(!string.IsNullOrEmpty(face) && size > 0 && !string.IsNullOrEmpty(content) && // pl.IsValid) // var te = RhinoDoc.ActiveDoc.Objects.AddText(content, pl, size, face, bold, italics); // Rhino.DocObjects.TextObject txt = RhinoDoc.ActiveDoc.Objects.Find(te) as Rhino.DocObjects.TextObject; // if(txt != null) // { // var tt = txt.Geometry as Rhino.Geometry.TextEntity; // A = tt.Explode(); // } // RhinoDoc.ActiveDoc.Objects.Delete(txt, true); // RhinoDoc.ActiveDoc.Objects.Delete(te, true); // } //} }
public static string makeDocBox() { try { //If docBox has not been created, create it and place it on its natalus layer. /* Abandoning layer idea for now. Not working as intended. * Rhino.DocObjects.Layer layer_D10 = new Rhino.DocObjects.Layer(); * int layer_D10_index = -1; * * if (RhinoDoc.ActiveDoc.Layers.FindName("D10").Index < 0) * { * RhinoDoc.ActiveDoc.Layers.Add(layer_D10); * layer_D10_index = layer_D10.Index; * } * else * { * layer_D10 = RhinoDoc.ActiveDoc.Layers.FindName("D10"); * layer_D10_index = layer_D10.Index; * } */ //Set initial dimensions and record to D01 if D01 does not exist. string D01_Path = utils.file_structure.getPathFor("D01"); string D20_Path = utils.file_structure.getPathFor("D20"); double docBox_width = 12; double docBox_height = 12; Rhino.Geometry.Point3d refPoint = new Rhino.Geometry.Point3d(0, 0, 0); //Check if previous dim configuration existed. if (System.IO.File.Exists(D01_Path) == true) { string[] dims = System.IO.File.ReadAllText(D01_Path).Split('|'); docBox_width = Convert.ToDouble(dims[0]); docBox_height = Convert.ToDouble(dims[1]); } else { System.IO.File.WriteAllText(D01_Path, "12|12"); } double adjust = 0; if (System.IO.File.Exists(D20_Path) == true) { string[] coords = System.IO.File.ReadAllText(D20_Path).Split(','); refPoint.X = Convert.ToDouble(coords[0]); refPoint.Y = Convert.ToDouble(coords[1]); adjust = docBox_height; } else if (System.IO.File.Exists(D20_Path) == false) { adjust = 0; } Rhino.Geometry.Plane docBox_plane = Rhino.Geometry.Plane.WorldXY; docBox_plane.OriginX = refPoint.X; docBox_plane.OriginY = refPoint.Y - adjust; Rhino.Geometry.Rectangle3d docBox = new Rhino.Geometry.Rectangle3d(docBox_plane, docBox_width, docBox_height); Rhino.DocObjects.ObjectAttributes docBox_attributes = new Rhino.DocObjects.ObjectAttributes(); //Until layer process resolved, docBox to be on any layer. int activeIndex = RhinoDoc.ActiveDoc.Layers.CurrentLayerIndex; docBox_attributes.LayerIndex = activeIndex; //(Rhino 5) Convert docBox Rectangle3D to polyline curve. Rhino.Geometry.Polyline docBoxPolyline = docBox.ToPolyline(); //Freeze updating while docBox is created. string x10_path = utils.file_structure.getPathFor("x10"); System.IO.File.WriteAllText(x10_path, "false"); //Determine GUID and record to D10. Guid newGuid = RhinoDoc.ActiveDoc.Objects.AddPolyline(docBoxPolyline); Rhino.DocObjects.ObjRef docBoxObj = new Rhino.DocObjects.ObjRef(newGuid); Rhino.DocObjects.CurveObject docBoxCurve = docBoxObj.Object() as Rhino.DocObjects.CurveObject; string docBoxGUID = newGuid.ToString(); string D10_Path = utils.file_structure.getPathFor("D10"); if (System.IO.File.Exists(D10_Path) && System.IO.File.ReadAllText(D10_Path) != "") { string D11_Path = utils.file_structure.getPathFor("D11"); System.IO.File.WriteAllText(D11_Path, System.IO.File.ReadAllText(D10_Path)); } System.IO.File.WriteAllText(D10_Path, docBoxGUID); //Set curve to Illustrator orange. System.Drawing.Color docBoxColor = System.Drawing.Color.FromArgb(240, 120, 6); docBoxCurve.Attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject; docBoxCurve.Attributes.ObjectColor = docBoxColor; docBoxCurve.Attributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject; docBoxCurve.Attributes.PlotColor = docBoxColor; docBoxCurve.Attributes.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject; docBoxCurve.Attributes.PlotWeight = 1.5; docBoxCurve.CommitChanges(); //Label it! Rhino.Geometry.TextEntity label = new Rhino.Geometry.TextEntity(); label.TextHeight = .4; Rhino.Geometry.Plane label_plane = Rhino.Geometry.Plane.WorldXY; label_plane.OriginX = docBox_plane.OriginX; label_plane.OriginY = docBox_plane.OriginY - .4 - .1; label.Plane = label_plane; label.Text = ("Linked Illustrator Artboard"); Guid docBoxLabel = RhinoDoc.ActiveDoc.Objects.AddText(label); Rhino.DocObjects.ObjRef labelObj = new Rhino.DocObjects.ObjRef(docBoxLabel); Rhino.DocObjects.TextObject labelText = labelObj.Object() as Rhino.DocObjects.TextObject; labelText.Attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject; labelText.Attributes.ObjectColor = docBoxColor; labelText.Attributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject; labelText.Attributes.PlotColor = docBoxColor; labelText.CommitChanges(); string docBoxLabelGUID = docBoxLabel.ToString(); string D30_Path = utils.file_structure.getPathFor("D30"); if (System.IO.File.Exists(D30_Path) && System.IO.File.ReadAllText(D30_Path) != "") { string D31_Path = utils.file_structure.getPathFor("D31"); System.IO.File.WriteAllText(D31_Path, System.IO.File.ReadAllText(D30_Path)); } System.IO.File.WriteAllText(D30_Path, docBoxLabelGUID); //Unfreeze updating. System.IO.File.WriteAllText(x10_path, "true"); //Update illustrator boundaries. int conversion = utils.units.conversion(); string jsxPath = utils.file_structure.getJavascriptPath(); echo.interop echo = new echo.interop(); echo.docBounds(docBox_width, System.Math.Abs(docBox_height), conversion, jsxPath); return(docBoxGUID); } catch (Exception e) { debug.alert(e.Message + " | " + e.Source); return("error"); } }