回望南山
记忆痕迹可以鲜明, 回望往事如数家珍——
posts - 177,  comments - 54,  trackbacks - 0

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)))

  (progn

    (if (findfile "doslib2k.arx")

      (arxload "doslib2k")

    (progn

      (alert "DosLib not installed")

      (setq flag nil)

    );progn

   );if

  );progn

);if

;if DosLib is installed and loaded
(if flag 

;do the following
(progn

  ;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")) 

  );progn

 );if flag

  ;finish clean
  (princ)

);defun

;load clean
(princ)

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.

posted on 2008-03-29 21:02 深藏记忆 阅读(265) 评论(0)  编辑  收藏 所属分类: 舶来备忘转载Vlisp

飘过是缘,相识最真

订阅到抓虾
google reader
gougou


点击这里给我发消息


<2008年3月>
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(5)

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

八面来息

天天充电

同行者

积分与排名

  • 积分 - 58699
  • 排名 - 61

最新评论

阅读排行榜

评论排行榜