[CommandMethod("Test", CommandFlags.UsePickSet)]publicstaticvoidTest(){try{using(vartransaction=ActiveUtil.TransactionManager.StartTransaction()){DBDictionarynamedDictionary=ActiveUtil.Database.NamedObjectsDictionaryId.GetObject<DBDictionary>();varresultBuf=newResultBuffer(newTypedValue((int)DxfCode.Text,"Hey this is string data"));varmyXrecord=newXrecord{Data=resultBuf};namedDictionary.UpgradeOpen();namedDictionary.SetAt("MyCustomData",myXrecord);transaction.AddNewlyCreatedDBObject(myXrecord,true);transaction.Commit();}using(vartransaction=ActiveUtil.TransactionManager.StartTransaction()){DBDictionarynamedDictionary=ActiveUtil.Database.NamedObjectsDictionaryId.GetObject<DBDictionary>();try{XrecordxRec=namedDictionary.GetAt("MyCustomData").GetObject<Xrecord>();TypedValue[]xRecData=xRec.Data.AsArray();foreach(TypedValuetvinxRecData){ActiveUtil.Editor.WriteLine(tv.Value.ToString());}}catch(System.Exception){}}}catch(System.Exceptionex){Application.ShowAlertDialog($"Something went wrong error:{ex.Message}");}}
/// <summary>/// Save a textstring in the ExtensionDictionary of an object/// </summary>publicstaticvoidSetObjXRecordText(ObjectIdid,stringkey,stringvalue){using(ResultBufferresBuf=newResultBuffer(newTypedValue((int)DxfCode.Text,value))){SetXRecordInObject(id,key,resBuf);}}
/// <summary>/// Read a string from the ExtensionDictionary of an object/// </summary>publicstaticstringGetObjXRecordText(ObjectIdid,stringkey){stringreturnValue=string.Empty;List<object>records=GetXRecordFromObject(id,key);if(records.Count>0){returnValue=Convert.ToString(records[records.Count-1]);}returnreturnValue;}
Code to Store Interger in Object
/// <summary>/// Save an integer in the ExtensionDictionary of an object/// </summary>publicstaticvoidSetObjXRecordInt32(ObjectIdid,stringkey,intvalue){using(ResultBufferresBuf=newResultBuffer(newTypedValue((int)DxfCode.Int32,value))){SetXRecordInObject(id,key,resBuf);}}
/// <summary>/// Read an integer from the ExtensionDictionary of an object/// </summary>publicstaticintGetObjXRecordInt32(ObjectIdid,stringkey){intreturnValue=-1;List<object>records=GetXRecordFromObject(id,key);if(records.Count>0){returnValue=Convert.ToInt32(records[records.Count-1]);}returnreturnValue;}