Baber62 Posted April 27, 2015 Share Posted April 27, 2015 (edited) 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. Edited April 27, 2015 by SLW210 icon appears unnecessarily (fixed with Code Tags!!) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 27, 2015 Share Posted April 27, 2015 Modify your codes by adding CODE TAGS to avoid any appearance of smileys . Can you upload a sample txt file ? Quote Link to comment Share on other sites More sharing options...
Baber62 Posted April 27, 2015 Author Share Posted April 27, 2015 Please find attached as requested Tharwat. Aberdeen Road.txt Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 27, 2015 Share Posted April 27, 2015 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) ) Quote Link to comment Share on other sites More sharing options...
Baber62 Posted April 27, 2015 Author Share Posted April 27, 2015 Thanks for your assist, Tharwat ... works beautifully. Please can you let me know what was wrong in the first instance. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 27, 2015 Share Posted April 27, 2015 Thanks for your assist, Tharwat ... works beautifully. You are welcome . Please can you let me know what was wrong in the first instance. 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 27, 2015 Share Posted April 27, 2015 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!) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 27, 2015 Share Posted April 27, 2015 FWIW, here's another way to parse the text file contents: Nice way of parsing the string Quote Link to comment Share on other sites More sharing options...
Baber62 Posted April 27, 2015 Author Share Posted April 27, 2015 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 Quote Link to comment Share on other sites More sharing options...
Baber62 Posted April 27, 2015 Author Share Posted April 27, 2015 No worries Tharwat the routine from Lee Mac resolves the issue. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 27, 2015 Share Posted April 27, 2015 My mistake that I modified your codes quickly and did not write new one , sorry for that Quote Link to comment Share on other sites More sharing options...
SLW210 Posted April 27, 2015 Share Posted April 27, 2015 I fixed your code this time, for future postings please read the Code Posting Guidelines. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 27, 2015 Share Posted April 27, 2015 Nice way of parsing the string Cheers Tharwat No worries Tharwat the routine from Lee Mac resolves the issue. You're welcome Baber62 Quote Link to comment Share on other sites More sharing options...
Baber62 Posted July 7, 2017 Author Share Posted July 7, 2017 @Lee Mac. Can the routine be adjusted to include the z coordinate? Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 7, 2017 Share Posted July 7, 2017 @Lee Mac. Can the routine be adjusted to include the z coordinate? Change: (= 3 (length lst)) to (= 4 (length lst)) ( assuming your whole list has z values ) Or: ( Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 8, 2017 Share Posted July 8, 2017 Thank you Ron for answering in my absence. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 10, 2017 Share Posted July 10, 2017 Thank you Ron for answering in my absence. Anytime Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.