Modify List Definition for a Manual Property Definition

Modify List Definition for a Manual Property Definition

tipitasa
Enthusiast Enthusiast
901 Views
6 Replies
Message 1 of 7

Modify List Definition for a Manual Property Definition

tipitasa
Enthusiast
Enthusiast

I would like to

1. Get all ListDefinitions of a document as shown in Style Manager

2. Find a ListDefinition by name

3. Open it to Add and Remove Items from it

How can I do that? What are the .NET methods to do that?
I managed to locate the class Autodesk.Aec.DatabaseServices.ListDefinitions in code, but nothing more.


Where can I find the .NET API Reference for Autodesk.Aec? I've been searching on https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-What_s_New but I cannot find anything. 

0 Likes
Accepted solutions (1)
902 Views
6 Replies
Replies (6)
Message 2 of 7

Gepaha
Collaborator
Collaborator
Accepted solution

I think it's relatively easy as there are similarities with other Aec dictionaries.

Reference to:

  • C:\Program Files\Autodesk\AutoCAD xxxx\ACA\AecArchMgd.dll
  • C:\Program Files\Autodesk\AutoCAD xxxx\ACA\AecBaseMgd.dll

Set copy local to false.

Not tested:

 

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.Aec.Arch.DatabaseServices;
using Autodesk.Aec.DatabaseServices;

using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AecDb = Autodesk.Aec.DatabaseServices;
 public static void ListListDefinition()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                AecDb.DictionaryListDefinition ldDict = new DictionaryListDefinition(db);

                AcDb.ObjectIdCollection objectIdCollection = ldDict.Records;
                foreach (AcDb.ObjectId ldId in objectIdCollection)
                {                    
                    ListDefinition ld = (ListDefinition)tr.GetObject(ldId, OpenMode.ForRead);
                    ed.WriteMessage($"\nList defintion name: {ld.Name}");
                }
            }
        }

 

 

        public static void CreateOrAddRenameItemToListDefinition()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                AecDb.DictionaryListDefinition ldDict = new DictionaryListDefinition(db);

                try
                {
                    // Find list definition by the name
                    if (ldDict.Has("MyListDefinition", tr))
                    {
                        AcDb.ObjectId ldId = ldDict.GetAt("MyListDefinition");
                        ListDefinition ld = (ListDefinition)tr.GetObject(ldId, OpenMode.ForWrite);
                        // add item to the list definition
                        ld.AddListItem("Name1");
                        ld.AddListItem("Name2");

                        // rename item
                        AcDb.ObjectId itemId = ld.GetListItem("Name3");
                        if (!itemId.IsNull)
                        {
                            ld.RenameList(itemId, "Name3Renamed");
                        }
                        tr.Commit();
                    }
                    else
                    {
                        ListDefinition ld = new ListDefinition();
                        ld.SubSetDatabaseDefaults(db);
                        ld.SetToStandard(db);
                        ldDict.AddNewRecord("MyListDefinition", ld);
                        ld.AddListItem("Name1");
                        ld.AddListItem("Name2");
                        ld.Description = "My list definition test";
                        // Set its AppliesToFilter property
                        System.Collections.Specialized.StringCollection strCol = new System.Collections.Specialized.StringCollection();
                        // You need use internal names
                        strCol.Add("AecListUserManualPropertyDef");
                        // strCol.Add("AecListUserSpaceNames")
                        // strCol.Add("AecListUserZoneNames")
                        ld.AppliesToFilter = strCol;
                        tr.AddNewlyCreatedDBObject(ld, true);
                        tr.Commit();
                    }
                }
                catch (System.Exception ex)
                {
                    Application.ShowAlertDialog(ex.Message);
                }
            }
        }

 

0 Likes
Message 3 of 7

tipitasa
Enthusiast
Enthusiast

Do you maybe know what needs to be done for the changes to ListDefinition to be shown in PROPERTIES > Extended Data?

 

When I modify the ListDefinition by adding or removing List Items, the changes are shown correctly in the Style Manager.
However, on the PROPERTIES > Extended Data > PROPERTY SETS the lists next to particular property definitions either do not change or even show an error message *Error getting value*.

When I close the whole PROPERTIES panel and then reopen it, the lists show the correct items.

This is the code that I use:

 

using Autodesk.Aec.DatabaseServices;
using Autodesk.Aec.PropertyData.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

using System.Collections.Generic;

using ObjectId = Autodesk.AutoCAD.DatabaseServices.ObjectId;
        Database _db = Application.DocumentManager.MdiActiveDocument.Database;

        internal void ImportStyleNamesToPropertySetListDefinitions()
        {
            ObjectId propertySetDefinitionId = ObjectId.Null;
            List<string> stylesToAdd = new List<string>();

            using (var tr = _db.TransactionManager.StartTransaction())
            {
                // open property set definition
                var propSetDef = tr.GetObject(propertySetDefinitionId, OpenMode.ForWrite) as PropertySetDefinition;

                // for each of the definitions in it
                foreach (PropertyDefinition propDefinition in propSetDef.Definitions)
                {
                    // go by name
                    if (propDefinition.Name == "SomeName")
                    {
                        if (propDefinition.DataType == Autodesk.Aec.PropertyData.DataType.List)
                        {
                            // get source list definition id
                            var listDefinitionId = propDefinition.ListDefinitionId;

                            // open this list definition
                            var listDefinition = tr.GetObject(listDefinitionId, OpenMode.ForWrite) as ListDefinition;

                            // add style name items to it
                            foreach (string styleName in stylesToAdd)
                                listDefinition.AddListItem(styleName);
                        }
                    }
                    
                }
                tr.Commit();
            }

 

0 Likes
Message 4 of 7

Gepaha
Collaborator
Collaborator

I tested it here and for me it is working correctly. I just added propDefinition.SubSetDatabaseDefaults(db).

 // add style name items to it
foreach (string styleName in stylesToAdd)
   listDefinition.AddListItem(styleName);
propDefinition.SubSetDatabaseDefaults(db);
0 Likes
Message 5 of 7

tipitasa
Enthusiast
Enthusiast

Thank you for your help. It's better now, but still does not work as it should.

The first time the command runs, I still get the error message. Then I manually remove and add the property set and after that it works every time. Well, I still need to change to another tab and then back, but that's not too bad.

Do you maybe know of something else I could try or have an idea of what could go wrong in the background?

0 Likes
Message 6 of 7

Gepaha
Collaborator
Collaborator

I tested this again and had no issues. I even removed "propDefinition.SubSetDatabaseDefaults(db)" and it also worked correctly. "SubSetDatabaseDefaults" is unnecessary. It is only used when new is created.

Perhaps,  looping through all PropertySets that have the ListDefinition attached and then forcing an update.
I have ACA/MEP installed and not Civil 3D. And since this situation does not occur in my tests, it is difficult to find a solution.
If you make the project and the dwg file available, maybe someone with Civil 3D can test it.

0 Likes
Message 7 of 7

tipitasa
Enthusiast
Enthusiast

I am just adding the link to the connected post, where the issue with the error message has been solved in.

0 Likes