private static Reinforcement[] CreateReinfObjs(RhinoDoc doc, ObjRef[] objects, int layerIndex, string mName, double diam) { List <Reinforcement> reinfList = new List <Reinforcement>(); foreach (ObjRef obj in objects) { if (obj.Point() == null) { continue; //Checks that object is a point } Point3d point = obj.Point().Location; Reinforcement reinf = new Reinforcement(ProjectPlugIn.Instance.CurrentBeam) { Material = new SteelMaterial(mName, SteelType.Reinforcement, ProjectPlugIn.Instance.CurrentBeam), Centroid = point, Diameter = diam }; reinfList.Add(reinf); ObjectAttributes attr = new ObjectAttributes(); attr.UserData.Add(reinf); attr.SetUserString("Name", "Reinforcement"); attr.SetUserString("infType", "Reinforcement"); attr.LayerIndex = layerIndex; doc.Objects.ModifyAttributes(obj, attr, true); } return(reinfList.ToArray()); }
//This method saves the useraddributes into the outlineCurve private static GeometryLarge DrawAndSaveUserAttr(Brep brep, RhinoDoc doc, MaterialType mType, string mName) { ObjectAttributes attr = new ObjectAttributes(); attr.SetUserString("Name", Enum.GetName(typeof(MaterialType), mType)); List <Layer> layers = (from layer in doc.Layers where layer.Name == Enum.GetName(typeof(MaterialType), mType) select layer).ToList <Rhino.DocObjects.Layer>(); if (layers.Count == 0 || (layers.Count == 1 && layers[0].IsDeleted)) { attr.LayerIndex = createLayer(doc, mType); } else if (layers.Count == 1) { attr.LayerIndex = layers[0].LayerIndex; //layers[0].IsLocked = true; layers[0].CommitChanges(); } else { RhinoApp.WriteLine("More than one layer with name Concrete excists. Remove one of them."); return(null); } GeometryLarge seg = new GeometryLarge(mType, mName, brep); attr.UserData.Add(seg); doc.Objects.AddBrep(brep, attr); return(seg); }
private void Bake(List <SmSatellite> sats) { Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects; // Bake Earth double scale = SpaceMonkeyCoreViewModel.Instance.ScaleFactor; Sphere earth = new Sphere(new Point3d(0, 0, 0), 6378.137 * scale); ot.AddSphere(earth); foreach (SmSatellite s in sats) { Point3d pt = SatToPoint(s); ObjectAttributes attr = new ObjectAttributes(); attr.SetUserString(nameof(SmSatellite.SatId), s.SatId.ToString()); attr.SetUserString(nameof(SmSatellite.SatName), s.SatName); attr.SetUserString(nameof(SmSatellite.IntDesignator), s.IntDesignator); attr.SetUserString(nameof(SmSatellite.LaunchDate), s.LaunchDate); attr.SetUserString(nameof(SmSatellite.SatLat), s.SatLat.ToString()); attr.SetUserString(nameof(SmSatellite.SatLng), s.SatLng.ToString()); attr.SetUserString(nameof(SmSatellite.SatAlt), s.SatAlt.ToString()); ot.AddPoint(pt, attr); } foreach (var view in Rhino.RhinoDoc.ActiveDoc.Views) { view.Redraw(); } }
//This method saves the useraddributes into the outlineCurve private static GeometryLarge DrawAndSaveUserAttr(Brep brep, List <Curve> baseCurves, RhinoDoc doc, MaterialType mType, string mName) { ObjectAttributes attr = new ObjectAttributes(); attr.SetUserString("Name", Enum.GetName(typeof(MaterialType), mType)); attr.SetUserString("infType", "GeometryLarge"); GetLayerIndex(mType, ref attr); GeometryLarge seg = new GeometryLarge(mType, mName, brep, ProjectPlugIn.Instance.CurrentBeam) { BaseCurves = baseCurves }; attr.UserData.Add(seg); Guid guid = doc.Objects.AddBrep(brep); doc.Objects.ModifyAttributes(guid, attr, true); //doc.Objects.AddBrep(brep, attr); return(seg); }
private void BakeLine() { RhinoDoc activeDoc = RhinoDoc.ActiveDoc; var parentLayerNames = new[] { "Column", "Girder", "Post", "Beam", "Brace", "Slab", "Wall" }; Color[] layerColors = { Color.Red, Color.Green, Color.Aquamarine, Color.LightCoral, Color.MediumPurple, Color.DarkGray, Color.CornflowerBlue }; GeometryBaker.MakeParentLayers(activeDoc, parentLayerNames, layerColors); Dictionary <string, string>[][] infoArray = Utils.TagUtils.GetAllSectionInfoArray(_stBridge.StbModel.StbMembers, _stBridge.StbModel.StbSections); foreach ((GH_Structure <GH_Line> lines, int i) in _lineList.Select((frameBrep, index) => (frameBrep, index))) { Layer parentLayer = activeDoc.Layers.FindName(parentLayerNames[i]); int parentIndex = parentLayer.Index; Guid parentId = parentLayer.Id; foreach ((Line line, int bIndex) in lines.Select((geometry, bIndex) => (geometry.Value, bIndex))) { var objAttr = new ObjectAttributes(); if (i < 5) { Dictionary <string, string>[] infos = infoArray[i]; Dictionary <string, string> info = infos[bIndex]; foreach (KeyValuePair <string, string> pair in info) { objAttr.SetUserString(pair.Key, pair.Value); } var layer = new Layer { Name = info["name"], ParentLayerId = parentId, Color = layerColors[i] }; int layerIndex = activeDoc.Layers.Add(layer); if (layerIndex == -1) { layer = activeDoc.Layers.FindName(info["name"]); layerIndex = layer.Index; } objAttr.LayerIndex = layerIndex; } else { objAttr.LayerIndex = parentIndex; } activeDoc.Objects.AddLine(line, objAttr); } } }
//this method draws the curves and saves the useraddributes into them private void DrawAndSaveUserAttr(List <Brep> breps, RhinoDoc doc, RhinoObject obj) { //TODO not a fully correctly implemented geometry large initialization GeometryLarge seg = new GeometryLarge(MaterialType.Concrete, "C30/37", breps[0]); foreach (Brep brep in breps) { seg.GeometrySegments.Add(new GeometrySegment(brep, seg.Material)); } ObjectAttributes attr = new ObjectAttributes(); attr.SetUserString("Name", "Concrete"); List <Layer> layers = (from layer in doc.Layers where layer.Name == "Concrete" select layer).ToList <Rhino.DocObjects.Layer>();; if (layers.Count == 0 || (layers.Count == 1 && layers[0].IsDeleted)) { Color color = Color.FromArgb(170, 170, 170); doc.Layers.Add("Concrete", color); int index = doc.Layers.Find("Concrete", true); Layer layer = doc.Layers[index]; //layer.IsLocked = true; attr.LayerIndex = index; layer.CommitChanges(); } else if (layers.Count == 1) { attr.LayerIndex = layers[0].LayerIndex; //layers[0].IsLocked = true; layers[0].CommitChanges(); } else { RhinoApp.WriteLine("More than one layer with name Concrete excists. Remove one of them."); return; } attr.UserData.Add(seg); doc.Objects.ModifyAttributes(obj, attr, 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) { string dir = ""; DA.GetData("directoryname", ref dir); string bname = ""; DA.GetData("beamfilename", ref bname); string cname = ""; DA.GetData("columnfilename", ref cname); string seclistname = ""; DA.GetData("sectionlistname", ref seclistname); if (seclistname == "none" | seclistname == "None") { seclistname = ""; } var secuserstring = "断面"; DA.GetData("userstring(sec)", ref secuserstring); var secname = new List <string>(); int nsec = 0; var sec_No = new List <int>(); var layerlist = new List <string>(); var layerindex = new List <int>(); var read_or_write = 0;//0ならsectionlistを新たに作る,1なら既存のリストを使う var linetexts = new List <string>(); var userstrings = new List <string>(); var uservalues = new List <List <string> >(); if (dir == "default") { dir = Directory.GetCurrentDirectory(); } var doc = RhinoDoc.ActiveDoc; var objs = new List <Guid>(); var lines = new List <Line>(); var xyz = new List <Point3d>(); StreamWriter w = new StreamWriter(@dir + "/temp", false); StreamReader r; if (seclistname != "") { if (File.Exists(@dir + "/" + seclistname)) { read_or_write = 1; } else { w.Close(); w = new StreamWriter(@dir + "/" + seclistname, false); } } if (seclistname != "" && read_or_write == 0) { w.WriteLine("No.,TYPE,P1,P2,P3,P4"); } else if (seclistname != "" && read_or_write == 1) { r = new StreamReader(@dir + "/" + seclistname); int k = 0; while (!r.EndOfStream) { string line = r.ReadLine(); linetexts.Add(line); // CSVファイルの一行を読み込む string[] values = line.Split(','); // 読み込んだ一行をカンマ毎に分けて配列に格納する if (k != 0) { var type = values[1]; var p1 = values[2].ToString(); var p2 = values[3].ToString(); var p3 = values[4].ToString(); var p4 = values[5].ToString(); string sec = type + "-" + p1 + "x" + p2 + "x" + p3 + "x" + p4; secname.Add(sec); nsec += 1; } k += 1; } r.Close(); w.Close(); w = new StreamWriter(@dir + "/" + seclistname, true); //追記用 } int check = 0; //最初の追加かどうかのflag(追記するsection.csvの一番最初に改行を入れるため) if (bname != "") //0:Level,1:Family_Name,2:FamilyType_Name,3:Start_PointX,4:Start_PointY,5:Start_PointZ,6:End_PointX,7:End_PointY,8:End_PointZ,9:bf,10:d,11:kr,12:tf,13:tw,14:mat,15:angle,16:joint,17:Lby,18:Lbz { var filename = dir + "/" + bname; StreamReader sr = new StreamReader(@filename);// 読み込みたいCSVファイルのパスを指定して開く, System.Text.Encoding.GetEncoding("shift_jis") int k = 0; while (!sr.EndOfStream) { string line = sr.ReadLine(); // CSVファイルの一行を読み込む string[] values = line.Split(','); // 読み込んだ一行をカンマ毎に分けて配列に格納する if (k != 0) { var r1 = new Point3d(double.Parse(values[3]) / 1000.0, double.Parse(values[4]) / 1000.0, double.Parse(values[5]) / 1000.0); var r2 = new Point3d(double.Parse(values[6]) / 1000.0, double.Parse(values[7]) / 1000.0, double.Parse(values[8]) / 1000.0); lines.Add(new Line(r1, r2)); if (values[1].Contains("角形") == true) { var s1 = (double.Parse(values[9]) / 1000.0).ToString(); var s2 = (double.Parse(values[10]) / 1000.0).ToString(); var s3 = (double.Parse(values[11]) / 1000.0).ToString(); var s4 = (double.Parse(values[12]) / 1000.0).ToString(); string sec = "□-" + s1 + "x" + s2 + "x" + s3 + "x" + s4; if (secname.Contains(sec) == false) { secname.Add(sec); if (read_or_write == 1 && check == 0) { w.WriteLine(""); check += 1; } if (seclistname != "") { var text = nsec.ToString() + ",□," + s1 + "," + s2 + "," + s3 + "," + s4; w.WriteLine(text); linetexts.Add(text); } nsec += 1; } sec_No.Add(secname.IndexOf(sec)); } else if (values[1].Contains("H") == true) { var s1 = (double.Parse(values[9]) / 1000.0).ToString(); var s2 = (double.Parse(values[10]) / 1000.0).ToString(); var s3 = (double.Parse(values[11]) / 1000.0).ToString(); var s4 = (double.Parse(values[12]) / 1000.0).ToString(); var sec = "H-" + s1 + "x" + s2 + "x" + s3 + "x" + s4; if (secname.Contains(sec) == false) { secname.Add(sec); if (read_or_write == 1 && check == 0) { w.WriteLine(""); check += 1; } if (seclistname != "") { var text = nsec.ToString() + ",H," + s1 + "," + s2 + "," + s3 + "," + s4; w.WriteLine(text); linetexts.Add(text); } nsec += 1; } sec_No.Add(secname.IndexOf(sec)); } if (layerlist.Contains(values[0]) == false) { layerlist.Add(values[0]); } layerindex.Add(layerlist.IndexOf(values[0])); var uservalue = new List <string>(); for (int i = 13; i < values.Length; i++) { if (i == 17 || i == 18) { uservalue.Add((double.Parse(values[i]) / 1000.0).ToString()); } else { uservalue.Add(values[i]); } } uservalues.Add(uservalue); } else { if (values.Length >= 14) { for (int i = 13; i < values.Length; i++) { userstrings.Add(values[i]); } } } k += 1; } } if (cname != "") { var filename = dir + "/" + cname; StreamReader sr = new StreamReader(@filename);// 読み込みたいCSVファイルのパスを指定して開く, System.Text.Encoding.GetEncoding("shift_jis") int k = 0; while (!sr.EndOfStream) { string line = sr.ReadLine(); // CSVファイルの一行を読み込む string[] values = line.Split(','); // 読み込んだ一行をカンマ毎に分けて配列に格納する if (k != 0) { var r1 = new Point3d(double.Parse(values[3]) / 1000.0, double.Parse(values[4]) / 1000.0, double.Parse(values[5]) / 1000.0); var r2 = new Point3d(double.Parse(values[6]) / 1000.0, double.Parse(values[7]) / 1000.0, double.Parse(values[8]) / 1000.0); lines.Add(new Line(r1, r2)); if (values[1].Contains("角形") == true) { var s1 = (double.Parse(values[9]) / 1000.0).ToString(); var s2 = (double.Parse(values[10]) / 1000.0).ToString(); var s3 = (double.Parse(values[11]) / 1000.0).ToString(); var s4 = (double.Parse(values[12]) / 1000.0).ToString(); string sec = "□-" + s1 + "x" + s2 + "x" + s3 + "x" + s4; if (secname.Contains(sec) == false) { secname.Add(sec); if (read_or_write == 1 && check == 0) { w.WriteLine(""); check += 1; } if (seclistname != "") { var text = nsec.ToString() + ",□," + s1 + "," + s2 + "," + s3 + "," + s4; w.WriteLine(text); linetexts.Add(text); } nsec += 1; } sec_No.Add(secname.IndexOf(sec)); } else if (values[1].Contains("H") == true) { var s1 = (double.Parse(values[9]) / 1000.0).ToString(); var s2 = (double.Parse(values[10]) / 1000.0).ToString(); var s3 = (double.Parse(values[11]) / 1000.0).ToString(); var s4 = (double.Parse(values[12]) / 1000.0).ToString(); var sec = "H-" + s1 + "x" + s2 + "x" + s3 + "x" + s4; if (secname.Contains(sec) == false) { secname.Add(sec); if (read_or_write == 1 && check == 0) { w.WriteLine(""); check += 1; } if (seclistname != "") { var text = nsec.ToString() + ",H," + s1 + "," + s2 + "," + s3 + "," + s4; w.WriteLine(text); linetexts.Add(text); } nsec += 1; } sec_No.Add(secname.IndexOf(sec)); } if (layerlist.Contains(values[0]) == false) { layerlist.Add(values[0]); } layerindex.Add(layerlist.IndexOf(values[0])); var uservalue = new List <string>(); for (int i = 13; i < values.Length; i++) { if (i == 17 || i == 18) { uservalue.Add((double.Parse(values[i]) / 1000.0).ToString()); } else { uservalue.Add(values[i]); } } uservalues.Add(uservalue); } k += 1; } } w.Close(); //最後の改行を削除/////////////////////////////////////////////////////////////////////////////// w = new StreamWriter(@dir + "/" + seclistname, false); w.Write("No.,TYPE,P1,P2,P3,P4"); for (int i = 1; i < linetexts.Count; i++) { w.Write(Environment.NewLine + linetexts[i]); } w.Close(); ///////////////////////////////////////////////////////////////////////////////////////////////// DA.SetDataList("lines", lines); DA.SetDataList("layers", layerlist); if (on_off == 1) { for (int i = 0; i < layerlist.Count; i++) { doc.Layers.Add(layerlist[i], Color.Black); } //レイヤ生成 for (int e = 0; e < lines.Count; e++) //節点生成 { var r1 = lines[e].From; var r2 = lines[e].To; var l1 = 10.0; var l2 = 10.0; for (int i = 0; i < xyz.Count; i++) { l1 = Math.Min(l1, (xyz[i] - r1).Length); } if (l1 > 5e-3) { xyz.Add(r1); } for (int i = 0; i < xyz.Count; i++) { l2 = Math.Min(l2, (xyz[i] - r2).Length); } if (l2 > 5e-3) { xyz.Add(r2); } } for (int e = 0; e < lines.Count; e++)//交差判定を行い交差部で要素分割する { var r1 = lines[e].From; var r2 = lines[e].To; var l0 = r2 - r1; var rc = new List <Point3d>(); var sec = sec_No[e]; var att = new ObjectAttributes(); att.SetUserString(secuserstring, sec.ToString()); for (int i = 0; i < userstrings.Count; i++) { if (uservalues[e][i] != "" && uservalues[e][i] != "rigid") { att.SetUserString(userstrings[i], uservalues[e][i]); } } att.LayerIndex = layerindex[e] + 1; for (int i = 0; i < xyz.Count; i++) { var l1 = xyz[i] - r1; if (l1.Length > 5e-3 && (r2 - xyz[i]).Length > 5e-3)//線分上に節点がいるかどうかチェック { if ((l0 / l0.Length - l1 / l1.Length).Length < 1e-5 && l0.Length - l1.Length > 5e-3) { rc.Add(xyz[i]); } } } if (rc.Count != 0) { var llist = new List <double>(); for (int i = 0; i < rc.Count; i++) { llist.Add((rc[i] - r1).Length); } int[] idx = Enumerable.Range(0, rc.Count).ToArray <int>();//r1とr2の間の点のソート Array.Sort <int>(idx, (a, b) => llist[a].CompareTo(llist[b])); var obj = doc.Objects.AddLine(r1, rc[idx[0]], att); for (int i = 0; i < idx.Length - 1; i++) { obj = doc.Objects.AddLine(rc[idx[i]], rc[idx[i + 1]], att); } obj = doc.Objects.AddLine(rc[idx[idx.Length - 1]], r2, att); } else { var obj = doc.Objects.AddLine(r1, r2, att); } } } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Point; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Pick all the points that you want to change to reinforcement."); go.GeometryFilter = geometryFilter; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (;;) { Rhino.Input.GetResult res = go.GetMultiple(1, 0); /* * if (res == Rhino.Input.GetResult.Option) * { * go.EnablePreSelect(false, true); * continue; * } * else if (res != Rhino.Input.GetResult.Option) * { * return Rhino.Commands.Result.Cancel; * } */ if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } List <Point3d> points = new List <Point3d>(); if (bHavePreselectedObjects) { for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } int layerIndex = getLayerIndex(doc, "Reinforcement"); doc.Layers[layerIndex].Color = Color.Black; if (layerIndex == 999) { return(Result.Failure); } ObjRef[] objects = go.Objects(); foreach (ObjRef obj in objects) { Point3d point = obj.Point().Location; //TODO add the functionality how to assign different steel materials. Reinforcement reinf = new Reinforcement(ProjectPlugIn.Instance.CurrentBeam) { Material = new SteelMaterial("B500B", SteelType.Reinforcement, ProjectPlugIn.Instance.CurrentBeam), Centroid = point, Diameter = 8 }; ObjectAttributes attr = new ObjectAttributes(); attr.UserData.Add(reinf); attr.SetUserString("Name", "Reinforcement"); attr.LayerIndex = layerIndex; //Unused code to create a hatch around the point /* * doc.Objects.AddCurve(reinf.OutLine,attr); * ObjectAttributes attrHatch = new ObjectAttributes(); * attrHatch.LayerIndex = layerIndex; * doc.Objects.AddHatch(reinf.Hatch, attrHatch); */ doc.Objects.ModifyAttributes(obj, attr, true); } return(Result.Success); }