Autocad: (re)Create closed boundaries for all hatches

26.03.2013 - updated release, completely rewritten, major bugfixing

This Autolisp routine is intended primarily for a Dwg to Gis conversion. See if it fits your needs.

It recreates boundaries around all the hatch patterns in a drawing at once. The recreated boundaries are drawn in new layers and consist only of single closed polylines (interpreted as polygons by Gis applications). Each curved element of the boundary is converted to a segmented polyline and finally all these pieces are combined into one.
The outcome might be not identical to the original hatch outline, since it has to be considered as an approximation. Anyway, this is exactly the same process used by common desktop Gis when importing drawings.

Tested on Autocad 2012.

  • creates single closed polyline boundaries (Gis polygons)
  • assigns the hatch color to the boundary
  • draws in new layers called as the source layer of the hatch, plus a custom suffix
  • deletes or keeps all the previous associated boundaries
  • handles every kind of known geometry in a boundary (elliptic arcs, circles...)

Download bulk-recreate-hatch-boundaries.lsp

In Autocad, load it from Tools menu > AutoLISP > Load application
Usage: type BULKRHB in the command-line

Example (click on the images to enlarge)

Hatch on layer "0" (without boundary)

All the hatch outline pieces (HATCHGENERATEBOUNDARY command result)

(BULKRHB performed: 3 closed polylines on layer "0_BOUNDARIES")

The difference between HATCHGENERATEBOUNDARY and BULKRHB in ArcMAP

Geomedia: Useful functional attributes

Useful functional attributes expressions.
Arguments separator could be different according to your international settings.

  • Distance (projected) from point to point
    There might be a bug in the DISTANCE function in case of coincident points, so you better workaround like this:
  • LENGTH( CREATEPOLYLINE( pointgeometry_1 ; pointgeometry_2 ) ; 1 )

  • Add leading zeros
    examples to get a four-digit string like 0001, 0012, 0123
    • to a numeric field:
      TEXT( numericfield ; "0000" )
    • to a text field all filled with numeric strings:
      TEXT( VALUE( textfield ) ; "0000" )
    • to a text field:
      REPT( "0"; 4 - LEN( textfield ) ) + textfield

  • Trim leading zeros
    MID( textfield ; SEARCH( "[^0]" ; textfield ) )

  • Point projected coordinates
    • north:
      X( geometryfield ; 1 )
    • east:
      Y( geometryfield ; 1 )

  • Convert text geometry to point geometry
    ORIGIN( textgeometryfield )

  • In analytical merge, count those records that fulfill a specified where condition
    example: count all the records where field is less than 20
    SUM( IF( numericfield < 20 ; 1 ; 0) )

  • Casting a numeric value to text
    TEXT( textfield ; "" )
    Fundamentals of text formatting: put a "0" to get a digit-value or a 0; put a "#" to get a digit-value or nothing; add a section in the mask for negative values. Examples:
    TEXT( 2.715 ; "0.00"  ) returns "2.72"
    TEXT( 2.71  ; "0.000" ) returns "2.710"
    TEXT( 2.71  ; "0.###" ) returns "2.71"
    TEXT( -2.7  ; "0.###;-0.000" ) returns "-2.700"

  • Rotate a point or a label by an attribute value in degrees
    SPIN( {text}pointgeometryfield ; numericfield )

  • Create a linestring from rows of points aggregated by an attribute value
    Use Analytical merge for this. Select the By Attribute option and choose the discriminating attribute in the list below. Then edit the Geometry attribute in the Output functional attributes box clicking on Properties. Delete the default MERGE(Input.Geometry) and type
    CREATEPOLYLINE( pointgeometryfield ; numericfield )
    numericfield is an optional but recommended attribute to set the order of the point sequence