AutoCAD Architecture Customization
Welcome to Autodesk’s AutoCAD Architecture Customization Forums. Share your knowledge, ask questions, and explore popular AutoCAD Architecture Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoCAD MEP: Create Property Set Method Execution Time

0 REPLIES 0
Reply
Message 1 of 1
Keith.Brown
1193 Views, 0 Replies

AutoCAD MEP: Create Property Set Method Execution Time

I originally posted this question in the AutoCAD .Net forum but Autodesk suggested that I ask the question here instead.  I am programmatically creating some property sets at runtime and it is taking a very long time to do so.  The original thread can be viewed here.  I will go ahead and post a different property set that has the same issue.  As soon as the running plugin reaches the line where it is setting the formula string the code will slowdown and take several seconds to complete.

 

#region CreatePipeFittingPropertySet

        internal static void CreatePipeFittingPropertySet(string propertySetName)
        {
            var database = Application.DocumentManager.MdiActiveDocument.Database;

            try
            {
                // Wrap the entire operation up inside of a single transaction so if creating
                // The property set definition fails at any point the entire property set definition
                // will not be created.
                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    var dictionaryPropertyDataFormat = new DictionaryPropertyDataFormat(database);
                    var propertySetDefinition = new PropertySetDefinition();

                    // Create the manual property definitions first for use in the formulas
                    using (Transaction transaction1 = database.TransactionManager.StartTransaction())
                    {
                        propertySetDefinition.SetToStandard(database);
                        propertySetDefinition.SubSetDatabaseDefaults(database);
                        propertySetDefinition.Description =
                            "SuperToolTips property set to display information on pipe fittings";
                        propertySetDefinition.AlternateName = propertySetName;
                        propertySetDefinition.IsLocked = false;
                        propertySetDefinition.IsVisible = true;
                        propertySetDefinition.IsWriteable = true;
                        var filters = new StringCollection { "AecbDbPipeFitting", "AecbDbPipeCustomFitting", "AecbDbPipeFlex" };
                        propertySetDefinition.SetAppliesToFilter(filters, false);

                        var automaticPropertyDefinition = new PropertyDefinition();
                        automaticPropertyDefinition.SetToStandard(database);
                        automaticPropertyDefinition.SubSetDatabaseDefaults(database);
                        automaticPropertyDefinition.Name = "Size Name";
                        automaticPropertyDefinition.Description = "The Part Size Name of the pipe fitting";
                        automaticPropertyDefinition.IsVisible = true;
                        automaticPropertyDefinition.IsReadOnly = true;
                        automaticPropertyDefinition.IsLocked = true;
                        automaticPropertyDefinition.SetAutomaticData("AecbDbPipeFitting", "Part Size Name");
                        propertySetDefinition.Definitions.Add(automaticPropertyDefinition);
                        propertySetDefinition.SetDisplayOrder(automaticPropertyDefinition, 1);

                        automaticPropertyDefinition = new PropertyDefinition();
                        automaticPropertyDefinition.SetToStandard(database);
                        automaticPropertyDefinition.SubSetDatabaseDefaults(database);
                        automaticPropertyDefinition.Name = "Routing Preference";
                        automaticPropertyDefinition.Description = "The routing preference of the pipe fitting";
                        automaticPropertyDefinition.IsVisible = true;
                        automaticPropertyDefinition.IsReadOnly = true;
                        automaticPropertyDefinition.IsLocked = true;
                        automaticPropertyDefinition.SetAutomaticData("AecbDbPipeFitting", "Routing Preference");
                        propertySetDefinition.Definitions.Add(automaticPropertyDefinition);
                        propertySetDefinition.SetDisplayOrder(automaticPropertyDefinition, 2);

                        automaticPropertyDefinition = new PropertyDefinition();
                        automaticPropertyDefinition.SetToStandard(database);
                        automaticPropertyDefinition.SubSetDatabaseDefaults(database);
                        automaticPropertyDefinition.Name = "System";
                        automaticPropertyDefinition.Description = "The System of the pipe fitting";
                        automaticPropertyDefinition.IsVisible = true;
                        automaticPropertyDefinition.IsReadOnly = true;
                        automaticPropertyDefinition.IsLocked = true;
                        automaticPropertyDefinition.SetAutomaticData("AecbDbPipeFitting", "System");
                        propertySetDefinition.Definitions.Add(automaticPropertyDefinition);
                        propertySetDefinition.SetDisplayOrder(automaticPropertyDefinition, 3);

                        automaticPropertyDefinition = new PropertyDefinition();
                        automaticPropertyDefinition.SetToStandard(database);
                        automaticPropertyDefinition.SubSetDatabaseDefaults(database);
                        automaticPropertyDefinition.Name = "LocationZ";
                        automaticPropertyDefinition.Description =
                            "The z element of the location of the object in 3D space";
                        automaticPropertyDefinition.IsVisible = false;
                        automaticPropertyDefinition.IsReadOnly = true;
                        automaticPropertyDefinition.IsLocked = true;
                        automaticPropertyDefinition.FormatId = dictionaryPropertyDataFormat.GetAt("Unformatted");
                        automaticPropertyDefinition.SetAutomaticData("AecbDbPipeFitting", "Location Z");
                        propertySetDefinition.Definitions.Add(automaticPropertyDefinition);

                        var dictionaryPropertySetDefinitions = new DictionaryPropertySetDefinitions(database);
                        if (dictionaryPropertySetDefinitions.Has(propertySetName, transaction1))
                        {
                            return;
                        }

                        dictionaryPropertySetDefinitions.AddNewRecord(propertySetName, propertySetDefinition);
                        transaction1.AddNewlyCreatedDBObject(propertySetDefinition, true);

                        // We need to commit these transactions so that the manual property definitions
                        // can be used in the formula definition
                        transaction1.Commit();
                    }


                    using (Transaction transaction2 = database.TransactionManager.StartTransaction())
                    {
                        propertySetDefinition =
                            transaction2.GetObject(propertySetDefinition.ObjectId, OpenMode.ForWrite) as
                                PropertySetDefinition;
                        var formulaPropertyDefinition = new PropertyDefinitionFormula();
                        formulaPropertyDefinition.SetToStandard(database);
                        formulaPropertyDefinition.SubSetDatabaseDefaults(database);
                        formulaPropertyDefinition.Name = "CenterOfPipeCalc";
                        formulaPropertyDefinition.Description = "The Center of the pipe elevation";
                        formulaPropertyDefinition.IsVisible = false;
                        if (propertySetDefinition != null)
                            propertySetDefinition.Definitions.Add(formulaPropertyDefinition);
                        formulaPropertyDefinition.SetFormulaString("RESULT = [LocationZ]");
                        formulaPropertyDefinition.DataItems[0].FormatId =
                            dictionaryPropertyDataFormat.GetAt("Unformatted");
                        formulaPropertyDefinition.FormatId =
                            dictionaryPropertyDataFormat.GetAt("Unit - Distance Feet-Inches - No Comma");
                        formulaPropertyDefinition.IsLocked = true;

                        // This formula definition needs to be commited so it can be used in the
                        // Next formula
                        transaction2.Commit();
                    }

                    using (Transaction transaction3 = database.TransactionManager.StartTransaction())
                    {
                        propertySetDefinition =
                            transaction3.GetObject(propertySetDefinition.ObjectId, OpenMode.ForWrite) as
                                PropertySetDefinition;
                        var formulaPropertyDefinition = new PropertyDefinitionFormula();
                        formulaPropertyDefinition.SetToStandard(database);
                        formulaPropertyDefinition.SubSetDatabaseDefaults(database);
                        formulaPropertyDefinition.Name = "CenterOfPipe";
                        formulaPropertyDefinition.IsVisible = false;
                        formulaPropertyDefinition.Description = "The center of the pipe elevation in 3D space";
                        propertySetDefinition.Definitions.Add(formulaPropertyDefinition);
                        formulaPropertyDefinition.SetFormulaString("RESULT = \"[CenterOfPipeCalc]\"");
                        formulaPropertyDefinition.DataItems[0].FormatId =
                            dictionaryPropertyDataFormat.GetAt("Unit - Distance Feet-Inches - No Comma");
                        formulaPropertyDefinition.IsLocked = true;

                        transaction3.Commit();
                    }

                    using (Transaction transaction4 = database.TransactionManager.StartTransaction())
                    {
                        propertySetDefinition =
                            transaction4.GetObject(propertySetDefinition.ObjectId, OpenMode.ForWrite) as
                                PropertySetDefinition;
                        var formulaPropertyDefinition = new PropertyDefinitionFormula();
                        formulaPropertyDefinition.SetToStandard(database);
                        formulaPropertyDefinition.SubSetDatabaseDefaults(database);
                        formulaPropertyDefinition.Name = "Elevation";
                        formulaPropertyDefinition.Description = "The elevation of the pipe object in 3D space";
                        formulaPropertyDefinition.IsVisible = true;
                        propertySetDefinition.Definitions.Add(formulaPropertyDefinition);
                        formulaPropertyDefinition.SetFormulaString("RESULT = \"[CenterOfPipe]\"");
                        propertySetDefinition.SetDisplayOrder(formulaPropertyDefinition, 4);
                        formulaPropertyDefinition.IsLocked = true;

                        transaction4.Commit();
                    }

                    transaction.Commit();
                }
            }
            catch (Exception e)
            {
                ToolTipUtilities.ActiveEditor.WriteMessage(e.Message + "\n");
            }

        }
        #endregion

 

Is anyone else out there creating property sets programmatically and if so did you run into the same issue?  If you did were you able to solve it?  I know i can store the property sets in a container drawing and programmatically import them into the current drawing but I was hoping to get this to work so i would not have to maintain code and a style drawing.  Thanks for any help.

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost