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

Update xrecord data attached to NOD or OBject

1 REPLY 1
Reply
Message 1 of 2
Anonymous
1461 Views, 1 Reply

Update xrecord data attached to NOD or OBject

Hi all,

 

Question, Is it possible to update values stored in an xrecord. If not what is the best aproche my goal?

 

Kind regards,

 

Irvin

1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

Might be a bit late, but here's what I use for a entity extension Dictionary, you will need to call it from within a transaction for it to work. Hope it helps

 

 

/// <summary>
        /// Add Extension Dictionary Data to the passed database object id
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="Buf">ResultBuffer to add as Xrecord to the db object's EDD</param>
        /// <param name="ObjId">object to add EDD too</param>
        /// <param name="DataKey">data key to use in the EDD</param>
        public static void EDDAdd (ref ResultBuffer Buf, ObjectId ObjId, string DataKey)
        {            
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            Debug.Assert(db.TransactionManager.NumberOfActiveTransactions > 0, "No transaction to link to");

          try
          {
              SymbolUtilityServices.ValidateSymbolName(DataKey, false); //validates the name is acceptable for the Dictionary, if not throws exception

              DBObject DBObj = (DBObject)db.TransactionManager.GetObject(ObjId, OpenMode.ForWrite);
              if (DBObj.ExtensionDictionary.IsNull)
              {
                  DBObj.CreateExtensionDictionary();
              }
              DBDictionary ExtDic = (DBDictionary)db.TransactionManager.GetObject(DBObj.ExtensionDictionary, OpenMode.ForWrite); //get entities extension dictionary
              if (ExtDic.Contains(DataKey))
              {
                  ObjectId XRecId = ExtDic.GetAt(DataKey);

                  Xrecord myXrecord = default(Xrecord);

                  myXrecord = (Xrecord)db.TransactionManager.GetObject(XRecId, OpenMode.ForWrite);

                  myXrecord.Data = Buf;

                 

              }
              else
              {
                  Xrecord myXrecord = new Xrecord();

                  myXrecord.Data = Buf;

                  ExtDic.SetAt(DataKey, myXrecord);

                  db.TransactionManager.AddNewlyCreatedDBObject(myXrecord, true);
              }
             

            
          }
          catch (Exception e) //Autodesk.AutoCAD.Runtime.Exception
          {
              ed.WriteMessage("Error: DwgData.EEDAdd - " + e.Message);
          }
        }

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