AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

AutoCAD and HTML - Page III

Time for another wee bit of a break for me. By sleuth of hand and the use of threats to various appendages stuck on his body, I finally conned someone else into writing the next section for me. Say hi to David Stein everyone, ("Hi Dave!!")
If you don't know Dave, well he is the gentleman responsible for "DSX Tools" and the "Visual Lisp Bible." You can find his new permanent home at http://www.dsxcad.com. Pop along as it's well worth the visit. (just check for your wife and wallet when you leave.)

Okey dokey. Dave is the author of this nice little program written using Visual Lisp that will not only write the Layer Names to an HTML file, but will also write the Layer properties and status. Let's have a look at the coding.

Copy and paste this into Notepad and save it as "DumpLayers.lsp."

;; This example involves the task of producing an HTML report of all
;; layers in the current drawing, including their properties (color, linetype, etc.)
;; and opening the report in a web browser after completion.
;; When loaded, the command is DUMPLAYERS.


(defun C:DUMPLAYERS
( / acad doc dwg layers name col ltp lwt pst onoff frz dat
path olist outfile output)

;load the VL extensions
(vl-load-com)

;get reference to AutoCAD
(setq acad (vlax-get-acad-object)

          ;reference the drawing
          doc (vla-get-activedocument acad)

          ;get the drawing name
          dwg (vla-get-name doc)

         ;get the drawing path
         path (vla-get-path doc)

      ;get the layers cpllection
      layers (vla-get-layers doc)

);setq

;process each layer
(vlax-for each layers

     ;get the layer name
     (setq name (vla-get-name each)

                ;get the layer color
                 col (itoa (vla-get-color each))

                ;get the linetype
                ltp (vla-get-linetype each)

                ;get the lineweight
                lwt (itoa (vla-get-lineweight each))

                ;get the plotstyle
                pst (vla-get-plotstylename each)

                ;on-off status
                onoff (if (= :vlax-true (vla-get-layeron each))
                "ON" "OFF")

               ;frozen-thawed status
               frz (if (= :vlax-true (vla-get-freeze each))
              "FROZEN" "THAWED")

              ;list them
              dat (list name col ltp lwt pst onoff frz)

              ;add to main list
              olist (cons dat olist)

    );setq

); vlax-for

;release all objects
(vlax-release-object layers)
(vlax-release-object doc)
(vlax-release-object acad)

;create the HTML file
(cond
  ( olist
    (setq outfile (strcat (vl-filename-base dwg) ".htm"))
    (setq outfile (strcat path outfile))
     (cond
        ( (setq output (open outfile "w"))
        (write-line "<html>" output)
        (write-line "<head><title>" output)
        (write-line (strcat "Layer Dump: " dwg) output)
        (write-line "</title></head><body>" output)
        (write-line (strcat "<b>Drawing: " dwg "</b><br>") output)
        (write-line "<table border=1>" output)
           (foreach layset olist
              (write-line "<tr>" output)
          (foreach prop layset
              (write-line (strcat "<td>" prop "</td>") output)
          )
         (write-line "</tr>" output)
          ); foreach layer set
         (write-line "</table></body></html>" output)
         (close output)
         (setq output nil)

   ;inform the user
   (princ "\nReport finished! Opening in browser...")

   ;open the HTML report in the browser
   (vl-cmdf "_.browser" outfile)
  )

  ( T (princ "\nUnable to open output file.") )
 )
 )
 ( T (princ "\nUnable to get layer table information.") )
 ) 
);defun

(princ)

Load and run this routine. The HTML file should automatically open in your browser.
Hey, is that not nice? All your layers, layer properties and status all nicely tabulated in a report! By the way, if you are not very clued up on Visual Lisp, there are a whole set of Tutorials posted on AfraLisp that you can use to familiarise yourself with this powerful addition to the AutoLisp language.

Okay, one more page to go. (phew.)
Now let's look at AutoCAD and HTML using Visual Basic. (Oooh, I can hear you say.)

 
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright © 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website