Author Topic: Edit xdata value  (Read 3158 times)

0 Members and 1 Guest are viewing this topic.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Edit xdata value
« on: June 30, 2008, 07:40:58 PM »
I am stuck trying to edit an xdata value.
For example:
I have a registered app ("CES") and a string (1000) xdata value ("Happy")
I would like to change "Happy" to "Sad".

This is easy enough with only one value to change, I just create a new ResultBuffer with the registered app and xdata TypedValues. (of course that's not really any good if you have other apps xdata in the object)

The problem is I have a list (of string type xdata) more like:
"IamHappy"
"YouareHappy"
"TheyareHappy"
"SheisHappy"
"WeareHappy"

and I want to change "SheisHappy" to "SheisSad".

If I iterate the TypedValues in ResultBuffer I can find "SheisHappy" but if I try to set the Value of that TypedValue I get a "Read Only" error. (yes the object is opened ForWrite)

For example:
Code: [Select]
ResultBuffer rb = myObj.XData;
foreach (TypedValue tval in rb)
{
   if (tval.TypeCode == 1000)
   {
      if (tval.Value.ToString() == "SheisHappy")
         {
            tval.Value = "SheisSad";
         }
   }
}

I've tried creating a new ResultBuffer and copying each element from the old to the new passing in the changed value.
Problem is if you use the Add method of the ResultBuffer the value is added to the top of the list and your reg app is in the wrong place.

I read Tonys post showing a way to build an xdata list but I don't see how it will help me edit a value.

Any help would be appreciated.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Edit xdata value
« Reply #1 on: June 30, 2008, 10:19:01 PM »
If you just get the entities xdata you get every applications xdata (a linked list of linked lists if I remember), if you use "GetXDataForApplication" you should only get your xdata with your app name, try that and loop into your code to the point/item you want to change.
hth.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8723
  • AKA Daniel
Re: Edit xdata value
« Reply #2 on: July 01, 2008, 10:48:48 AM »
I don’t think you can edit the value in TypedValue this way. You should instead, create a new TypedValue object to replace the old one. Get the Xdata from the entity, convert the Resultbuffer into a List<TypedValue>, replace the TypedValue, convert the List<TypedValue> back to a ResultBuffer, set the xdata with your new buffer.

Clear as mud?

To make things easier, do a search in this forum for TypedValueList. This class has implicit operators that help do these conversions

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Edit xdata value
« Reply #3 on: July 01, 2008, 02:28:42 PM »
I don’t think you can edit the value in TypedValue this way. You should instead, create a new TypedValue object to replace the old one. Get the Xdata from the entity, convert the Resultbuffer into a List<TypedValue>, replace the TypedValue, convert the List<TypedValue> back to a ResultBuffer, set the xdata with your new buffer.

Clear as mud?

To make things easier, do a search in this forum for TypedValueList. This class has implicit operators that help do these conversions

I used the TypedValueList class as posted by Tony T. and did as you suggested.
SUCCESS!!!
Thank you all.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions