HOW TO MODIFY FIELD DATA THROUGH CODE.

HOW TO MODIFY FIELD DATA THROUGH CODE.

nikhilsTHSR5
Participant Participant
393 Views
2 Replies
Message 1 of 3

HOW TO MODIFY FIELD DATA THROUGH CODE.

nikhilsTHSR5
Participant
Participant

I have added Data to Field Data. How can I get those values Programatically?

Any help will be great. Thanks

 

for reference, I have attached the image and link:

Field data.PNGhttps://allaboutcad.com/tutorial-use-fields-for-titleblock-text/ 

0 Likes
Accepted solutions (1)
394 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You can use these extension methods.

        /// <summary>
		/// Gets the value of a custom property.
        /// </summary>
        /// <param name="db">Database the method applys to.</param>
        /// <param name="key">Property key.</param>
        /// <returns>The property value or null if not found.</returns>
        public static string GetCustomProperty(this Database db, string key)
        {
            DatabaseSummaryInfoBuilder sumInfo = new DatabaseSummaryInfoBuilder(db.SummaryInfo);
            IDictionary custProps = sumInfo.CustomPropertyTable;
            return ((string)custProps[key]).Trim();
        }

        /// <summary>
		/// Gets the Database properties.
        /// </summary>
        /// <param name="db">Database the method applys to.</param>
        /// <returns>A dictionary containing the custom properties.</returns>
        public static Dictionary<string, string> GetCustomProperties(this Database db)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();
            IDictionaryEnumerator dictEnum = db.SummaryInfo.CustomProperties;
            while (dictEnum.MoveNext())
            {
                DictionaryEntry entry = dictEnum.Entry;
                result.Add((string)entry.Key, ((string)entry.Value).Trim());
            }
            return result;
        }

        /// <summary>
		/// Sets the value of an existing property or create it if it didn't exist.
        /// </summary>
        /// <param name="db">Database the method applys to.</param>
        /// <param name="key">Property key.</param>
        /// <param name="value">Property value.</param>
        public static void SetCustomProperty(this Database db, string key, string value)
        {
            DatabaseSummaryInfoBuilder infoBuilder = new DatabaseSummaryInfoBuilder(db.SummaryInfo);
            IDictionary custProps = infoBuilder.CustomPropertyTable;
            if (custProps.Contains(key))
                custProps[key] = value;
            else
                custProps.Add(key, value);
            db.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo();
        }

        /// <summary>
		/// Sets the values of existing properties or create those which didn't exist.
        /// </summary>
        /// <param name="db">Database the method applys to.</param>
        /// <param name="values">Key/Value pairs for the properties.</param>
        public static void SetCustomProperties(this Database db, params KeyValuePair<string, string>[] values)
        {
            DatabaseSummaryInfoBuilder infoBuilder = new DatabaseSummaryInfoBuilder(db.SummaryInfo);
            IDictionary custProps = infoBuilder.CustomPropertyTable;
            foreach (KeyValuePair<string, string> pair in values)
            {
                string key = pair.Key;
                if (custProps.Contains(key))
                    custProps[key] = pair.Value;
                else
                    custProps.Add(key, pair.Value);
            }
            db.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo();
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3

nikhilsTHSR5
Participant
Participant

Hello,

Thank you it worked.

 

0 Likes