.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to indexing a ResultBuffer in VB.NET or C#

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
ilovejingle
2248 Views, 5 Replies

How to indexing a ResultBuffer in VB.NET or C#

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
5 REPLIES 5
Message 2 of 6
Keith.Brown
in reply to: ilovejingle

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();
Message 3 of 6
Keith.Brown
in reply to: ilovejingle

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. 

Message 4 of 6
dgorsman
in reply to: ilovejingle

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.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 5 of 6
ilovejingle
in reply to: Keith.Brown

Thank you very much.

Message 6 of 6
ilovejingle
in reply to: dgorsman

Thank you for replying.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost