Jump to content

Recommended Posts

Posted

Hi all :D

 

I really do not have much experience with AutoLISP but I would like to write a script that allows me to:

 

1. Create a new DWG

2. Draw a line from a set of existing coordinates from a .txt file

3. Save this drawing in a specified location

4. Close the drawing

5. Rinse and repeat until all of the .txt files have been drawn.

 

Basically this will be used for hundreds of .txt files containing coordinates to draw the cross-sections of a tunnel.

 

Is this something that can be done? As after hours of research I have only managed to be able to draw one cross-section using a batch file but haven't been able to close the drawing or save it. :(

 

Thanks in advance for any help :)

Posted

A script is not exactly the same as a lisp routine.

 

Lee Mac, one of the many talented lisp gurus here at CADTutor, describes it thusly, "...a Script is merely a list of AutoCAD commands to be executed one after the other, as if the user were typing them at the command-line."

Posted

What does the text file look like?

 

Something like this?

; X,Y coords
5214.6582,6581.1247
5218.4741,6501.2362
;etc.

Posted

Yes, each text file looks like this

; X,Y,Z Coords
+00.0000 +00.0000 006
+01.4350 -00.0710 007
+03.5190 -00.1610 006
+04.9540 -00.2420 007
-02.3650 -00.0690 000
-02.3660 +00.1150 000
-02.3620 +00.3250 000
-02.3660 +00.5990 000
-02.3660 +00.8010 000
-02.3660 +01.0550 000
-02.3630 +01.2530 000
-02.3560 +01.4540 000
-02.3450 +01.6590 000
-02.3370 +01.8920 000
-02.3380 +02.1860 000
-02.3500 +02.5580 000
-02.3600 +02.9840 000
-02.3600 +03.2070 000
-02.3660 +03.3890 000
-02.3670 +03.5710 000
-02.3640 +03.7150 000
-02.3600 +03.8580 000
-02.3490 +04.1770 000
-02.3390 +04.3990 000
-02.3360 +04.5490 000
-02.3320 +04.6980 000
-02.3260 +04.8380 000
-02.3140 +04.9780 000
-02.2970 +05.0880 000
-02.2760 +05.1970 000
-02.2520 +05.3060 000
-02.2220 +05.4340 000
-02.1870 +05.5610 000
-02.1550 +05.6660 000
-02.1180 +05.7700 000
-02.0870 +05.8400 000
-02.0520 +05.9090 000
-02.0160 +05.9770 000
-01.9460 +06.0930 000
-01.8700 +06.2050 000
-01.7950 +06.3180 000
-01.7060 +06.4740 000
-01.6610 +06.5520 000
-01.6120 +06.6280 000
-01.5540 +06.6970 000
-01.4960 +06.7510 000
-01.4350 +06.8010 000
-01.3730 +06.8500 000
-01.3100 +06.8980 000
-01.2460 +06.9440 002
+05.5030 +07.0060 000
+05.5740 +06.9730 000
+05.6430 +06.9350 000
+05.7090 +06.8920 000
+05.7710 +06.8440 000
+05.8300 +06.7920 000
+05.8820 +06.7370 000
+05.9290 +06.6770 000
+05.9730 +06.6160 000
+06.0190 +06.5560 000
+06.0610 +06.5020 000
+06.1040 +06.4480 000
+06.1660 +06.3810 000
+06.2320 +06.3170 000
+06.2660 +06.2870 000
+06.2990 +06.2570 000
+06.3460 +06.2020 000
+06.3870 +06.1430 000
+06.4230 +06.0800 000
+06.4540 +06.0140 000
+06.4820 +05.9480 000
+06.5120 +05.8590 000
+06.5350 +05.7670 000
+06.5590 +05.6760 000
+06.5910 +05.5820 000
+06.6230 +05.4880 000
+06.6520 +05.3930 000
+06.6760 +05.2850 000
+06.6950 +05.1760 000
+06.7100 +05.0660 000
+06.7240 +04.9140 000
+06.7300 +04.7620 000
+06.7340 +04.6090 000
+06.7420 +04.4570 000
+06.7490 +04.3850 000
+06.7570 +04.3140 000
+06.7610 +04.2420 000
+06.7540 +04.1450 000
+06.7410 +04.0490 000
+06.7330 +03.9530 000
+06.7380 +03.8450 000
+06.7510 +03.7380 000
+06.7640 +03.6310 000
+06.7750 +03.5490 000
+06.7870 +03.4670 000
+06.7920 +03.3840 000
+06.7840 +03.3000 000
+06.7700 +03.2160 000
+06.7610 +03.1320 000
+06.7640 +03.0570 000
+06.7710 +02.9820 000
+06.7760 +02.9070 000
+06.7760 +02.7970 000
+06.7740 +02.6880 000
+06.7660 +02.4910 000
+06.7650 +02.4060 000
+06.7700 +02.2840 000
+06.7760 +02.1620 000
+06.7750 +02.0690 000
+06.7740 +01.9750 000
+06.7820 +01.8580 000
+06.7940 +01.7400 000
+06.8010 +01.6230 000
+06.7990 +01.5080 000
+06.7940 +01.3940 000
+06.7900 +01.2860 000
+06.7850 +01.1500 000
+06.7770 +01.0140 000
+06.7650 +00.9090 000
+06.7540 +00.8030 000
+06.7530 +00.7300 000
+06.7530 +00.6560 000
+06.7530 +00.5550 000
+06.7560 +00.4550 000
+06.7630 +00.3820 000
+06.7710 +00.3100 000
+06.7770 +00.1790 000
+06.7760 +00.0480 000
+06.7790 -00.3290 000
+06.7450 -00.5510 000
+06.7380 -00.7000 002

Posted

The script could look something like this

 

open mytemplatefilefortunnels 
(setq filename "c:\mytunnel\tunnel1.txt)
(load "tunnelmaker")
open mytemplatefile for tunnels
(setq filename "c:\mytunnel\tunnel2.txt")
(load "tunnelmaker")
open mytemplatefile for tunnels
(setq filename "c:\mytunnel\tunnel2.txt")
(load "tunnelmaker")

 

Going in the direction that Rkmcswain may be heading open a blank template, the lisp program opens the data file creates tunnel and at end saves and closes the file. This may be easier rather than converting the txt file to a script but that could be done also.

Posted

That's almost perfect thanks BIGAL, but how do I get the LISP to automatically load the next txt file?

Basically there are lots of txt files that all contain coordinates. Its not just the one txt file named "tunnelmaker" that I need to draw.

So for example there are 3 txt files named "tunnelmaker 1" "tunnelmaker 2" "tunnelmaker 3" containing coordinates0.

Is there a way of writing the LISP to firstly open the txt files in order, and each time, save the newly created tunnel cross-section without having to write the save name in the script beforehand?

 

I'd like this because after the LISP is written, I can hand it over to other people for them to plot their tunnel cross-sections without the need for them to edit the AutoLISP file.

 

Thanks.

Posted (edited)

iNside the tunnel maker.lsp is variable fname this is the name of the txt file. Tunnel1.txt to be read.

 

Yes you do need a read text file lisp and draw lines can you post a dwg and a txt file so if like me I can find some time will do for you.

 

The first step would be to create the script from a onscreen method to pick files.

 

Yes left a step unanswered inside the tunnel lisp is a save dwg and close.

 

A script runs next line once a lisp is completed so open template again and repeat.

Edited by BIGAL
Autoceoorect on a Ipad is a pain
Posted

I got this from your data it took a few seconds to do just used notepad to remove + and changed space to "," changed 006 & 007 etc to 000.

 

Removed all notes from start of file added LINE as 1st line Ctrl A Ctrl C then pasted to Autocad command line. Just not sure if this is correct.

 

ScreenShot004.jpg

Posted

That's exactly how it is supposed to look. I just need a way of automating it for lots of drawings.

 

Thanks,

Posted

Do you want in one drawing, rather than multiple ?

 

Will try to find time to do something.

Posted

In multiple drawings ideally. I really appreciate your help, the majority of this sort of thing is lost on me at the moment :)

Posted (edited)

Ok this is very first step get the read file working, next will be to write a script and repeat for multiple files. Try it by just changing the file name at end. Thanks also to lee-mac.

 

; tunnel takes a txt file ignores lines that are not xy description
(vl-load-com)
;;-------------------=={ Parse Numbers }==--------------------;;
;;                                                            ;;
;;  Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;

(defun LM:ParseNumbers ( s )
 (
   (lambda ( l )
     (read
       (strcat "("
         (vl-list->string
           (mapcar
             (function
               (lambda ( a b c )
                 (if
                   (or
                     (< 47 b 58)
                     (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                     (and (= 46 b) (< 47 a 58) (< 47 c 58))
                   )
                   b 32
                 )
               )
             )
             (cons nil l) l (append (cdr l) (list nil))
           )
         )
         ")"
       )
     )
   )
   (vl-string->list s)
 )
)

(defun tunnel (fname / x xyzlist xyz)
(setq fo (open fname "R"))
(command "_pline")
(while (= (getvar "cmdactive") 1 )
(while (setq newline (read-line fo))
(if (or (= (substr newline 1 1 ) "+")(= (substr newline 1 1 ) "-"))
(progn
(setq xyzlist (LM:ParseNumbers newline))
;(setq xyz (strcat (rtos (nth 0 xyzlist)2 4) "," (rtos (nth 1 xyzlist)2 4))) 
;(command xyz) ; co-ords of line
(command (list (nth 0 xyzlist) (nth 1 xyzlist) 0.0))
);progn
(princ "skip")
);if
); while read file
(command "") ; end line
) ; end pline while
);defun

; run code
(tunnel "C:\\acadtemp\\175475BK.txt")
;(command "saveas" "c:\\cadtemp\\175475BK" "close")

Edited by BIGAL
Posted

When running that .lsp it returns an error:

 

first test.lsp successfully loaded.

Command: _pline

Specify start point: ; error: bad argument type: FILE nil

Specify start point:

Command:

Specify start point: *Cancel*

Command: *Cancel*

 

Any ideas?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...