I am creating an AutoCAD plug.
what it does is that it draw some blocks and attach some additional information with it. such as length, weight, supplier etc.
I am achieving this with Xrecord and Extension Dictionaries.
when I am about to read it, I am able to get the result buffer from codes below.
My question is how do i indexing one of the values. such as supplier from the result buffer.
Using trans As Transaction = db.TransactionManager.StartTransaction Dim objEnt As Entity = trans.GetObject(resEnt.ObjectId, OpenMode.ForRead) Dim rb As ResultBuffer = objEnt.GetXDataForApplication("Test") ... End Using
Solved! Go to Solution.
Solved by dgorsman. Go to Solution.
Solved by Keith.Brown. Go to Solution.
What I do is create a class for each resultbuffer object that i create. For instance, consider the class below. You can use it to read/write data to/from xdata on an entity.
Please note I wrote the code from memory and have not tested it or done adequate error checking. It is only meant as a starting block for your own code.
internal class GenericXData { internal GenericXData(Entity entity) { ResultBuffer rb = entity.GetXDataForApplication("GenericXData"); if (rb == null) { this.XDataExists = false; return; } TypedValue[] data = rb.AsArray(); this.PropertyOne = (string)data[1].Value; this.PropertyTwo = (string)data[2].Value; } internal bool XDataExists {get; set;} = true; internal string PropertyOne { get; set; } = string.Empty; internal string PropertyTwo { get; set; } = string.Empty; internal ResultBuffer GetResultBuffer() { ResultBuffer buffer = new ResultBuffer(); buffer.Add(new TypedValue(ExtendedDataRegAppName, "GenericXData")); buffer.Add(new TypedValue(ExtendedDataAsciiString, this.PropertyOne)); buffer.Add(new TypedValue(ExtendedDataAsciiString, this.PropertyTwo)); return buffer; } } // How to use GenericXData data = new GenericXData(entity); string supplier = data.PropertyOne;
data.PropertyOne = "New Supplier";
entity.XData = data.GetResultBuffer();
I reread your original post and saw that you were using xrecords and extension dictionaries. While not Xdata, the concept should be the same for you.
Two methods. The first is everything is always at the same index; not a huge deal since you would write the code to generate it this way. The other is to use separate xrecords for each labeled piece of data; as xrecords are named items you can look them up from the containing dictionary. For example, the length property might be in an xrecord named "Length", and would contain one real value.
Can't find what you're looking for? Ask the community or share your knowledge.