public winModifyStairSolid(List <LayerObject> _layers, SolidStairObject _bso) { InitializeComponent(); this.DataContext = _bso; List <LayerObject> Layers = _layers; int i = 0; foreach (LayerObject layer in Layers) { if (layer.IsSelected) { break; } else { i++; } } CB_Layers.ItemsSource = Layers; CB_Layers.SelectedIndex = i; }
public void ModifySolidStair() { ObjectId entId = MyFunctions.SelectStair(); Matrix3d matDisplacement, matRotation; Solid3d stair3d; if (entId != ObjectId.Null) { // we have a valid id for a stair with attached properties using (Transaction tr = db.TransactionManager.StartTransaction()) { // getting stair geometry and parameters stair3d = tr.GetObject(entId, OpenMode.ForRead) as Solid3d; // getting stair position and rotation matDisplacement = MyFunctions.GetStairDisplacment(stair3d); matRotation = MyFunctions.GetStairRotation(stair3d); tr.Commit(); }; List <LayerObject> lstLayers = MyFunctions.GetLayerList(stair3d.LayerId); BaseStairObject bso = MyFunctions.GetStairPropertiesFromSolid(stair3d); Point3d pInsert = MyFunctions.GetStairInsertPoint(stair3d); Double angle = MyFunctions.GetStairRotationAngle(stair3d); SolidStairObject sso = new SolidStairObject { Id = bso.Id, Name = bso.Name, Steps = bso.Steps, Riser = bso.Riser, Tread = bso.Tread, Landing = bso.Landing, Width = bso.Width, Slope = bso.Slope, X = pInsert.X, Y = pInsert.Y, Elevation = pInsert.Z, Rotation = angle / Math.PI * 180 }; winModifyStairSolid win = new winModifyStairSolid(lstLayers, sso); Boolean rtn = Application.ShowModalWindow(win).Value; if (rtn == false) { return; } LayerObject selectedLayer = win.CB_Layers.SelectedItem as LayerObject; try { SolidStairObject retObjStair = new SolidStairObject { Id = ObjectId.Null, Name = win.TB_Name.Text, Steps = Convert.ToInt32(win.TB_Steps.Text), Tread = Convert.ToDouble(win.TB_Tread.Text), Riser = Convert.ToDouble(win.TB_Riser.Text), Landing = Convert.ToDouble(win.TB_Landing.Text), Width = Convert.ToDouble(win.TB_Width.Text), Slope = Convert.ToDouble(win.TB_Slope.Text), X = Convert.ToDouble(win.TB_X.Text), Y = Convert.ToDouble(win.TB_Y.Text), Elevation = Convert.ToDouble(win.TB_E.Text), Rotation = Convert.ToDouble(win.TB_R.Text) / 180 * Math.PI }; using (Transaction tr = db.TransactionManager.StartTransaction()) { try { stair3d = tr.GetObject(entId, OpenMode.ForWrite) as Solid3d; stair3d.RecordHistory = true; Polyline pline = MyFunctions.CreateStairPolyline(retObjStair.Steps, retObjStair.Riser, retObjStair.Tread, retObjStair.Landing, retObjStair.Slope); Polyline path = MyFunctions.CreateStairSweepPath(retObjStair.Width); stair3d.CreateSweptSolid(pline, path, MyFunctions.CreateSweepOptions(path).ToSweepOptions()); //update matrix Point3d pNewInsert = new Point3d(retObjStair.X, retObjStair.Y, retObjStair.Elevation); Vector3d disp = Point3d.Origin.GetVectorTo(pNewInsert); matDisplacement = Matrix3d.Displacement(disp); stair3d.TransformBy(matDisplacement); matRotation = Matrix3d.Rotation(retObjStair.Rotation, Vector3d.ZAxis, pNewInsert); stair3d.TransformBy(matRotation); retObjStair.Id = stair3d.Id; //update layer stair3d.LayerId = selectedLayer.Id; // set property data Boolean isCreated = MyFunctions.SetStairPropertiesToSolid(stair3d, retObjStair); } catch (System.Exception ex) { ed.WriteMessage(ex.ToString()); } tr.Commit(); } } catch { ed.WriteMessage("\n Something wrong"); } } ; }