Jump to content

Recommended Posts

Posted (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 by SLW210
icon appears unnecessarily (fixed with Code Tags!!)
Posted

Modify your codes by adding CODE TAGS to avoid any appearance of smileys .

 

Can you upload a sample txt file ?

Posted

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)
 )

Posted

Thanks for your assist, Tharwat ... works beautifully.

 

Please can you let me know what was wrong in the first instance.

Posted
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

Posted

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!)

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

 

Nice way of parsing the string :thumbsup:

Posted

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

Posted

No worries Tharwat the routine from Lee Mac resolves the issue.

Posted

My mistake that I modified your codes quickly and did not write new one , sorry for that :(

Posted
Nice way of parsing the string :thumbsup:

 

Cheers Tharwat :beer:

 

No worries Tharwat the routine from Lee Mac resolves the issue.

 

You're welcome Baber62 :)

  • 2 years later...
Posted

@Lee Mac. Can the routine be adjusted to include the z coordinate?

Posted
@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: (

Posted
Thank you Ron for answering in my absence.

 

Anytime :)

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...