Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Read from multiple external files?

9 REPLIES 9
Reply
Message 1 of 10
Golfball2k6
566 Views, 9 Replies

Read from multiple external files?

Is it possible to loop through multiple files in a directory?

 

Like this:

 

(setq file (open "..\\TOPO QUADS\\*.jgw" "r"))

 

Doug
Windows 7 x 64 Professional
Nvidia Quadro 4000
8 GB Ram
i5 2500 @ 3.30 GHz
Civil 3D 2012 SP 2
Civil 3D 2013 SP 1
9 REPLIES 9
Message 2 of 10
patrick_35
in reply to: Golfball2k6
Message 3 of 10
_Tharwat
in reply to: Golfball2k6

Read about the function vl-directory-files and just shot if you need any help with your code .

 

Tharwat

Message 4 of 10
devitg
in reply to: Golfball2k6

To do what?? Yes it can be do
Message 5 of 10
Golfball2k6
in reply to: _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!

Doug
Windows 7 x 64 Professional
Nvidia Quadro 4000
8 GB Ram
i5 2500 @ 3.30 GHz
Civil 3D 2012 SP 2
Civil 3D 2013 SP 1
Message 6 of 10
_Tharwat
in reply to: Golfball2k6

Consider this as an example ...

 

(foreach x (vl-directory-files "C:/TOPO QUADS" "*.jgw" 1)
  (print x)
)

 Tharwat

Message 7 of 10
Golfball2k6
in reply to: _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. 

Doug
Windows 7 x 64 Professional
Nvidia Quadro 4000
8 GB Ram
i5 2500 @ 3.30 GHz
Civil 3D 2012 SP 2
Civil 3D 2013 SP 1
Message 8 of 10
devitg
in reply to: Golfball2k6

Please upload a sample file , both the data and the DWG how do you want to do it.

 

Message 9 of 10
Golfball2k6
in reply to: devitg

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.

Doug
Windows 7 x 64 Professional
Nvidia Quadro 4000
8 GB Ram
i5 2500 @ 3.30 GHz
Civil 3D 2012 SP 2
Civil 3D 2013 SP 1
Message 10 of 10
devitg
in reply to: Golfball2k6

So you will work on CIVIL·3d??

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost