Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
deandavis
Posts: 17
Registered: ‎08-30-2007
Message 1 of 14 (935 Views)

Re-posted: Using AutoLISP to copy a text string from one file to another

935 Views, 13 Replies
05-07-2012 02:59 PM

Sorry folks, but I'm a newcomer to AutoLISP and still struggling with the code I was trying to write last week.  I do appreciate the help that all of you have given me so far.  I will try to better explain what I am trying to do.  I am trying to automate the conversion of scanned drawings to full CAD drawings.  The program I am using to convert the scanned drawings is titled Scan2Cad.  The program that I am writing generates a text file that can be used in a command prompt when Scan2Cad launches.  The file that I want the program to read from is test.csv.  This file has 13 lines in it.  Each line states the filename and directory path to the scanned file I want to convert.  The program will read the file path of the image and insert it in the appropriate line of the text file that will be called from the command prompt.  The program also writes additional lines specifying the options I want Scan2Cad to use for the conversion.  This generated text file is named testing.txt.

 

The program as written, will generate the first text file for the first image, launch Scan2Cad and save the dxf file.  What I need it to do, (and this is where I'm having difficulty), is for the program to continue to loop (using WHILE) through the remaining files listed in test.csv, overwriting the testing.txt file with the new information for the next image until all files listed in test.csv have been processed.  The code is shown below.  I have removed my previous while statement, as I could not get it to work.

 

Thanks again for your help!

 

 

(defun c:runscan2cad ()
  (setq a (open "c:\\misc\\test.csv" "r"))
  (setq temp (read-line a))
  (setq b (open "c:\\dwgs\\beniciafab\\scripttools\\testing.txt" "w"))
  (write-line "LOADRASTER" b)
  (write-line temp b)
  (write-line "REMOVESPECKLES" b)
  (write-line "8" b)
  (write-line "RUNVECTOR" b)
  (write-line "SAVEVECTOR" b)
  (write-line "EXIT" b)
  (close b)
  (startapp "C:/program files/scan2cadv7/scan2cadv7.exe"
	    "C:\\dwgs\\beniciafab\\scripttools\\testing.txt"
  )
  (princ)
)

 

Distinguished Mentor
gasty1001
Posts: 524
Registered: ‎04-11-2010
Message 2 of 14 (919 Views)

Re: Re-posted: Using AutoLISP to copy a text string from one file to another

05-08-2012 05:57 PM in reply to: deandavis

Hi, Not sure about the workflow you are trying to implement, but something  like this may help.

 

(while (setq temp (read-line a))

   (do your stuff...)

)

(close a)

 

Obs: I think you need to create a different "testing.txt" in each pass of the loop, usinga index like

 

(setq idx 0)

(setq path "MyPath")

(while (setq temp (read-line a))

 (setq testingFileName (strcat path  "testing" (itoa idx) ".txt"))

(setq b (open testingFileName "w"))

(write...stuff)

(close b)

(startapp...)

(setq idx (+ idx 1))

)

(close a)

 

 

 

Mentor
balisteor
Posts: 339
Registered: ‎02-23-2009
Message 3 of 14 (889 Views)

Re: Re-posted: Using AutoLISP to copy a text string from one file to another

05-09-2012 12:03 PM in reply to: deandavis

if you could attach the csv file that has all of the filenames that would be helpful, because it is a csv file you may need to remove commas, or other information from each line, but from what your doing it seems that every line in the csv file is the exact path to the drawing on each line and not really a csv file. If this is the case I have made some changes to your program and it should work. if not  then hopefully it helps you finish it.

 

(defun c:runscan2cad ( / a b temp)
(setq a (open "c:\\misc\\test.csv" "r"))
(while (setq temp (read-line a))
(setq b (open "c:\\dwgs\\beniciafab\\scripttools\\testing.txt" "w"))
(foreach line (list "LOADRASTER" temp "REMOVESPECKLES" "8" "RUNVECTOR" "SAVEVECTOR" "EXIT")
(write-line line b)
);fe
(close b)
(startapp "C:/program files/scan2cadv7/scan2cadv7.exe" "C:\\dwgs\\beniciafab\\scripttools\\testing.txt")
);w

(close a)
(princ))

 
Also i have never used this program "Scan2Cad", so just wanted to let you know that this will start the application up for every line in the csv file. and it may or may not shut itself down every time.  but autolisp will not wait for it to do so.

 

Contributor
deandavis
Posts: 17
Registered: ‎08-30-2007
Message 4 of 14 (873 Views)

Re: Re-posted: Using AutoLISP to copy a text string from one file to another

05-10-2012 06:40 AM in reply to: balisteor
Thank you for your help. I will try the program and see how it does. I may need to find some way to pause AutoLISP to allow Scan2Cad to exit before AutoLISP starts processing the next line. I have attached the csv file as you requested, but you are correct, each line just shows the filename and path to the file. Dean Davis CAD Administrator Capital Projects - Drafting Chevron Richmond Refinery
Mentor
balisteor
Posts: 339
Registered: ‎02-23-2009
Message 5 of 14 (869 Views)

Re: Re-posted: Using AutoLISP to copy a text string from one file to another

05-10-2012 06:53 AM in reply to: deandavis

If waiting for the program to complete is an issue I'm sure there are a few solutions, I don't know if you are familiar with doslib, but that is what I use for these types of things.

Contributor
deandavis
Posts: 17
Registered: ‎08-30-2007
Message 6 of 14 (864 Views)

Re: Re-posted: Using AutoLISP to copy a text string from one file to another

05-10-2012 07:30 AM in reply to: balisteor
I ran your code and it does like you say. The Scan2Cad program launches, but AutoLISP continues to run the rest of the program code before Scan2Cad finishes the first line. Scan2CAD displays the message "Only a single instance of Scan2Cad is allowed". I have seen another lisp programmer use the DELAY statement in an AutoLISP program he wrote, but I don't fully follow his code to see if there is anything else he has put in that allows it to work.
Mentor
balisteor
Posts: 339
Registered: ‎02-23-2009
Message 7 of 14 (857 Views)

Re: Re-posted: Using AutoLISP to copy a text string from one file to another

05-10-2012 10:04 AM in reply to: deandavis

So, my next question would be does scan2cad shut down when it is finished? or do we also need to shut it down, or it may also accept sending a different command to it to scan another drawing while its open, see if you can figure this stuff out, If i get a change ill download the trial and see what i can find out.  we can always have autolisp delay and then continue but even then if scan2cad wont accept another drawing and wont shut down we have to fix that first.

I also wonder even if scan2cad can read a file with more lines, so we just send it all info at once.

so file will look something like the following and be accepted by scan2cad

 

"LOADRASTER"
**filetoread**
"REMOVESPECKLES"
"8"
"RUNVECTOR"
"SAVEVECTOR"
"EXIT" <<<-- is this supposed to exit program (if so we remove it for next files)

"LOADRASTER"
**filetoread**
"REMOVESPECKLES"
"8"
"RUNVECTOR"
"SAVEVECTOR"
"EXIT"

"LOADRASTER"
**filetoread**
"REMOVESPECKLES"
"8"
"RUNVECTOR"
"SAVEVECTOR"
"EXIT"

"LOADRASTER"
**filetoread**
"REMOVESPECKLES"
"8"
"RUNVECTOR"
"SAVEVECTOR"
"EXIT"

 

 

 

Send me a link if you have one on the scan2cad documentation, otherwise i will try to find this out when i can.

Mentor
balisteor
Posts: 339
Registered: ‎02-23-2009
Message 8 of 14 (848 Views)

Re: Re-posted: Using AutoLISP to copy a text string from one file to another

05-10-2012 11:18 AM in reply to: deandavis

I was digging around with the documentation i could find online, keep in mind this is all guesswork but If you have version 8.3 this may work well, see if you can read through what im doing here so you can see if i have the right idea.

 

(defun c:runscan2cad ( / filetoread filetowrite scanfilepath)
(setq filetoread (open "c:\\misc\\test.csv" "r")
      filetowrite (open "c:\\dwgs\\beniciafab\\scripttools\\testing.txt" "w")
)
(while (setq scanfilepath (read-line filetoread))
(foreach S2C_COMMAND (list "LOADRASTER" scanfilepath "REMOVESPECKLES" "8" "RUNVECTOR" "SAVEVECTOR" "CLOSERASTER")
(write-line S2C_COMMAND filetowrite)
);fe
);w

(close filetoread)
(close filetowrite)
(startapp "C:/program files/scan2cadv7/scan2cadv7.exe" "C:\\dwgs\\beniciafab\\scripttools\\testing.txt")
(princ))

 

Contributor
deandavis
Posts: 17
Registered: ‎08-30-2007
Message 9 of 14 (844 Views)

Re: Re-posted: Using AutoLISP to copy a text string from one file to another

05-10-2012 11:27 AM in reply to: balisteor
LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-89429-0.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT
Contributor
deandavis
Posts: 17
Registered: ‎08-30-2007
Message 10 of 14 (837 Views)

Re: Re-posted: Using AutoLISP to copy a text string from one file to another

05-10-2012 12:01 PM in reply to: balisteor
LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-304021-4.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-304022-4.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-304023-4.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-304024-4.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-304025-4.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-304026-2.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 03\D-308245-0.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\B-311559-0-1.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-312422-0.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-312423-0.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-312424-0.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 02\B-86761-1.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT LOADRASTER G:\SCANNED\MHA Scanned Files\Delivery 06\D-89429-0.TIF REMOVESPECKLES 8 RUNVECTOR SAVEVECTOR EXIT
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

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