.NET

Reply
*Expert Elite*
Keith.Brown
Posts: 1,093
Registered: ‎03-13-2008
Message 1 of 3 (217 Views)

AutoCAD MEP: Create Property Set Method Execution Time

217 Views, 2 Replies
11-13-2013 10:07 AM

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.

 

 


Keith Brown AutoCAD MEP BLOG | RSS Feed
AutoCAD MEP 2014 | Revit 2014 | EastCoast CAD/CAM V6.1 | Visual Studio 2013
────────────────────────────────────
⁞|⁞ Please use Mark Solutions!.Accept as Solution and Give Kudos!Give Kudos as appropriate. Thank you!
ADN Support Specialist
Virupaksha.aithal
Posts: 92
Registered: ‎06-15-2011
Message 2 of 3 (200 Views)

Re: AutoCAD MEP: Create Property Set Method Execution Time

11-14-2013 10:28 PM in reply to: Keith.Brown

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

*Expert Elite*
Keith.Brown
Posts: 1,093
Registered: ‎03-13-2008
Message 3 of 3 (194 Views)

Re: AutoCAD MEP: Create Property Set Method Execution Time

11-15-2013 04:57 AM in reply to: Virupaksha.aithal

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.


Keith Brown AutoCAD MEP BLOG | RSS Feed
AutoCAD MEP 2014 | Revit 2014 | EastCoast CAD/CAM V6.1 | Visual Studio 2013
────────────────────────────────────
⁞|⁞ Please use Mark Solutions!.Accept as Solution and Give Kudos!Give Kudos as appropriate. Thank you!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community