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

I received this from Andy Canfield :

Kenny,
    Since you are so nice I am attaching my super cool version of your function which allows an onclick event. Switches the direction of the slashes and produces a formatted link. Very cool.
Andy.

 

(defun C:Dwf-Html ( / flag thelist thedir nfiles
			thefile fn ctr dname flen
			len1 shortdname revSlash
			f_oldstr f_newstr f_string)
   
   ;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))
         
         ;need to reverse the slashes
         (setq f_oldstr "\\")
         (setq f_newstr "\/")
         (setq f_string thedir)
         (setq revSlash (replace f_oldstr 
			f_newstr f_string))
         
         ;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"))
         
         ;set the counter
         (setq ctr 0)
         
         ;start the loop
         (repeat nfiles 
            
            ;get the drawing name
            (setq dname (nth ctr thelist))
            
            ;get the length of the drawing name
            (setq flen (strlen dname))
            
            ;length of drawing name minus .dwf
			(setq len1 (- flen 4))
			
			;the drawing name minus .dwf
			(setq shortdname (substr dname 1 len1))
            
            ;create the HTML link
            (write-line (strcat "<a href=# onClick=" "\""
		"window.open(" "'" "file:" revSlash dname "'" ",
		'modifications','toolbar=no,menubar=no,
		status=yes,resizable=yes,scrollbars=yes,
		width=800,height=600'); return false;
		" "\"" ">" shortdname "</a><br>") fn)
            
            ;increment the counter
            (setq ctr (1+ ctr))
            
         );end repeat
         
         ;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)

;the following function was Written By Michel Loftus
(defun replace (f_oldstr f_newstr 
		f_string / f_cur f_loop)
;like subst but with strings not lists
  (if (null (and (stringp f_oldstr)
		 (stringp f_newstr)
		 (stringp f_string)
	    )
      )
    (exit)
  )
  (if (> (strlen f_oldstr) (strlen f_string))
    (exit)
  )
  (setq f_loop 1)
  (repeat (strlen f_string)
    (progn
      (setq f_cur (substr f_string f_loop 
	(strlen f_oldstr)))
      (if (= f_cur f_oldstr)
	(setq f_string (strcat (substr f_string 1 (- f_loop 1))
			       f_newstr
			       (substr f_string
				       (+ f_loop (strlen f_oldstr))
				       (strlen f_string)
			       )
		       )
	)
      )
      (setq f_loop (1+ f_loop))
    )
  )
  f_string
)
;eg (replace "\t" " " "Line one\tLine two") = "Line one Line two"

;the following function was Written By Michel Loftus
(defun stringp (f_val) ;test if a string
  (if (= (type f_val) 'STR)
    t
    nil
  )
)
;eg (stringp "Hello") = true

Download Source Coding Here

 
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