Baber62 发表于 2022-7-5 16:13:22

Error message in routine - bad

I have a lisp routine which worked well in earlier editions of AutoCAD but now with AutoCAD Map 2014 it doesn't work giving me the following error message:
 
; error: bad argument type: numberp: nil
 
The routine draws a circle around a number located at an x,y co-ordinate.
 
Here's the code:
 

(defun c:ImportPts (/ txtht file line ptno x y xy b4y) (setq txtht (getreal "\nText height?")           file (open (getfiled "Select the input file: " "" "txt""r") ;;;the smiley with shades is 8 with a bracket next to it) (while (setq line (read-line file))   (setq ptno (substr line 1 (setq xy (vl-string-search "," line)))x (vl-string-left-trim " " (substr line (+ 2 xy) (- (setq b4y (vl-string-search "," line (+ 2 xy))) 2)))y (vl-string-left-trim " " (substr line (+ 2 b4y)))) (command "circle" (list (atof x) (atof y)) txtht) (command "text" "j" "mc" (list (atof x) (atof y)) txtht 0 ptno) ) )
 
 
I would appreciate any help, thanks in advance.

Tharwat 发表于 2022-7-5 16:20:26

Modify your codes by adding CODE TAGS to avoid any appearance of smileys .
 
Can you upload a sample txt file ?

Baber62 发表于 2022-7-5 16:21:47

Please find attached as requested Tharwat.
Aberdeen Road.txt

Tharwat 发表于 2022-7-5 16:25:29

Things like this ?
 

(defun c:ImportPts(/ h f p w st x y xy b4y) (if   (and (setq h (getreal "\nText height :"))      (setq          f (getfiled "Select the input txt file: " "" "txt" 16))      (setq f (open f "r"))      )    (progn      (while (setq w (read-line f))      (setq st               (substr w 1 (setq xy (vl-string-search " " w)))            x               (vl-string-left-trim                   " "                   (substr w(+ 2 xy) (- (setq b4y (vl-string-search "," w (+ 2 xy))) 3)))            y               (vl-string-left-trim " " (substr w (+ 2 b4y)))            )      (entmake          (list '(0 . "CIRCLE")                (cons 10                      (setq p (trans (list (atof x) (atof y)) 1 0)))                (cons 40 h)))      (entmake          (list '(0 . "TEXT")                (cons 1 st)                (cons 7 (getvar 'TEXTSTYLE))                (cons 10 p)                (cons 11 p)                (cons 40 h)                '(50 . 0.)                '(71 . 0)                '(72 . 1)                '(73 . 2)                )          )      )      (close f)      )) (princ) )

Baber62 发表于 2022-7-5 16:29:36

Thanks for your assist, Tharwat ... works beautifully.
 
Please can you let me know what was wrong in the first instance.

Tharwat 发表于 2022-7-5 16:33:15

 
You are welcome .
 
 
The first function that search for comma (,) is supposed to be empty space " " and the variable b4y should be increased in location to reach the correct destination and I changed it to 3 .
 
Compare between the two routine to learn and see the differences ( if you'd like ) .
 
Tharwat

Lee Mac 发表于 2022-7-5 16:39:11

FWIW, here's another way to parse the text file contents:

(defun c:test ( / des hgt lst txt )   (initget 6)   (if (and (setq hgt (getdist "\nSpecify text height: "))            (setq txt (getfiled "" "" "txt" 16))            (setq des (open txt "r"))       )       (progn         (while (setq str (read-line des))               (if (and (setq lst (read (strcat "(" (vl-string-translate "," " " str) ")")))                        (= 3 (length lst))                        (apply 'and (mapcar 'numberp lst))                   )                   (progn                     (entmake                           (list                               '(0 . "CIRCLE")                              (cons 10 (cdr lst))                               (cons 40 hgt)                           )                     )                     (entmake                            (list                               '(0 . "TEXT")                               (cons 10 (cdr lst))                               (cons 11 (cdr lst))                               (cons 01 (itoa (car lst)))                               (cons 40 hgt)                               '(72 . 1)                               '(73 . 2)                           )                     )                   )               )         )         (close des)       )   )   (princ))
(Untested & typed in post box!)

Tharwat 发表于 2022-7-5 16:42:41

 
Nice way of parsing the string

Baber62 发表于 2022-7-5 16:46:28

Hi Tharwat,
 
Apologies for this but with the modified routine the coordinates for the first set of points (1-9) are drawn out of synch, possibly because of the number of digits. the coordinates are fine for points number 10 onwards. When I have got the coordinate say for point number 1 it reads as 53250,166730 rather than 532050, 166730. I have attached the sample text file I am using.
Chesnut Primary.txt

Baber62 发表于 2022-7-5 16:50:27

No worries Tharwat the routine from Lee Mac resolves the issue.
页: [1] 2
查看完整版本: Error message in routine - bad