Autolisp part II - convert drawing to grayscale skeleton

For my second Autolisp job, I was tasked to convert a drawing to a grayscale skeleton so that it could be used as a background for additional drawings.  This is typical of floor plans that are developed by one company, then another company overlays electrical, air conditioning or other building services over top of the floor plan.

acadpartii

This involves converting all the colours in the drawing to gray, setting all the fonts, line weights and line styles to a consistent style, deleting all hatches, removing all xrefs, fixing and drawing errors, and purging all unused items. This turned out to be much easier than I thought it was going to be, with the vast bulk of these things being achievable using basic Autocad commands.

(vl-load-com)
(defun C:HatchKiller (/ b o)
  ;;--- Tharwat 26.June.2013 ---;; 
  (or doc
    (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  )
  (vlax-for b
    (vla-get-blocks
      doc
    )
    (if
      (and
        (eq :vlax-false (vla-get-isLayout b))
        (eq :vlax-false (vla-get-isXref b))
      )
      (vlax-for o b
        (if (eq "AcDbHatch" (vla-get-objectname o))
          (vl-catch-all-apply 'vla-delete (list o))
        )
      )
    )
  )
  (vla-regen doc acAllViewports)
  (princ)
)

;;double offset with offset line style change
(defun C:cleanthatdirtydrawing(/ hatches text dims)
  (command "_.Undo" "BE") 
  (command "_.setbylayer" "all" "" "y" "y")
  (command "_.-layer" "color" "253" "*" "")
  (command "_.-layer" "LWeight" "0.0" "*" "") 
  (princ "Do Hatches")
  (setq hatches (ssget "_X" '((0 . "HATCH"))))
  (if hatches
    (command "_.erase" hatches "")
  )
  (setq text (ssget "_X" '((0 . "TEXT,MTEXT,MLEADER"))))
  (if text
    (command "_.optchprop" text "" "Textstyle" "ISO CP" "")
  )
  (setq dims (ssget "_X" '((0 . "DIMENSION"))))
  (if dims
    (command "_.optchprop" dims "" "DimStyle" "ISO CP" "")
  )
  (C:HatchKiller)
  (command "_.-xref" "unload" "*")
  (command "_.-xref" "detach" "*")
  (command "_.purge" "all" "*" "n")
  (command "_.audit" "y")
  (command "_.Undo" "END")
  (princ)
)


| October 29th, 2014 | Posted in Software |

Leave a Reply