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.

Features:
  • 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

17 comments:

  1. non mi funziona su autocad 2012 English version...load da Tools e richiamo il comando ma la command line mi dice:
    "; error: no function definition: VLAX-GET-ACAD-OBJECT"

    ReplyDelete
  2. prova ad aggiungere:

    (vl-load-com)

    appena dopo i commenti e prima di (prompt...


    ciao

    ReplyDelete
  3. Grazie Toni per la risposta,
    ma non so utilizzare il codice e non saprei dove inserirlo, stavo provando soltanto a far girare la lisp con il load da Tools non so come editarlo...l'ho provato su un altro computer con un altro autocad e mi da lo stesso errore...

    ReplyDelete
  4. 6 un mostro funziona! :D grande!!!!
    ehehe...mi sto per laureare e ovviamente sto in panne...ma per caso nell'infinita vastità del tuo sapere "lisp-esco" è fattibile ricreare un bordo per ogni area chiusa che si crea semplicemente magari senza una tolleranza minuziosa? mi spiego meglio: lavorando giorni e giorni sullo stesso progetto e dando solo importanza al progetto più che al disegno, mi sono ritrovato con disegno che facendo il comando "boundary" non mi funzionava in tante aree perchè certe linee non si chiudevano ma non si vedevano, altre si estendevano e quindi cliccando dentro l'area dei muri mi dava errore...un pò meno me lo dava se facevo l'hatch, ma portandolo su rhino per fare il 3d mi fà gli estrusi solidi con piccoli artefatti. sai se si può automatizzare una procedura del genere di creazione di aree di polilinee o se esiste un modo più pulito per esportare aree fatte "male" in aree belle chiuse e sigillate cosicchè quando le estrudo funzionino? capisco che nn chiedo una cosa semplicissima, volevo sapere se riusciresti ad illuminarmi!
    grazie tanto...

    ReplyDelete
  5. nice lisp.
    i modified the lisp by inserting (vl-load-com)(gc)under function
    (defun c:BULKRHB())
    (vl-load-com)(gc)
    to avoid message error "error: no function definition: VLAX-GET-ACAD-OBJECT"

    thanks
    -zainul-

    ReplyDelete
    Replies
    1. where exactly did you paste this into the code? was it at the beginning after
      (defun c:BULKRHB (/ BP OLDCMDECHO LAYERSUFFIX HATCHSELECTSET COUNTER HATCHENTITY
      HATCHENTITYDATA NUMERICRGB STRINGRGB SOURCELAYER SOURCELAYERDATA
      TARGETLAYER COLORGROUP WHEREPOLICY VLADOCUMENT VLALAYERS
      OLDOSMODE OLDPELLIPSE CHECKGEOMETRY OLDDRAWORDERCTL) ?

      Delete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. Adam ZeitgeistVernon Bouzane has left a new comment on your post "Autocad: Recreate boundaries around all hatches":

      So nice!

      awesome routine!
      open source!
      Sharing information
      Tony from Italy Rocks!

      Delete
  7. there is a new command in autoCAD
    "hatchgenerateboundary" same routine as the "bulkrhb" LISP program.

    ReplyDelete
    Replies
    1. saved my day
      thnx
      /D

      Delete
    2. Hi Allan, you can better understand the difference between HATCHGENERATEBOUNDARY and BULKRHB in the description for the new release

      thank you

      Delete
  8. Hello everyone. I use a lot this command , but, in my company, not all computers has autocad 2015. Some licenses are autocad 2010 , and I can't perform this command in this version. Does anyone know if there is a similar command , or some adaptation of bulk for autocad 2010? Thanku you.

    ReplyDelete