.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoCAD MEP: Create Property Set Method Execution Time

2 REPLIES 2
Reply
Message 1 of 3
Keith.Brown
1013 Views, 2 Replies

AutoCAD MEP: Create Property Set Method Execution Time

Hi,

 

When i run the following code to create a property set definition in AutoCAD MEP the method takes over 28 seconds to complete.  The slowdown occurs when I am adding the formulas to the formula property definitions.  I followed the sample that shipped with AutoCAD MEP and the property sets are being created properly the method just takes forever to complete.  Is there something that I have forgotten to do?

 

 

using System;
using System.Collections.Specialized;
using Autodesk.Aec.PropertyData.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

namespace Brow.SuperToolTips
{
    class ToolTipPropertySetDefinitions
    {

        internal static void CreateMvPartPropertySet(string propertySetName)
        {
            var database = Application.DocumentManager.MdiActiveDocument.Database;
            DateTime startTime = DateTime.Now;
            try
            {
                var dictionaryPropertyDataFormat = new DictionaryPropertyDataFormat(database);
                var propertySetDefinition = new PropertySetDefinition();

                using (Transaction transaction1 = database.TransactionManager.StartTransaction())
                {
                    propertySetDefinition.SetToStandard(database);
                    propertySetDefinition.SubSetDatabaseDefaults(database);
                    propertySetDefinition.Description = "SuperToolTips property set to display information on Multi-View Parts";
                    propertySetDefinition.AlternateName = propertySetName;
                    propertySetDefinition.IsLocked = false;
                    propertySetDefinition.IsVisible = true;
                    propertySetDefinition.IsWriteable = true;
                    var filters = new StringCollection();
                    filters.Add("AecbDbMvPart");
                    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 Multi-View Part";
                    automaticPropertyDefinition.IsVisible = true;
                    automaticPropertyDefinition.IsReadOnly = true;
                    automaticPropertyDefinition.SetAutomaticData("AecbDbMvPart", "Part Size Name");
                    propertySetDefinition.Definitions.Add(automaticPropertyDefinition);

                    automaticPropertyDefinition = new PropertyDefinition();
                    automaticPropertyDefinition.SetToStandard(database);
                    automaticPropertyDefinition.SubSetDatabaseDefaults(database);
                    automaticPropertyDefinition.Name = "System";
                    automaticPropertyDefinition.Description = "The Systems of the Multi-View Part";
                    automaticPropertyDefinition.IsVisible = true;
                    automaticPropertyDefinition.IsReadOnly = true;
                    automaticPropertyDefinition.SetAutomaticData("AecbDbMvPart", "System");
                    propertySetDefinition.Definitions.Add(automaticPropertyDefinition);

                    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.FormatId = dictionaryPropertyDataFormat.GetAt("Unformatted");
                    automaticPropertyDefinition.SetAutomaticData("AecbDbMvPart", "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);
                    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 = "ElevationCalc";
                    formulaPropertyDefinition.Description = "RESULT = [LocationZ]";
                    formulaPropertyDefinition.IsVisible = false;
                    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");
                    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 = "Elevation";
                    formulaPropertyDefinition.Description = "The elevation of the Multi-View Part in 3D space";
                    propertySetDefinition.Definitions.Add(formulaPropertyDefinition);
                    formulaPropertyDefinition.SetFormulaString("RESULT = \"[ElevationCalc]\"");
                    formulaPropertyDefinition.DataItems[0].FormatId = dictionaryPropertyDataFormat.GetAt("Unit - Distance Feet-Inches - No Comma");

                    transaction3.Commit();
                }
                DateTime endTime = DateTime.Now;
                ToolTipUtilities.ActiveEditor.WriteMessage("Time for Method to Execute: " + (endTime - startTime).Minutes.ToString());
            }
            catch (Exception e)
            {
                ToolTipUtilities.ActiveEditor.WriteMessage(e.Message + "\n");
            }

        }

    }
}

 

 

I call the method with a simple call that includes the desired property set definition name like so:

 

            ToolTipPropertySetDefinitions.CreateMvPartPropertySet("MvPartSuperToolTip");

 

Thank you.

 

 

2 REPLIES 2
Message 2 of 3

Hi keith

 

Sorry, I don't have an answer. You may try posting to AutoCAD MEP forum. As this is AutoCAD Forum. I suspect majority of people are working with vanilla AutoCAD.  There may be somebody over there who might be able to answer your question.  (or cross post with pointers so that you get maximum exposure, at least.)



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 3 of 3

Posting a .net question in the AutoCAD MEP forum is akin to watching paint dry.  In other words no one is going to answer. 

 

I will try the autocad architecture customization forum but .net questions don't get answered there very often either.  BTW, there is an error in the AecPropertyDefinitionFormulaSampleMgd c# .net sample that ships with AutoCAD Architecture and AutoCAD MEP.  The file will compile but will generate an exception when ran.  A filter is created for the wall type but it is never applied to the property set.  Since the property set has not filters applied you cannot create an automatic property definition and it generates the exception.  Adding the following line after creating the filter will cause the sample to run correctly.

 

def.SetAppliesToFilter(appliesTo, false);

 

I was really wanting to create the property sets programmatically and not have to supply a "style" drawing to store the property sets in.  But it looks like I am going to have to go that route and just import the property sets into the current drawing.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost