<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: AutoCAD C#: Modify Xdata value in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393680#M39665</link>
    <description>&lt;BR /&gt;Thank you very much for everything, your comment helped me a lot and to be able to find a solution to what I needed</description>
    <pubDate>Wed, 31 Aug 2022 18:43:32 GMT</pubDate>
    <dc:creator>SoporteEspecializado</dc:creator>
    <dc:date>2022-08-31T18:43:32Z</dc:date>
    <item>
      <title>AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5670680#M39655</link>
      <description>&lt;P&gt;How can I modify the value of existing Xdata on the existing objects?&amp;nbsp; I was able to retrieve the Xdata values, but I have not been able to find a method to change the value.&amp;nbsp; So far I got the following code by Googling everywhere, but "aryXD[intXD].Value" seems to be read only, and I can't find the way to assign different value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;TypedValue[] acTypValAr = new TypedValue[2]; //instanciate array 

 acTypValAr.SetValue(new TypedValue((int)DxfCode.ExtendedDataRegAppName,strAFM), 0); //archibus

 acTypValAr.SetValue(new TypedValue((int)DxfCode.ExtendedDataAsciiString, strCur), 1); //bldg code 

SelectionFilter acSelFtr = new SelectionFilter(acTypValAr); //assign 



//select

SelectionSet acSSet = acDocEd.SelectAll(acSelFtr).Value;

MessageBox.Show("object before: " + acSSet.Count.ToString());



foreach (SelectedObject acSSObj in acSSet)

{

if (acSSObj != null)

{

Entity acEnt = MyCommands.acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite) as Entity;

if (acEnt != null)

{

TypedValue[] aryXD = acEnt.XData.AsArray();

if (aryXD != null)

{

for (int intXD = 0; intXD &amp;lt; aryXD.Length; intXD++)

{

if (aryXD[intXD].TypeCode == 1000)

{

if (aryXD[intXD].Value.ToString() == strCur)

{
&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jun 2015 19:14:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5670680#M39655</guid>
      <dc:creator>mnpatric</dc:creator>
      <dc:date>2015-06-09T19:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5671237#M39656</link>
      <description>&lt;P&gt;Hi Patric,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To my knowledge, XData record can’t be updated. But below workaround may help you achieve this.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Retrieve data from XData record&lt;/LI&gt;
&lt;LI&gt;Delete/Dispose XData record from object&lt;/LI&gt;
&lt;LI&gt;Create a new TypedValue/XData Record with updated values from retrieved data&lt;/LI&gt;
&lt;LI&gt;Add this new record to object&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Srikanth.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2015 08:57:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5671237#M39656</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-06-10T08:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5672133#M39657</link>
      <description>&lt;P&gt;thank you very much for your info.&amp;nbsp; that makes sense because when i tried to setvalue to the existing xdata, i get a fatal error.&amp;nbsp; i will try your method.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2015 15:49:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5672133#M39657</guid>
      <dc:creator>mnpatric</dc:creator>
      <dc:date>2015-06-10T15:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5672235#M39658</link>
      <description>&lt;P&gt;if possible, could you please post a sample code?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2015 16:33:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5672235#M39658</guid>
      <dc:creator>mnpatric</dc:creator>
      <dc:date>2015-06-10T16:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5672489#M39659</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming &lt;EM&gt;strAFM&lt;/EM&gt; is bound to your application name and &lt;EM&gt;strCur&lt;/EM&gt; is bound to the string value you want to change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;

TypedValue[] filter = { new TypedValue(1001, strAFM) };
PromptSelectionResult psr = ed.GetSelection(new SelectionFilter(filter));
if (psr.Status != PromptStatus.OK) return;

using (Transaction tr = db.TransactionManager.StartTransaction())
{
    foreach (SelectedObject obj in psr.Value)
    {
        Entity ent = (Entity)tr.GetObject(obj.ObjectId, OpenMode.ForWrite);
        ResultBuffer resbuf = ent.GetXDataForApplication(strAFM);
        TypedValue[] data = resbuf.AsArray();
        for (int i = 0; i &amp;lt; data.Length; i++)
        {
            TypedValue tv = data[i];
            if (tv.TypeCode == 1000 &amp;amp;&amp;amp; (string)tv.Value == strCur)
            {
                data[i] = new TypedValue(1000, "new value");
            }
        }
        resbuf = new ResultBuffer(data);
        ent.XData = resbuf;
    }
    tr.Commit();
}&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jun 2015 18:52:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5672489#M39659</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2015-06-10T18:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5672495#M39660</link>
      <description>&lt;P&gt;thank you very much for your help&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2015 18:55:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/5672495#M39660</guid>
      <dc:creator>mnpatric</dc:creator>
      <dc:date>2015-06-10T18:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/8121649#M39661</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;greetings...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if we you AutoCAD COM API, How can I proceed. could you please support me&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 20:20:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/8121649#M39661</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-07-10T20:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/8121677#M39662</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Have a look at the &lt;A href="http://help.autodesk.com/view/OARX/2018/FRA/?guid=GUID-330FCA31-A2A9-47F0-972D-6915B6B98426" target="_blank"&gt;GetXData()&lt;/A&gt; and &lt;A href="http://help.autodesk.com/view/OARX/2018/FRA/?guid=GUID-EF0393EC-8446-4989-8C72-F3AE49D81176" target="_blank"&gt;SetXData()&lt;/A&gt; methods.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 20:33:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/8121677#M39662</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-07-10T20:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393167#M39663</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello My name is Danieel, I am trying to make sure that the xdata associated with an unexploded element can be maintained when the element is exploded.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);&lt;BR /&gt;BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);&lt;/P&gt;&lt;P&gt;DBObjectCollection objs = new DBObjectCollection();&lt;/P&gt;&lt;P&gt;foreach (ObjectId objId in btr)&lt;BR /&gt;{&lt;BR /&gt;ent = (Entity)tr.GetObject(objId, OpenMode.ForRead);&lt;BR /&gt;ent.Explode(objs);&lt;BR /&gt;ent.UpgradeOpen();&lt;BR /&gt;// ent.Erase();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;foreach (DBObject obj in objs)&lt;BR /&gt;{&lt;BR /&gt;Entity ent1 = (Entity)obj;&lt;BR /&gt;&lt;BR /&gt;TypedValue[] c = ent.XData.AsArray();&lt;BR /&gt;String nameref = c[0].Value.ToString();&lt;BR /&gt;idRef = c[3].Value.ToString();&lt;BR /&gt;&lt;BR /&gt;btr.AppendEntity(ent1);&lt;BR /&gt;tr.AddNewlyCreatedDBObject(ent1, true);&lt;BR /&gt;ent1.XData = new ResultBuffer(new TypedValue(1001, nameref), new TypedValue(1070, 1), new TypedValue(1000, idRef));&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;tr.Commit();&lt;BR /&gt;db.SaveAs(rutanarchivo, DwgVersion.Current);&lt;BR /&gt;}&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;I only get the xdata of an element&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Could someone help me?&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2022 14:56:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393167#M39663</guid>
      <dc:creator>SoporteEspecializado</dc:creator>
      <dc:date>2022-08-31T14:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393331#M39664</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before exploding each entity within the current space, you should check if the entity is explodable and if it has (the required) xdata.&lt;/P&gt;
&lt;P&gt;You should use a simple method which try to explode an entity maintaing the xdata (if any) in the resulting entities, so that you can try this method by selection a single entity and, when it suit your needs use this same method with all entities within the current space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example of this kind of method:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        static DBObjectCollection TryExplodeMaintainingXdata(Entity entity)
        {
            try
            {
                var entitySet = new DBObjectCollection();
                var data = entity.XData;
                entity.Explode(entitySet);
                if (data != null)
                {
                    foreach (Entity ent in entitySet)
                    {
                        ent.XData = data;
                    }
                }
                return entitySet;
            }
            catch { return null; }
        }&lt;/LI-CODE&gt;
&lt;P&gt;And a testing command:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("XPLODETEST")]
        public static void ExplodeTest()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var pr = ed.GetEntity("\nSelect entity to explode: ");
            if (pr.Status != PromptStatus.OK)
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var entity = (Entity)tr.GetObject(pr.ObjectId, OpenMode.ForWrite);
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                var entitySet = TryExplodeMaintainingXdata(entity);
                if (entitySet != null)
                {
                    foreach (Entity ent in entitySet)
                    {
                        curSpace.AppendEntity(ent);
                        tr.AddNewlyCreatedDBObject(ent, true);
                    }
                }
                else
                {
                    ed.WriteMessage("\nSelected entity cannot be exploded.");
                }
                tr.Commit();
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 31 Aug 2022 16:02:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393331#M39664</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-08-31T16:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393680#M39665</link>
      <description>&lt;BR /&gt;Thank you very much for everything, your comment helped me a lot and to be able to find a solution to what I needed</description>
      <pubDate>Wed, 31 Aug 2022 18:43:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393680#M39665</guid>
      <dc:creator>SoporteEspecializado</dc:creator>
      <dc:date>2022-08-31T18:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393922#M39666</link>
      <description>&lt;PRE&gt;&lt;SPAN class=""&gt;Hello
Doing more tests with the code, it crashes when trying to manage large planes.
Attached code extract.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;using (Database db = new Database(false, true))&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;db.ReadDwgFile(filedwg, FileOpenMode.OpenForReadAndAllShare, false, "");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;catch (System.Exception)&lt;BR /&gt;{&lt;BR /&gt;ed.WriteMessage("\nUnable to read drawing file.");&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;PromptResult sigla = ed.GetString("Ingrese las propiedades para las capas");&lt;BR /&gt;using (Transaction tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);&lt;BR /&gt;BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);&lt;BR /&gt;foreach (ObjectId objId in btr)&lt;BR /&gt;{&lt;BR /&gt;var entity = (Entity)tr.GetObject(objId, OpenMode.ForWrite);&lt;BR /&gt;var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);&lt;BR /&gt;var entitySet = TryExplodeMaintainingXdata(entity);&lt;BR /&gt;&lt;BR /&gt;if (entitySet != null)&lt;BR /&gt;{&lt;BR /&gt;foreach (Entity ent in entitySet)&lt;BR /&gt;{&lt;BR /&gt;curSpace.AppendEntity(ent);&lt;BR /&gt;tr.AddNewlyCreatedDBObject(ent, true);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;ed.WriteMessage("\nSelected entity cannot be exploded.");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;tr.Commit();&lt;BR /&gt;db.SaveAs(rutanarchivo, DwgVersion.Current);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;static DBObjectCollection TryExplodeMaintainingXdata(Entity entity)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;var entitySet = new DBObjectCollection();&lt;BR /&gt;var data = entity.XData;&lt;BR /&gt;entity.Explode(entitySet);&lt;BR /&gt;if (data != null)&lt;BR /&gt;{&lt;BR /&gt;foreach (Entity ent in entitySet)&lt;BR /&gt;{&lt;BR /&gt;ent.XData = data;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;return entitySet;&lt;BR /&gt;}&lt;BR /&gt;catch { return null; }&lt;BR /&gt;}&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 21:03:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393922#M39666</guid>
      <dc:creator>SoporteEspecializado</dc:creator>
      <dc:date>2022-08-31T21:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393965#M39667</link>
      <description>&lt;P&gt;It looks like you copy/paste code snippets you do not fully understand.&lt;/P&gt;
&lt;P&gt;You're opening the currents pace for write twice.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;(BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 31 Aug 2022 21:24:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393965#M39667</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-08-31T21:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393989#M39668</link>
      <description>&lt;PRE&gt;&lt;SPAN class=""&gt;Excuse me, I'm new to the world of programming and autocad, I try to learn as they ask me.&lt;/SPAN&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2022 21:39:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11393989#M39668</guid>
      <dc:creator>SoporteEspecializado</dc:creator>
      <dc:date>2022-08-31T21:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11394463#M39669</link>
      <description>&lt;P&gt;No need to apologize.&lt;BR /&gt;Assuming that you are new to AutoCAD programming, you should start with simple tasks so that you can write the code by yourself.&lt;BR /&gt;For example, in this case, don't try to do batch processing right away by using in-memory databases (with ReadDwgFile) to explode all entities in the current space of each.&lt;BR /&gt;Start by learning how to explode a single entity as I showed you. &lt;BR /&gt;Then try to write a method that exploses all the entities in the current space so you can test it in the current drawing. And only when you are satisfied that the method works, you can use it to do batch processing.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 05:17:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11394463#M39669</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-09-01T05:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11395499#M39670</link>
      <description>I followed your advice. I made some modifications and it worked.&lt;BR /&gt;Change the "ed.GetEntity"&lt;BR /&gt;by "ed.SelectAll()" which allowed me to make a selection to all the elements and add a filter so that it would only take the block reference that I needed to change Thanks for your help&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;[CommandMethod("XPLODETEST")]&lt;BR /&gt;public static void ExplodeTest()&lt;BR /&gt;{&lt;BR /&gt;var doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;var db = doc.Database;&lt;BR /&gt;var ed = doc.Editor;&lt;BR /&gt;&lt;BR /&gt;PromptSelectionResult pr = ed.SelectAll();&lt;BR /&gt;&lt;BR /&gt;if (pr.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;using (var tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;foreach (var id in pr.Value.GetObjectIds())&lt;BR /&gt;{&lt;BR /&gt;var entity = (Entity)tr.GetObject(id, OpenMode.ForWrite);&lt;BR /&gt;if (entity.GetType().Name == "BlockReference")&lt;BR /&gt;{&lt;BR /&gt;var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);&lt;BR /&gt;var entitySet = TryExplodeMaintainingXdata(entity);&lt;BR /&gt;if (entitySet != null)&lt;BR /&gt;{&lt;BR /&gt;foreach (Entity ent in entitySet)&lt;BR /&gt;{&lt;BR /&gt;curSpace.AppendEntity(ent);&lt;BR /&gt;tr.AddNewlyCreatedDBObject(ent, true);&lt;BR /&gt;entity.Erase();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;ed.WriteMessage("\nSelected entity cannot be exploded.");&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;tr.Commit();&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Sep 2022 14:52:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11395499#M39670</guid>
      <dc:creator>SoporteEspecializado</dc:creator>
      <dc:date>2022-09-01T14:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD C#: Modify Xdata value</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11395687#M39671</link>
      <description>&lt;P&gt;Happy to know you get it work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just some improvements to your code.&lt;/P&gt;
&lt;P&gt;If you use SelectAll, take care it select entities in all the layouts (model and paer spaces). A good practice with a selection is to use a SelectionFilter. In this case you should filter on the entity type (INSERT for block references and the current space).&lt;/P&gt;
&lt;P&gt;Do not make things in loops (foreach, for, while) if they could be done only once outside of the loop scope.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("XPLODETEST1")]
        public static void ExplodeTest1()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            // Create a filter to select all the block references in the current space
            string ctab = (string)Application.GetSystemVariable("CTAB");
            var filter = new SelectionFilter(new[] {
                new TypedValue(0, "INSERT"),
                new TypedValue(410, ctab) });
            PromptSelectionResult pr = ed.SelectAll(filter);

            if (pr.Status == PromptStatus.OK)
            {
                using (var tr = db.TransactionManager.StartTransaction())
                {
                    // Open the current space outside of the foreach loop
                    var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    foreach (var id in pr.Value.GetObjectIds())
                    {
                        // We know all entities within the selection set are block references
                        var blockRef = (BlockReference)tr.GetObject(id, OpenMode.ForWrite);
                        var entitySet = TryExplodeMaintainingXdata(blockRef);
                        if (entitySet != null)
                        {
                            foreach (Entity ent in entitySet)
                            {
                                curSpace.AppendEntity(ent);
                                tr.AddNewlyCreatedDBObject(ent, true);
                            }
                            // Erase the source block reference outside of the foearch loop
                            blockRef.Erase();
                        }
                        else
                        {
                            ed.WriteMessage("\nSelected entity cannot be exploded.");
                        }
                    }
                    tr.Commit();
                }
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of SelectAll, you could also directly iterate throug all the entities int the current space checking for the entity type to get only block references. This method is not slower than the SelectAll with filter which internally does the same thing.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("XPLODETEST2")]
        public static void ExplodeTest2()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                // Open the current space
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                foreach (ObjectId id in curSpace)
                {
                    // Check if the id is one of a block reference
                    if (id.ObjectClass.DxfName == "INSERT")
                    {
                        var blockRef = (BlockReference)tr.GetObject(id, OpenMode.ForWrite);
                        var entitySet = TryExplodeMaintainingXdata(blockRef);
                        if (entitySet != null)
                        {
                            foreach (Entity ent in entitySet)
                            {
                                curSpace.AppendEntity(ent);
                                tr.AddNewlyCreatedDBObject(ent, true);
                            }
                            // Erase the source block reference outside of the foreach loop
                            blockRef.Erase();
                        }
                        else
                        {
                            ed.WriteMessage("\nSelected entity cannot be exploded.");
                        }
                    }
                }
                tr.Commit();
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 01 Sep 2022 15:57:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-c-modify-xdata-value/m-p/11395687#M39671</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-09-01T15:57:56Z</dc:date>
    </item>
  </channel>
</rss>

