Is it possible to loop through multiple files in a directory?
Like this:
(setq file (open "..\\TOPO QUADS\\*.jgw" "r"))
Read about the function vl-directory-files and just shot if you need any help with your code .
Tharwat
(defun C:TileTopo() (vl-load-com) (setq intFileDia (getvar "filedia")) ;get current filedia sysvar - store it (setq pt1 (getpoint "\n Pick a Point to add Quadrangle: ")) ;get point from user (setq x1 (car pt1)) (setq y1 (cadr pt1)) (setq ax1 1) (setq ay1 1) (setq bx1 2) (setq by1 2) (setq file (list (vl-directory-files "C:/TOPO QUADS" "*.jgw"))) (while (cond (and (> x1 ax1)(< x1 bx1)) (and (< y1 ay1)(> y1 by1));pretty sure this not how this is done ) (setq ofile (open file "r"));this isn't working - figure out how to sequence through files in list (setq ax1 (nth 4 ofile)) (setq ay1 (nth 5 ofile)) (close ofile) (setq bx1 (+ ax1 3415)) (setq by1 (- ay1 4554)) ) ;(setvar "filedia" 0) ;turn filedia off ;TODO - convert file name to the equivalent jpg file name and import it. ;(command "-mapimport" "" fileLOC "n" "p") ;run the map import command ;(setvar "filedia" intFileDia) ;turn the filedia back to original setting )
ok Tharwat, you put me on a good path...I'm afraid I'm just too green with this stuff to get much further. Any help finishing this up or getting it further along will be appreciated. I'm simply trying to load quadrangles into the drawing based on point user clicks. I realize the direction I'm heading may not work perfectly due to rotation etc, but I think it should be close. I'm trying to learn here so teach me to fish. 🙂 Thanks!
Consider this as an example ...
(foreach x (vl-directory-files "C:/TOPO QUADS" "*.jgw" 1) (print x) )
Tharwat
Note: this could possibly lock up.
(defun C:TileTopo() (vl-load-com) (setq intFileDia (getvar "filedia")) ;get current filedia sysvar - store it (setq pt1 (getpoint "\n Pick a Point to add Quadrangle: ")) ;get point from user (setq x1 (car pt1)) ;pull x coordinate (setq y1 (cadr pt1)) ;pull y coordinate (setq ax1 1) ;establish point for upper left corner of topo (setq ay1 1) ;establish point for upper left corner of topo (setq bx1 2) ;establish point for lower right corner of topo (setq by1 2) ;establish point for lower right corner of topo (while (cond (and (> x1 ax1)(< x1 bx1)(and(< y1 ay1)(> y1 by1))));i don't think this is correct (foreach file (vl-directory-files "C:/TOPO QUADS" "*.jgw" 1) ;get all of the world files in the topo directory (setq path (strcat "C:/TOPO QUADS/" file)) (setq ofile (open path "r"));open the file and read the contents (read-line ofile) (read-line ofile) (read-line ofile) (read-line ofile) (setq ax1 (read-line ofile)) (setq ay1 (read-line ofile)) (close ofile) (setq bx1 (+ (atoi ax1) 3415)) (setq by1 (- (atoi ay1) 4554)) (print (strcat file " - " ax1 ", " ay1 " - " (itoa bx1) ", " (itoa by1)));THIS IS JUST TESTING WITH OUTPUT RIGHT NOW - REMOVE LATER ) ) ;(setvar "filedia" 0) ;turn filedia off ;TODO - convert file name to the equivalent jpg file name and import it. ;(command "-mapimport" "" fileLOC "n" "p") ;run the map import command ;(setvar "filedia" intFileDia) ;turn the filedia back to original setting (princ) )
Ok, inching along. I can now cycle through the files and set the variables. But it is locking up after it gets through so many of them, and I don't think I have the while and condition quite right.
Please upload a sample file , both the data and the DWG how do you want to do it.
world file are available all over. You can download them freely. Here are some for Pennsylvania: http://www.pasda.psu.edu/data/drg24k-c/ these are tif files with a tfw world file...same thing as jpg with a jgw.
There isn't really a sample file...the lisp just (is suppposed to) loads one of these maps (mapiinsert - civil3d) if you click within the area where it should be displayed.