コード例 #1
0
 public winCreateStair(List <LayerObject> _layers, BaseStairObject _bso)
 {
     InitializeComponent();
     // Layers = _layers;
     CB_Layers.ItemsSource = _layers;
     this.DataContext      = _bso;
 }
コード例 #2
0
ファイル: myFunctions.cs プロジェクト: AndreasLuka/ALC-C3D-LX
        public static BaseStairObject GetPropertySetDefinitionStairStandardValues()
        {
            PropertySetDefinition psd = new PropertySetDefinition();
            // ObjectId psdId = ObjectId.Null;

            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            BaseStairObject retBso = new BaseStairObject();

            using (Transaction tr = tm.StartTransaction())
            {
                try
                {
                    DictionaryPropertySetDefinitions psdDict = new DictionaryPropertySetDefinitions(db);
                    if (psdDict.Has(MyPlugin.psdName, tr))
                    {
                        // Get the ObjectID of the property set definition by name
                        // psdId = psdDict.GetAt(MyPlugin.psdName);
                        psd = (PropertySetDefinition)tr.GetObject(psdDict.GetAt(MyPlugin.psdName), OpenMode.ForRead);

                        // Get the standard value from the properties in the property set defenition
                        BaseStairObject bso = new BaseStairObject
                        {
                            Id      = ObjectId.Null,
                            Name    = Convert.ToString(psd.Definitions[psd.Definitions.IndexOf("name")].DefaultData),
                            Steps   = Convert.ToInt32(psd.Definitions[psd.Definitions.IndexOf("_steps")].DefaultData),
                            Tread   = Convert.ToDouble(psd.Definitions[psd.Definitions.IndexOf("_tread")].DefaultData),
                            Riser   = Convert.ToDouble(psd.Definitions[psd.Definitions.IndexOf("_riser")].DefaultData),
                            Landing = Convert.ToDouble(psd.Definitions[psd.Definitions.IndexOf("_landing")].DefaultData),
                            Width   = Convert.ToDouble(psd.Definitions[psd.Definitions.IndexOf("_width")].DefaultData),
                            Slope   = Convert.ToDouble(psd.Definitions[psd.Definitions.IndexOf("_slope")].DefaultData)
                        };
                        retBso = bso;
                    }
                    else
                    {
                        ed.WriteMessage("\n PropertySetDefinition {0} does not exist ", MyPlugin.psdName);
                    }
                }
                catch
                {
                    ed.WriteMessage("\n GetPropertySetDefinitionIdByName failed");
                }
                tr.Commit();
            }
            return(retBso);
        }
コード例 #3
0
ファイル: myFunctions.cs プロジェクト: AndreasLuka/ALC-C3D-LX
        public static bool SetStairPropertiesToSolid(Solid3d sol, BaseStairObject bso)
        {
            bool result = false;

            if (!IsStairPropertySetOnSolid(sol))
            {
                AddStairPropertySetToSolid(sol);
            }

            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                ObjectIdCollection setIds = PropertyDataServices.GetPropertySets(sol);
                if (setIds.Count > 0)
                {
                    foreach (ObjectId id in setIds)
                    {
                        PropertySet pset = (PropertySet)id.GetObject(OpenMode.ForWrite);
                        if (pset.PropertySetDefinitionName == MyPlugin.psdName && pset.IsWriteEnabled)
                        {
                            // Get the ObjectID of the property set definition by name
                            // Get the value of the property definition
                            pset.SetAt(pset.PropertyNameToId("name"), bso.Name);
                            pset.SetAt(pset.PropertyNameToId("_tread"), bso.Tread);
                            pset.SetAt(pset.PropertyNameToId("_riser"), bso.Riser);
                            pset.SetAt(pset.PropertyNameToId("_landing"), bso.Landing);
                            pset.SetAt(pset.PropertyNameToId("_width"), bso.Width);
                            pset.SetAt(pset.PropertyNameToId("_slope"), bso.Slope);
                            pset.SetAt(pset.PropertyNameToId("_steps"), bso.Steps);
                            result = true;
                            break;
                        }
                    }
                }
                tr.Commit();
            }
            return(result);
        }
コード例 #4
0
ファイル: myFunctions.cs プロジェクト: AndreasLuka/ALC-C3D-LX
        public static BaseStairObject GetStairPropertiesFromSolid(Solid3d sol)
        {
            BaseStairObject retBso = null;

            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                ObjectIdCollection setIds = PropertyDataServices.GetPropertySets(sol);
                if (setIds.Count > 0)
                {
                    foreach (ObjectId id in setIds)
                    {
                        PropertySet pset = (PropertySet)id.GetObject(OpenMode.ForRead);

                        if (pset.PropertySetDefinitionName == MyPlugin.psdName)
                        {
                            // Get the ObjectID of the property set definition by name
                            // Get the value of the property definition
                            BaseStairObject bso = new BaseStairObject
                            {
                                Id      = sol.Id,
                                Name    = Convert.ToString(pset.GetAt(pset.PropertyNameToId("name"))),
                                Steps   = Convert.ToInt32(pset.GetAt(pset.PropertyNameToId("_steps"))),
                                Tread   = Convert.ToDouble(pset.GetAt(pset.PropertyNameToId("_tread"))),
                                Riser   = Convert.ToDouble(pset.GetAt(pset.PropertyNameToId("_riser"))),
                                Landing = Convert.ToDouble(pset.GetAt(pset.PropertyNameToId("_landing"))),
                                Width   = Convert.ToDouble(pset.GetAt(pset.PropertyNameToId("_width"))),
                                Slope   = Convert.ToDouble(pset.GetAt(pset.PropertyNameToId("_slope")))
                            };
                            retBso = bso;
                        }
                    }
                }
                tr.Commit();
            }
            return(retBso);
        }
コード例 #5
0
        public void CreateSolidStair()
        {
            PromptResult pr;

            // Get default values
            BaseStairObject bsoStandard = MyFunctions.GetPropertySetDefinitionStairStandardValues();

            List <LayerObject> lstLayers = MyFunctions.GetLayerList();

            winCreateStair win = new winCreateStair(lstLayers, bsoStandard);
            Boolean        rtn = Application.ShowModalWindow(win).Value;

            if (rtn == false)
            {
                return;
            }

            LayerObject selectedLayer = win.CB_Layers.SelectedItem as LayerObject;

            try
            {
                BaseStairObject objStair = new BaseStairObject
                {
                    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)
                };
                MyJig2 jig = new MyJig2(objStair.Steps, objStair.Riser, objStair.Tread, objStair.Landing, objStair.Width, objStair.Slope);

                do
                {
                    // Get the value entered by the user
                    pr = ed.Drag(jig);

                    // Exit if the user presses ESC or cancels the command
                    if (pr.Status == PromptStatus.Cancel)
                    {
                        return;
                    }

                    if (pr.Status == PromptStatus.OK)
                    {
                        // Go to next phase
                        jig.jigStatus++;
                    }
                }while (jig.jigStatus < 2);

                if (pr.Status == PromptStatus.OK)
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            BlockTable bt      = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                            Solid3d    stair3d = MyFunctions.CreateStair3D(jig.steps, jig.riser, jig.tread, jig.landing, jig.width, jig.slope);
                            if (stair3d != null)
                            {
                                // Moving and adding to staircase drawing database
                                stair3d.TransformBy(jig.matDisplacement);
                                stair3d.TransformBy(jig.matRotation);
                                //update layer
                                stair3d.LayerId = selectedLayer.Id;

                                BlockTableRecord curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                                curSpace.AppendEntity(stair3d);
                                tr.AddNewlyCreatedDBObject(stair3d, true);

                                // Adding ParameterSet to Staircase
                                objStair.Id = stair3d.Id;
                                bool isCreated = MyFunctions.SetStairPropertiesToSolid(stair3d, objStair);
                            }
                        }
                        catch (System.Exception ex)
                        {
                            ed.WriteMessage(ex.ToString());
                        }
                        tr.Commit();
                    }
                }
            }
            catch
            {
                ed.WriteMessage("\n Something wrong");
            }
        }
コード例 #6
0
        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");
                }
            }
            ;
        }