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 II

This time we're going to have a look at creating an HTML file that lists a directory of DWF drawings using AutoLisp. To select the DWF files and the relevant directory, we are going to make use of a very powerful DosLib function "dos_filem." Oh, before I forget, you will need to have the DosLib library installed on your workstation. If you don't have DosLib, you can download the latest version from Robert McNeel & Associates.

I'd like to thank Andy Canfield(Cornbread) for his ideas and input into this routine. Andy wrote about 90% of this program and in fact, gave me the initial idea for this article. I've changed a couple of things and tidied it up for publishing, but Andy did the major work. Any errors or typos are from my desk.
Right, enough waffle, lets get on with it. Copy and paste this into Notepad and then save it as "Dwf-Html.lsp."

(defun C:Dwf-Html ( / flag thelist thedir nfiles thefile fn ctr dname)

;set the flag
(setq flag T)

;check Doslib is loaded
(if (not (member "doslib2k.arx" (arx)))


    (if (findfile "doslib2k.arx")

      (arxload "doslib2k")


      (alert "DosLib not installed")

      (setq flag nil)





;if DosLib is installed and loaded
(if flag 

;do the following

  ;select the DWF files
  (setq thelist (dos_getfilem "Select Drawings" 
                             "C:\\" "DWF Files (*.dwf)|*.dwf"))

  ;retrieve the directory
  (setq thedir (car thelist))

  ;retrieve the file names
  (setq thelist (cdr thelist))

  ;get the number of files
  (setq nfiles (length thelist))

  ;create the HTML file
  (setq thefile (strcat thedir "Dwf-Html.html"))

  ;open the HTML file
  (setq fn (open thefile "w"))

  ;write the header information
  (write-line "<html><head>
                    <title>AutoCAD and HTML</title>
                    </head><body>" fn)

  ;give it a title
  (write-line "<h1>AutoCAD and HTML</h1><hr>" fn)

  ;set the counter
  (setq ctr 0)

  ;start the loop
  (repeat nfiles 

      ;get the drawing name
      (setq dname (nth ctr thelist))

      ;create the HTML link
      (write-line (strcat "<a href =" "\"" 
                                  thedir dname "\"" ">" thedir dname "
                                  </a><br>") fn)

      ;increment the counter
      (setq ctr (1+ ctr))

  );end repeat

  ;write the HTML footer
  (write-line "<hr><h3>Brought to you by CAD Encoding</h3>
                    </body></html>" fn)

  ;close the file
  (close fn)

  ;inform the user
  (alert (strcat "File saved as" "\n" thedir "Dwf-Html.html")) 


 );if flag

  ;finish clean


;load clean

Now, load and run this routine.
A file dialog will appear. Choose the directory your DWf files are located in, and then select the DWF files you would like listed in the HTML report.
The HTML file will be created and stored in the same directory as your DWF files and will be named "Dwf-Html.html." Open this file in your browser. You should have a list of links to all the DWF files you selected.

As I mentioned earlier, we make use of the DosLib function "dos_filem" to allow the user to select the DWF files that he/she/it wants to process.
The "dos_filem" function
displays a file open dialog box that allows for multiple file selection. The function returns a list of filenames if successful. The first element of the list is a qualified path to the selected directory. eg.

(setq thedir (car thelist))

returns the file directory and 

(setq thelist (cdr thelist))

returns a list of file names. Do yourself a favour and read the help file that comes with DosLib as you'll find a lot of useful functions that will make your AutoLisp coding a lot easier.

Right, now let's have a look at doing something with HTML using Visual Lisp.

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