Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
Golfball2k6
Posts: 13
Registered: ‎09-30-2011
Message 1 of 10 (285 Views)

Read from multiple external files?

285 Views, 9 Replies
09-13-2012 08:09 AM

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
Distinguished Contributor
patrick_35
Posts: 663
Registered: ‎06-01-2005
Message 2 of 10 (283 Views)

Re: Read from multiple external files?

09-13-2012 08:16 AM in reply to: Golfball2k6
Distinguished Mentor
_Tharwat
Posts: 599
Registered: ‎07-02-2010
Message 3 of 10 (278 Views)

Re: Read from multiple external files?

09-13-2012 09:09 AM in reply to: Golfball2k6

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

 

Tharwat

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Mentor
devitg
Posts: 1,694
Registered: ‎03-14-2004
Message 4 of 10 (248 Views)

Re: Read from multiple external files?

09-14-2012 08:16 AM in reply to: Golfball2k6
To do what?? Yes it can be do
Contributor
Golfball2k6
Posts: 13
Registered: ‎09-30-2011
Message 5 of 10 (238 Views)

Re: Read from multiple external files?

09-14-2012 01:51 PM 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. :smileyhappy: 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
Distinguished Mentor
_Tharwat
Posts: 599
Registered: ‎07-02-2010
Message 6 of 10 (227 Views)

Re: Read from multiple external files?

09-15-2012 03:13 AM in reply to: Golfball2k6

Consider this as an example ...

 

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

 Tharwat

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Contributor
Golfball2k6
Posts: 13
Registered: ‎09-30-2011
Message 7 of 10 (174 Views)

Re: Read from multiple external files?

09-18-2012 06:22 AM 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
Mentor
devitg
Posts: 1,694
Registered: ‎03-14-2004
Message 8 of 10 (164 Views)

Re: Read from multiple external files?

09-18-2012 07:36 AM in reply to: Golfball2k6

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

 

Contributor
Golfball2k6
Posts: 13
Registered: ‎09-30-2011
Message 9 of 10 (161 Views)

Re: Read from multiple external files?

09-18-2012 07:48 AM 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
Mentor
devitg
Posts: 1,694
Registered: ‎03-14-2004
Message 10 of 10 (157 Views)

Re: Read from multiple external files?

09-18-2012 08:03 AM in reply to: Golfball2k6

So you will work on CIVIL·3d??

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.