Querying the AutoCAD Document

Read from the drawing — get hold of objects that already exist, inspect them, and select them with filters.


Bringing an AutoCAD object into Grasshopper

The most direct way to get existing AutoCAD geometry into a definition is to reference it with a parameter:

  1. From the Params ▸ AutoCAD group, drop the parameter for the type you want onto the canvas — for a hatch, the AutoCAD Hatch param.
  2. Right-click the param and choose Set One AutoCAD Hatch (or Set Multiple AutoCAD Hatches to pick several).
  3. Grasshopper hands control to AutoCAD — click the hatch in the drawing to select it.
  4. The param now holds a live reference to that object, which you can wire into the rest of your definition.

This is the interactive, one-object-at-a-time counterpart to the filter-based querying further down — ideal when you just want to grab a specific object you can see.

Referencing an AutoCAD hatch into Grasshopper with Set One AutoCAD Hatch Dropping an AutoCAD Hatch param, choosing "Set One AutoCAD Hatch", and picking the hatch in the drawing.

Everything defaults to the active document

You'll notice that many AutoCAD components have a Document (Doc) input, and that it's optional. If you leave it empty, the component automatically uses the currently active AutoCAD document. You only need to wire a Document in when you want to target a specific, non-active drawing.

If you do need to work with documents explicitly, the AutoCAD Document component (AC-Doc, AutoCAD ▸ Document) decomposes a document into properties such as its file name, file path, read-only state, and whether it's the active document.

The DBObject component

Every object in an AutoCAD drawing — a line, a block reference, a layer, a hatch — is ultimately a DBObject. The AutoCAD DBObject component (AC-DbObj, AutoCAD ▸ Document) takes advantage of this: feed it almost any AutoCAD object (or its Id) and it extracts the common properties they all share, including:

  • the object's Type,
  • its Layer (name and Id),
  • its Color, Material (name and Id), and Linetype (name and Id),
  • its Extension Dictionary Id (the attached-data dictionary mentioned in AutoCAD-Native Types).

Because it works at the DBObject level, it's a handy general-purpose inspector for whatever you've pulled out of the drawing, without needing a type-specific component for every case.

Filters — selecting what you want

To pull objects out of the drawing you use the Get AutoCAD Objects By Filter component (AC-GetByFilter, AutoCAD ▸ Filter). It takes an optional Document (active by default), a Filter describing what to select, and an optional Limit (default 100; use 0 for unlimited), and returns the matching Objects and a Count.

The filter itself is where you say what to fetch.

The default (geometry-type) filter. The simplest filter selects by object type. Drop the AutoCAD Geometry Filter Type value list (AutoCAD ▸ Filter), pick a type — Curve, Point, Mesh, Solid, Hatch, Text, Block, Layer, and so on — and wire it into the Filter input. (You can even type the name as plain text; it's converted to the matching filter for you.) This single-type filter covers most everyday queries, like "give me every curve in the drawing."

Composite filters. When one type isn't enough, combine filters:

  • And Filter (AC-AndFilter) — matches objects that satisfy both Filter A and Filter B.
  • Or Filter (AC-OrFilter) — matches objects that satisfy either Filter A or Filter B.

Because each combiner outputs a single filter, you can chain them — feed the output of one And/Or into another — to build up as specific a selection rule as you need. There's also a Layer Filter (AC-LayerFilter) to match everything on a given layer, and, for advanced cases, a Create Custom Filter (AC-CustomFilter) that builds a filter from raw DXF filter rules.

A geometry-type filter and an And/Or composite filter feeding Get AutoCAD Objects By Filter A simple geometry-type filter (left) and a composite And/Or filter, both feeding the Get AutoCAD Objects By Filter component.