Author Topic: under pressure and stuck  (Read 2599 times)

0 Members and 1 Guest are viewing this topic.

Ciaran

  • Guest
under pressure and stuck
« on: October 14, 2013, 04:23:27 PM »
Hi,
I have an issue with a lisp and am looking for some assistance. The lisp is currently reporting an error.

Quote
Click the point you want: ; error: too few arguments

It asks for a point and then puts the "Closest point" (a grid column) from the *.csv into mtext box.
It should also put the distance to the "Closest point" below that but it seems to be failing here.

Capture 1.jpg attached is what i am looking for.
Capture 2.jpg attached is what i am getting. 

I have also attached the *.csv i am using and lsp file

Below is the current code I am using. If anyone can help that would be great.

Thanks in advance.

Code: [Select]
(defun c:yeah ( / pnt file pntlist bob apntlst pntlst sttext)
  (if (setq pnt (getpoint "\nClick the point you want: "))
    (progn
      (findfile "GRIDLINE.csv")
      (setq file (open "C://GRIDLINE.csv" "r"))
      (setq pntlst (list ""))
      (while (setq bob (read-line file))
 (if (not (vl-string-search "GRID" (strcase bob)))
   (progn
     (setq apntlst (list (substr bob 1 (vl-string-search "," bob)) (list (atoi (substr bob (+ 2 (vl-string-search "," bob)) (- (vl-string-search "," bob (vl-string-search "," bob)) 1))) (atoi (substr bob (+ 2 (vl-string-position (ascii ",") bob nil t)) (strlen bob))) 0)))
     (setq pntlst (vl-remove "" (cons apntlst pntlst)))
     )))
      (if pntlst
 (progn
   (setq pntlst (vl-sort pntlst '(lambda (z a) ( < (distance pnt (cadr z)) (distance pnt (cadr a))))))
   (setq sttext (strcat "Gridline Reference \\P" "Closest point: " (caar pntlst)))
   (setq os (getvar "osmode"))
   (setvar "osmode" 0)
   (sb-mktxt2 sttext pnt)
   (setvar "osmode" os)
   ))
     
     
      ))
 
  )

(defun sb-mktxt2 (text pnt / )
  (vlax-put-property (vla-addMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point pnt) 0 text))
 
  )

DEVITG

  • Bull Frog
  • Posts: 481
Re: under pressure and stuck
« Reply #1 on: October 14, 2013, 04:53:49 PM »
Hi Ciaran , if you upload the dwg where you apply the LISP will help to help you
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

hmspe

  • Bull Frog
  • Posts: 362
Re: under pressure and stuck
« Reply #2 on: October 14, 2013, 05:01:59 PM »
A few things:

In line 10 you use 'apntlst' instead of 'pntlst'.

In your while loop you get a line from the file, process the line, then overwrite the value of 'pntlst'.  You end up with one entry in 'pntlst', corresponding to the last line in the .csv file.  I think you meant to append to the exiting 'pntlst' so that 'pntlst' has an entry for each line in the file.

Each 'pntlst' entry has the form    (NIL A036 (100 433783 0))     CADR will return A036, not the point.

The vlax-put-property line in the sb-mktxt2 appears to be in error.  You are not specifying the parameter to set or the value to set it to.
"Science is the belief in the ignorance of experts." - Richard Feynman

hmspe

  • Bull Frog
  • Posts: 362
Re: under pressure and stuck
« Reply #3 on: October 14, 2013, 06:20:03 PM »
I'd recommend contacting Lee at www.lee-mac.com.
"Science is the belief in the ignorance of experts." - Richard Feynman

Lee Mac

  • Seagull
  • Posts: 12925
  • London, England
Re: under pressure and stuck
« Reply #4 on: October 14, 2013, 06:59:55 PM »
I've received your message Ciaran, however its late here so I'll take a look at this in the morning if I get some time.

Thanks for the recommendation hmspe. :-)
« Last Edit: October 14, 2013, 07:03:16 PM by Lee Mac »

pBe

  • Bull Frog
  • Posts: 402
Re: under pressure and stuck
« Reply #5 on: October 14, 2013, 08:41:37 PM »
B=2165
1=3000


What are the reference for those value ciaran?

ymg

  • Guest
Re: under pressure and stuck
« Reply #6 on: October 15, 2013, 02:26:12 AM »
Don't really know what you are trying to achieve, but try this.

I replaced tour routine to read the csv by the one from Lee Mac,
then sort the point list according to distance to your point.

Also replaced your sub for inserting the mtext.

ymg

Code - Auto/Visual Lisp: [Select]
  1. (defun c:yeah (/ pnt pntlst sttext)
  2.  
  3.   (setq pntlst (lm:readcsv (findfile "GRIDLINE.csv"))
  4.         pntlst (cdr pntlst)
  5.   )
  6.  
  7.   (if (setq pnt (getpoint "\nClick the point you want: "))
  8.      (progn
  9.           (setq pntlst (vl-sort pntlst '(lambda (a b) (< (distance pnt (list (atof(cadr a)) (atof (caddr a))))
  10.                                                          (distance pnt (list (atof(cadr b)) (atof (caddr b))))
  11.                                                       )
  12.                                         )
  13.                        )
  14.                 sttext (strcat "Gridline Reference \\P" "Closest point: " (caar pntlst))
  15.           )      
  16.           (mk_mtext pnt sttext)
  17.          
  18.      )
  19.   )
  20. )
  21.  
  22.  
  23. (defun mk_mtext (pt val)
  24.     (list
  25.       (cons 0   "MTEXT")        
  26.       (cons 100 "AcDbEntity")          
  27.       (cons 100 "AcDbMText")    
  28.       (cons 10 pt)        
  29.       (cons 1 val)
  30.     )
  31.   )
  32. )  
  33.  
  34.  
  35.  
  36.  
  37. ;; ReadCSV  -  Lee Mac
  38. ;; Parses a CSV file into a list of lists, each sublist is a row of CSV cell values.
  39.  
  40. (defun LM:ReadCSV ( filename / _csv->lst file line lst )
  41.  
  42.     (defun _csv->lst ( str / pos )
  43.         (if (setq pos (vl-string-position 44 str))
  44.             (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
  45.             (list str)
  46.         )
  47.     )
  48.  
  49.     (if (setq file (open filename "r"))
  50.         (progn
  51.             (while (setq line (read-line file))
  52.                 (setq lst (cons (_csv->lst line) lst))
  53.             )
  54.             (close file)
  55.         )
  56.     )
  57.     (reverse lst)
  58. )
  59.  
  60.  

ymg

  • Guest
Re: under pressure and stuck
« Reply #7 on: October 15, 2013, 09:49:45 AM »
Ciaran,

Just modify as shown below to get the rest.

Only line 8 to 12 are modified from before.

ymg

Code - Auto/Visual Lisp: [Select]
  1. (if (setq pnt (getpoint "\nClick the point you want: "))
  2.      (progn
  3.           (setq pntlst (vl-sort pntlst '(lambda (a b) (< (distance pnt (list (atof(cadr a)) (atof (caddr a))))
  4.                                                          (distance pnt (list (atof(cadr b)) (atof (caddr b))))
  5.                                                       )
  6.                                         )
  7.                        )
  8.                 sttext (strcat "Gridline Reference \\P" "Closest point: " (caar pntlst)
  9.                                                    "\\P Distance to Point"
  10.                                                    "\\P     E/W : " (rtos(abs (- (atof (cadar pntlst)) (car pnt))) 2 0)
  11.                                                    "\\P     N/S : " (rtos (abs (- (atof (caddar pntlst)) (cadr pnt))) 2 0)
  12.                                                    "\\P Elevation : " (rtos (caddr pnt) 2 0)
  13.                        )
  14.           )      
  15.           (mk_mtext pnt sttext)
  16.          
  17.      )
  18.   )
  19.