This post was inspired by an email I saw from Philippe Leefsma, from DevTech EMEA, which made use of the Autodesk.AutoCAD.Windows.Data namespace – something I didn’t even know existed.
The specific example Philippe showed was how to access the list of hatch patterns available in the current drawing without iterating through the relevant dictionary in the named objects dictionary.
Here’s Philippe’s C# code:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows.Data;
public class DataStuff
{
[CommandMethod("HPS")]
static public void GetHatchPatterns()
{
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
foreach (
string str in HatchPatterns.Instance.AllPatterns)
ed.WriteMessage("\n" + str);
}
}
When we run it, we see the following output at the command-line:
Command: HPS
SOLID
ANGLE
ANSI31
ANSI32
ANSI33
ANSI34
ANSI35
ANSI36
ANSI37
ANSI38
AR-B816
AR-B816C
AR-B88
AR-BRELM
AR-BRSTD
AR-CONC
AR-HBONE
AR-PARQ1
AR-RROOF
AR-RSHKE
AR-SAND
BOX
BRASS
BRICK
BRSTONE
CLAY
CORK
CROSS
DASH
DOLMIT
DOTS
EARTH
ESCHER
FLEX
GOST_GLASS
GOST_GROUND
GOST_WOOD
GR_LINEAR
GR_CYLIN
GR_INVCYL
GR_SPHER
GR_HEMISP
GR_CURVED
GR_INVSPH
GR_INVHEM
GR_INVCUR
GRASS
GRATE
GRAVEL
HEX
HONEY
HOUND
INSUL
ACAD_ISO02W100
ACAD_ISO03W100
ACAD_ISO04W100
ACAD_ISO05W100
ACAD_ISO06W100
ACAD_ISO07W100
ACAD_ISO08W100
ACAD_ISO09W100
ACAD_ISO10W100
ACAD_ISO11W100
ACAD_ISO12W100
ACAD_ISO13W100
ACAD_ISO14W100
ACAD_ISO15W100
LINE
MUDST
NET
NET3
PLAST
PLASTI
SACNCR
SQUARE
STARS
STEEL
SWAMP
TRANS
TRIANG
ZIGZAG
USER
I was curious about this namespace and so asked around to find out more about its origins. Apparently it was introduced to provide simplified access to data that needs to be displayed in the AutoCAD user interface: we expose this data through Autodesk.AutoCAD.Windows.Data to make it simpler to implement the ribbon without having to iterate database objects there directly. What’s nice is the data changes when the connected database does: whether relevant items are added to, edited in or removed from the database, or the user changes the currently active drawing in the editor, the data made accessible is adjusted accordingly.
This capability is known internally as the BOL or Bindable Object Layer. Cool stuff.
At this stage, I didn’t find a way to access other data from this namespace: HatchPatterns is the only class with a static Instance property that provides access to it. There is a very interesting DataBindings class, that appears to provide access to the data in the rest of the namespace, but I so far have been unable to find a way to instantiate (or retrieve an existing instance of it).