Author Topic: Modifying XData  (Read 2362 times)

0 Members and 1 Guest are viewing this topic.

tik

  • Guest
Modifying XData
« on: April 12, 2013, 02:03:01 PM »
Please someone help me understanding this bizarre behavior with modifying XData. I have a list of ObjectIds, I want to modify the XData for all the entities with those ObjectIds. This is where I am having trouble, to modify the XData I loop through the list of object ids, open the corresponding entity inside a transaction change the XData for each entity but XData is not getting changed and also I am not seeing exceptions or error. 

To make things complicated if I use the following code(copied from a different question in this forum) it works. I verified that object ids are same, only difference here I select a single entity from the drawing. I also tried passing my ObjectId as parameter to the following function instead of selecting an entity and it wont work.

Does anyone saw this kind of behavior before or am I missing very simple and obvious.

Thanks in advance.

Tik.

<code>
public void PutXData()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            var resEnt = ed.GetEntity("Select a Entity");
            if (resEnt.Status == PromptStatus.OK)
            {

                using (var tr = db.TransactionManager.StartTransaction())
                {

                    Entity ent = tr.GetObject(resEnt.ObjectId, OpenMode.ForWrite) as Entity;
                    var rb = ent.GetXDataForApplication("AQME");
                   
                    //List<TypedValue> values = rb.AsArray().ToList<TypedValue>();
                    //values[1] = new TypedValue(1000, "value" + values.Count.ToString());

                    List<TypedValue> DataArray = new List<TypedValue>();
                    DataArray.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "MyApp")); //0
                    DataArray.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "1010-BLACK"));//1
                    DataArray.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "1010-BLACK Description"));//2

                    ent.XData = new ResultBuffer(DataArray.ToArray());                   

                    tr.Commit();
                }
            }
        }

</code>
« Last Edit: April 12, 2013, 02:07:01 PM by tik »

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Modifying XData
« Reply #1 on: April 12, 2013, 02:36:07 PM »
Instead of posting what did work, could you add what didn't?

tik

  • Guest
Re: Modifying XData
« Reply #2 on: April 12, 2013, 02:45:52 PM »
The code wont work if I remove the GetEntity() and pass an objectId directly.

TheMaster

  • Guest
Re: Modifying XData
« Reply #3 on: April 12, 2013, 02:54:16 PM »
The code wont work if I remove the GetEntity() and pass an objectId directly.

Is the application name for the Xdata ("MyApp" in your example) registered ?

tik

  • Guest
Re: Modifying XData
« Reply #4 on: April 12, 2013, 03:18:44 PM »
TT,

Ya it is registered.

TheMaster

  • Guest
Re: Modifying XData
« Reply #5 on: April 13, 2013, 08:40:59 AM »
The code wont work if I remove the GetEntity() and pass an objectId directly.

I think you need to show the actual code that doesn't work. And, what exactly happens (an error or the XData isn't being attached) ?