What is a Result Buffer Data Type? (AutoCAD .net API)

A physical representation of a Result Buffer outside the world of ObjectARX. hahha.
A physical representation of a Result Buffer outside the world of ObjectARX. hahha.

Unfortunately, and unsurprisingly, the documentation is a little sparse on this point. But somewhere deep within the annals of the AutoCAD documentation I found this little beauty:

Here is the documentation. But for you folks who may find that the link does not work, I will also copy and paste verbatim, what is said there:

The ResultBuffer type is a class that mirrors the resbuf struct defined in the ObjectARX SDK. The resbuf struct provides a flexible container for AutoCAD-specific data.

An Autodesk.AutoCAD.DatabaseServices.ResultBuffer class object is used in much the same way as a resbuf chain. You define a ResultBuffer and populate it with a sequence of data pairs. Each pair contains a data type description and a value. In the managed API, these data pairs are instances of theAutodesk.AutoCAD.DatabaseServices.TypedValue class. This utility class serves the same purpose as the restype and resval members of the resbuf struct.

The TypedValue.TypeCode property is a 16-bit integer value that indicates the TypedValue.Value property’s data type. Acceptable TypeCode values depend on the specific use of aResultBuffer instance. For example, TypeCode values that are suitable for an xrecord definition are not necessarily appropriate for xdata. TheAutodesk.AutoCAD.DatabaseServices.DxfCode enum defines codes that accurately describe the full range of possible ResultBuffer data types.

The TypedValue.Value property maps to an instance of System.Object, and theoretically may contain any type of data. However, the Value data must conform to the type indicated by TypeCode to guarantee usable results.

You can prepopulate a ResultBuffer by passing an array of TypedValue objects to its constructor, or you can construct an empty ResultBuffer and later call theResultBuffer::Add() method to append new TypedValue objects. The following example shows a typical ResultBuffer constructor usage:

using (Xrecord rec = new Xrecord())

{

rec.Data = new ResultBuffer(

new TypedValue(Convert.ToInt32(DxfCode.Text), “This is a test”),

new TypedValue(Convert.ToInt32(DxfCode.Int8), 0),

new TypedValue(Convert.ToInt32(DxfCode.Int16), 1),

new TypedValue(Convert.ToInt32(DxfCode.Int32), 2),

new TypedValue(Convert.ToInt32(DxfCode.HardPointerId), db.BlockTableId),

new TypedValue(Convert.ToInt32(DxfCode.BinaryChunk), new byte[] {0, 1, 2, 3, 4}),

new TypedValue(Convert.ToInt32(DxfCode.ArbitraryHandle), db.BlockTableId.Handle),

new TypedValue(Convert.ToInt32(DxfCode.UcsOrg),

new Point3d(0, 0, 0)));

}

What does all this mean?

I can’t justify an entire post without adding some degree of value: let’s try simplify its meaning a little more. Basically, result buffers are like CLR dictionaries: they are made up of a series of TypedValue objects. These TypedValue objects are like Key-Value pairs which you can fill with different types of data (i.e. AutoCAD data), or even non-AutoCAD data. The values you can use for the Key (in a TypedValue object) are basically that which are specified as DxfCode values.

Result Buffers are:

  • Made of TypedValue objects.
    • Typed value objects are like Key Value pairs
      • Where the key of the TypedValue is a DxfCode and
      • The value of the TypedValue is any AutoCAD type which corresponds to the DxfCode set as the key.

I hope that’s making some degree of sense? It will be a sad day if such an explanation obfuscates what is written in the documentation (where it exists) to a greater degree than the documentation itself. Anyways, I do hope it helps.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *