コード例 #1
0
        public void ShowSample()
        {
            Database db = GetDatabase();
            Editor   ed = GetEditor();

            ed.WriteMessage("Adding a new property set definition contains a formula property to calculate wall volume.\n");
            // we need to add all the automatic properties prior to the formula property
            PropertySetDefinition psd = CreateWallPropertySetDefinition();
            // then we add the property set definition to the dictionary to make formula property work properly
            DictionaryPropertySetDefinitions dict = new DictionaryPropertySetDefinitions(db);

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                dict.AddNewRecord("SampleWallPropertySetDefinition", psd);
                trans.AddNewlyCreatedDBObject(psd, true);
                // now we can create the formula property
                PropertyDefinitionFormula formula = new PropertyDefinitionFormula();
                formula.SetToStandard(db);
                formula.SubSetDatabaseDefaults(db);
                formula.Name = "Wall Volume";
                formula.UseFormulaForDescription = true;
                // before setting formula string to the formula property, we need to make sure
                // that the property definition is added to the property set definition (which has an object id)
                psd.Definitions.Add(formula);
                // so we can set the formula string now
                formula.SetFormulaString("[Length]*[Height]*[Width]");
                // and here we change the sample values of the referenced properties
                formula.DataItems[0].Sample = 1;
                formula.DataItems[1].Sample = 2;
                formula.DataItems[2].Sample = 3;
                trans.Commit();
            }
            ed.WriteMessage("A new property set definition \"SampleWallPropertySetDefinition\" is created.\n");
            ed.WriteMessage("It contains a formula definition named \"Wall Volume\".\n");
        }
コード例 #2
0
ファイル: myFunctions.cs プロジェクト: AndreasLuka/ALC-C3D-LX
        public static ObjectId CreateStairPropertySetDefinition(string psdName)
        {
            ObjectId psdId;

            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

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

            DictionaryPropertySetDefinitions dict = new DictionaryPropertySetDefinitions(db);


            // Check for existing propert set definition ... If so just return its ObjectId.
            psdId = GetPropertySetDefinitionIdByName(psdName);

            if (psdId != ObjectId.Null)
            {
                ed.WriteMessage("\n Property set definition {0} exist", psdName);
                return(psdId);
                // check version and correctness not implemented
            }
            else
            {
                // Create the new property set definition;
                PropertySetDefinition psd = new PropertySetDefinition();
                psd.SetToStandard(db);
                psd.SubSetDatabaseDefaults(db);
                psd.AlternateName = psdName;
                psd.IsLocked      = true;
                psd.IsVisible     = false;
                psd.IsWriteable   = true;

                // Setup an array of objects that this property set definition will apply to
                System.Collections.Specialized.StringCollection appliesto = new System.Collections.Specialized.StringCollection
                {
                    "AcDb3dSolid"
                };
                psd.SetAppliesToFilter(appliesto, false);

                // Add the property set definition to the dictionary to make formula property work correctly
                using (Transaction tr = tm.StartTransaction())
                {
                    dict.AddNewRecord(psdName, psd);
                    tr.AddNewlyCreatedDBObject(psd, true);

                    // Invisible Properties (managed by app)
                    PropertyDefinition def;

                    def = new PropertyDefinition();
                    def.SetToStandard(db);
                    def.SubSetDatabaseDefaults(db);
                    def.Name        = "_tread";
                    def.DataType    = Autodesk.Aec.PropertyData.DataType.Real;
                    def.DefaultData = 0.32;
                    def.IsVisible   = false;
                    psd.Definitions.Add(def);

                    def = new PropertyDefinition();
                    def.SetToStandard(db);
                    def.SubSetDatabaseDefaults(db);
                    def.Name        = "_riser";
                    def.DataType    = Autodesk.Aec.PropertyData.DataType.Real;
                    def.DefaultData = 0.15;
                    def.IsVisible   = false;
                    psd.Definitions.Add(def);

                    def = new PropertyDefinition();
                    def.SetToStandard(db);
                    def.SubSetDatabaseDefaults(db);
                    def.Name        = "_landing";
                    def.DataType    = Autodesk.Aec.PropertyData.DataType.Real;
                    def.DefaultData = 1.1;
                    def.IsVisible   = false;
                    psd.Definitions.Add(def);

                    def = new PropertyDefinition();
                    def.SetToStandard(db);
                    def.SubSetDatabaseDefaults(db);
                    def.Name        = "_width";
                    def.DataType    = Autodesk.Aec.PropertyData.DataType.Real;
                    def.DefaultData = 2.00;
                    def.IsVisible   = false;
                    psd.Definitions.Add(def);


                    def = new PropertyDefinition();
                    def.SetToStandard(db);
                    def.SubSetDatabaseDefaults(db);
                    def.Name        = "_slope";
                    def.DataType    = Autodesk.Aec.PropertyData.DataType.Real;
                    def.DefaultData = 0.02;
                    def.IsVisible   = false;
                    psd.Definitions.Add(def);

                    def = new PropertyDefinition();
                    def.SetToStandard(db);
                    def.SubSetDatabaseDefaults(db);
                    def.Name        = "_steps";
                    def.DataType    = Autodesk.Aec.PropertyData.DataType.Integer;
                    def.DefaultData = 5;
                    def.IsVisible   = false;
                    psd.Definitions.Add(def);

                    // Visable properties (exposed to user)

                    def = new PropertyDefinition();
                    def.SetToStandard(db);
                    def.SubSetDatabaseDefaults(db);
                    def.Name        = "name";
                    def.DataType    = Autodesk.Aec.PropertyData.DataType.Text;
                    def.DefaultData = "Stair - ";
                    def.IsVisible   = true;
                    psd.Definitions.Add(def);

                    // Visable read only properties (exposed to user)

                    PropertyDefinitionFormula formula;

                    // Property definition need to be added to the property set definition before setting formula string to the formula property

                    // steps
                    formula = new PropertyDefinitionFormula();
                    formula.SetToStandard(db);
                    formula.SubSetDatabaseDefaults(db);
                    formula.Name = "steps";
                    psd.Definitions.Add(formula);
                    formula.SetFormulaString("[_steps]");

                    // riser
                    formula = new PropertyDefinitionFormula();
                    formula.SetToStandard(db);
                    formula.SubSetDatabaseDefaults(db);
                    formula.Name = "riser";
                    psd.Definitions.Add(formula);
                    formula.SetFormulaString("[_riser]");

                    // tread
                    formula = new PropertyDefinitionFormula();
                    formula.SetToStandard(db);
                    formula.SubSetDatabaseDefaults(db);
                    formula.Name = "tread";
                    psd.Definitions.Add(formula);
                    formula.SetFormulaString("[_tread]");

                    // landing
                    formula = new PropertyDefinitionFormula();
                    formula.SetToStandard(db);
                    formula.SubSetDatabaseDefaults(db);
                    formula.Name = "landing";
                    psd.Definitions.Add(formula);
                    formula.SetFormulaString("[_landing]");

                    // width
                    formula = new PropertyDefinitionFormula();
                    formula.SetToStandard(db);
                    formula.SubSetDatabaseDefaults(db);
                    formula.Name = "width";
                    psd.Definitions.Add(formula);
                    formula.SetFormulaString("[_width]");

                    // slope
                    formula = new PropertyDefinitionFormula();
                    formula.SetToStandard(db);
                    formula.SubSetDatabaseDefaults(db);
                    formula.Name = "slope";
                    psd.Definitions.Add(formula);
                    formula.SetFormulaString("[_slope]");

                    tr.Commit();

                    psdId = psd.ObjectId;
                    return(psdId);
                }
            }
        }