Author Topic: CAB,LEE,Help me,code appear "stringp nil"  (Read 2793 times)

0 Members and 1 Guest are viewing this topic.

myloveflyer

  • Newt
  • Posts: 152
CAB,LEE,Help me,code appear "stringp nil"
« on: December 15, 2012, 03:25:48 AM »
Why run error program, asks everybody to help to look, data and test chart in Appendix,Thanks!
Code - Auto/Visual Lisp: [Select]
  1. (defun c:te (/ lst1 lst2 ss len i entn entx c ltext s1 s2 count f1 rline1 pos1 1ststr1 2ndstr1 result1 f2 rline2 pos2 1ststr2 2ndstr2 result2 con1 con2 delta lstx lst dt gd)
  2.  (setvar "cmdecho" 0)
  3.  
  4. (setq f1 (open "c:\\sj1.dat" "r"))
  5. (while (setq rline1 (read-line f1))
  6. (setq pos1 (vl-string-search " " rline1))
  7. (setq 1ststr1 (substr rline1 1 pos1)
  8.       2ndstr1 (substr rline1 (+ 3 pos1))
  9.   )
  10. (setq result1 (append (list(cons 1ststr1 2ndstr1)
  11.        )
  12.        result1
  13.        )
  14.   )
  15. )
  16. (close f1)
  17. (setq lst1(reverse result1))
  18.  
  19. (setq f2 (open "c:\\sj2.dat" "r"))
  20. (while (setq rline2 (read-line f2))
  21. (setq pos2 (vl-string-search " " rline2))
  22. (setq 1ststr2 (substr rline2 1 pos2)
  23.       2ndstr2 (substr rline2 (+ 3 pos2))
  24.   )
  25. (setq result2 (append (list(cons 1ststr2 2ndstr2)
  26.        )
  27.        result2
  28.        )
  29.   )
  30. )
  31. (close f2)
  32. (setq lst2(reverse result2))
  33. (setq con1 (getpoint  "\nFrist point:"))
  34. (setq con2 (getcorner con1 "\nSecond point:"))
  35.         (setq lst (transtab lst1 lst2))
  36. (setq dt (getint "\nHeight difference <0> :"))
  37. ;(if (null dt) (exit))
  38. (if (= dt 0.0) (progn (setq dt 0.0))
  39. (progn (setq dt dt)))
  40.  (setq ss (ssget "w" con1 con2 '((8 . "qh") (0 . "TEXT"))))
  41.  (setq filename (getfiled "\nFile storage location" "" "xls" 33))
  42.  (setq filedesc (open filename "a"))
  43.  (if ss (progn
  44.   (setq len (sslength ss))
  45.   (setq i 0)
  46.            ;; extract all text in selection and save in list var "ltext"
  47.   (repeat len
  48.    (setq entn (ssname ss i))
  49.    (setq entx (entget entn))
  50.    (setq c (cdr (assoc 1 entx)))
  51.    (setq ltext (cons c ltext))
  52.    (setq i (1+ i))
  53.   )
  54.            ;; Sort and count ltext and then report result
  55.   (setq ltext (acad_strlsort ltext)
  56.             len   (length ltext)
  57.         i     0
  58.         count 0)
  59.   (repeat len
  60.    (setq s1 (nth i ltext))
  61.    (if (= s2 nil) (setq s2 s1) (setq gd (+ dt (atof (cdr(assoc s2 lstx))))))
  62.    (if (/= s2 s1) (progn
  63.     (write-line (strcat s2 "NU" "\t" (itoa count) "NO" "\t" (rtos gd 2 0) "mm" )filedesc)
  64.     (setq s2 s1 count 1)
  65.    )
  66.     (setq count (1+ count))
  67.    )
  68.    (setq i (1+ i))
  69.   )
  70.   (write-line (strcat s2 "NU" "\t" (itoa count) "NO" "\t" (rtos gd 2 0) "mm" )filedesc)
  71.  ))
  72.  (write-line "" filedesc)
  73.  (write-line "" filedesc)              
  74.  (close filedesc)
  75.  (setvar "cmdecho" 1)
  76.  (princ)
  77. )
  78.  
  79.  
  80.  
« Last Edit: December 16, 2012, 08:31:06 AM by myloveflyer »
Never give up !

kruuger

  • Swamp Rat
  • Posts: 637
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #1 on: December 15, 2012, 03:35:16 AM »
hello,

what program should do ? now saves xls file with few spaces.
no error on my side

kruuer

myloveflyer

  • Newt
  • Posts: 152
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #2 on: December 15, 2012, 03:49:44 AM »
Program requires completion of the statistics of the same character, and according to the data files to calculate a numerical value and then output。
eg.
When the input the height difference is 0 when be
Output form is as follows:
WD*A   4   48
WD*B   42   36
WD*C   78   27
WD*D   80   18
WD*E   40   9
WD*F   8   0
« Last Edit: December 15, 2012, 04:07:42 AM by myloveflyer »
Never give up !

kruuger

  • Swamp Rat
  • Posts: 637
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #3 on: December 15, 2012, 04:50:27 AM »
Program requires completion of the statistics of the same character, and according to the data files to calculate a numerical value and then output。
eg.
When the input the height difference is 0 when be
Output form is as follows:
WD*A   4   48
WD*B   42   36
WD*C   78   27
WD*D   80   18
WD*E   40   9
WD*F   8   0
where is the text in this drawing ? where did you hide them ?
i saw text on pallete after CTRL+A but no on screen  :o
k.

myloveflyer

  • Newt
  • Posts: 152
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #4 on: December 15, 2012, 05:33:11 AM »
Program requires completion of the statistics of the same character, and according to the data files to calculate a numerical value and then output。
eg.
When the input the height difference is 0 when be
Output form is as follows:
WD*A   4   48
WD*B   42   36
WD*C   78   27
WD*D   80   18
WD*E   40   9
WD*F   8   0
where is the text in this drawing ? where did you hide them ?
i saw text on pallete after CTRL+A but no on screen  :o
k.

"WD * A, WD * B ,WD * C, WD * D, WD * E, WD * F" from CSS. DWG diagram select out, then the output to EXCEL, the first is the Numbers, the second is quantity, the third is the numerical calculation.
« Last Edit: December 15, 2012, 05:45:02 AM by myloveflyer »
Never give up !

kruuger

  • Swamp Rat
  • Posts: 637
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #5 on: December 15, 2012, 06:14:15 AM »
there was missing font and i hit escape. now i replace them and text is fine
error is at atof function:
Code: [Select]
(atof (cdr(assoc s2 lstx))) -> (atof nil)this will return nil.

kruuger

myloveflyer

  • Newt
  • Posts: 152
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #6 on: December 15, 2012, 06:20:30 AM »
there was missing font and i hit escape. now i replace them and text is fine
error is at atof function:
Code: [Select]
(atof (cdr(assoc s2 lstx))) -> (atof nil)this will return nil.

kruuger

How to modify the program to make correct
Never give up !

kruuger

  • Swamp Rat
  • Posts: 637
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #7 on: December 15, 2012, 06:45:55 AM »
there was missing font and i hit escape. now i replace them and text is fine
error is at atof function:
Code: [Select]
(atof (cdr(assoc s2 lstx))) -> (atof nil)this will return nil.

kruuger

How to modify the program to make correct
first change WT at dat2 file to WD...

myloveflyer

  • Newt
  • Posts: 152
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #8 on: December 15, 2012, 07:51:25 AM »
there was missing font and i hit escape. now i replace them and text is fine
error is at atof function:
Code: [Select]
(atof (cdr(assoc s2 lstx))) -> (atof nil)this will return nil.

kruuger

How to modify the program to make correct
first change WT at dat2 file to WD...

Not too understand what you mean
The results of the two words like is nil
I delete the two sentences, modified as follows:
Code: [Select]
(defun c:te (/ lst1 lst2 ss len i entn entx c ltext s1 s2 count f1 rline1 pos1 1ststr1 2ndstr1 result1 f2 rline2 pos2 1ststr2 2ndstr2 result2 con1 con2 delta lstx lst dt gd)
 (setvar "cmdecho" 0)
 
(setq f1 (open "c:\\sj1.dat" "r"))
(while (setq rline1 (read-line f1))
(setq pos1 (vl-string-search " " rline1))
(setq 1ststr1 (substr rline1 1 pos1)
      2ndstr1 (substr rline1 (+ 3 pos1))
  )
(setq result1 (append (list(cons 1ststr1 2ndstr1)
       )
       result1
       )
  )
)
(close f1)
(setq lst1(reverse result1))

(setq f2 (open "c:\\sj2.dat" "r"))
(while (setq rline2 (read-line f2))
(setq pos2 (vl-string-search " " rline2))
(setq 1ststr2 (substr rline2 1 pos2)
      2ndstr2 (substr rline2 (+ 3 pos2))
  )
(setq result2 (append (list(cons 1ststr2 2ndstr2)
       )
       result2
       )
  )
)
(close f2)
(setq lst2(reverse result2))
(setq con1 (getpoint  "\nFrist point:"))
(setq con2 (getcorner con1 "\nSecond point:"))
   (setq lst (transtab lst1 lst2))
(setq dt (getint "\nHeight difference <0> :"))
;(if (null dt) (exit))
(if (= dt 0.0) (progn (setq dt 0.0))
(progn (setq dt dt)))
 (setq ss (ssget "w" con1 con2 '((8 . "qh") (0 . "TEXT"))))
 (setq filename (getfiled "\nFile storage location" "" "xls" 33))
 (setq filedesc (open filename "a"))
 (if ss (progn
  (setq len (sslength ss))
  (setq i 0)
      ;; extract all text in selection and save in list var "ltext"
  (repeat len
   (setq entn (ssname ss i))
   (setq entx (entget entn))
   (setq c (cdr (assoc 1 entx)))
   (setq ltext (cons c ltext))
   (setq i (1+ i))
  )
      ;; Sort and count ltext and then report result
  (setq ltext (acad_strlsort ltext)
       len   (length ltext)
        i     0
        count 0)
  (repeat len
   (setq s1 (nth i ltext))
   (if (= s2 nil) (setq s2 s1) (setq gd (+ dt (atof (cdr(assoc s2 lst))))))
   (if (/= s2 s1) (progn
    (write-line (strcat s2 "NU" "\t" (itoa count) "NO" "\t" (rtos gd 2 0) "mm" )filedesc)
    (setq s2 s1 count 1)
   )
    (setq count (1+ count))
   )
   (setq i (1+ i))
  )
  (write-line (strcat s2 "NU" "\t" (itoa count) "NO" "\t" (rtos gd 2 0) "mm" )filedesc)
 ))
 (write-line "" filedesc)
 (write-line "" filedesc)     
 (close filedesc)
 (setvar "cmdecho" 1)
 (princ)
)


(setq LST (transtab lst1 lst2) is I need to get the list
Back to (setq gd (+ dt (atof (CDR (assoc s2 lst))))) this is nil
Don't know what the problem out there, please help modify the program,thanks
« Last Edit: December 20, 2012, 10:15:20 PM by myloveflyer »
Never give up !

kruuger

  • Swamp Rat
  • Posts: 637
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #9 on: December 15, 2012, 11:41:13 AM »
you are trying use assoc:
Code: [Select]
(cdr(assoc s2 lstx))on list:
Code: [Select]
(("WT*A" . "48") ("WT*B" . "36") ("WT*C" . "27") ("WT*D" . "18") ("WT*E" . "9") ("WT*F" . "0"))but your s2 is WD*X
this will always fail.

change all text to WT or all data in sj2.dat to WD. after that all seems to be ok.

sample
Code: [Select]
(cdr (assoc "WD*A" '(("WT*A" . "48") ("WT*B" . "36") ("WT*C" . "27") ("WT*D" . "18") ("WT*E" . "9") ("WT*F" . "0")))) -> always nil
(cdr (assoc "WT*A" '(("WT*A" . "48") ("WT*B" . "36") ("WT*C" . "27") ("WT*D" . "18") ("WT*E" . "9") ("WT*F" . "0")))) -> "48"
kruuger
« Last Edit: December 15, 2012, 12:47:14 PM by kruuger »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #10 on: December 15, 2012, 12:30:54 PM »
I would suggest you add some error checking within the routine unless you want it to fail in order to reveal the errors to the user.
« Last Edit: December 15, 2012, 12:33:59 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

myloveflyer

  • Newt
  • Posts: 152
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #11 on: December 16, 2012, 08:30:14 AM »
you are trying use assoc:
Code: [Select]
(cdr(assoc s2 lstx))on list:
Code: [Select]
(("WT*A" . "48") ("WT*B" . "36") ("WT*C" . "27") ("WT*D" . "18") ("WT*E" . "9") ("WT*F" . "0"))but your s2 is WD*X
this will always fail.

change all text to WT or all data in sj2.dat to WD. after that all seems to be ok.

sample
Code: [Select]
(cdr (assoc "WD*A" '(("WT*A" . "48") ("WT*B" . "36") ("WT*C" . "27") ("WT*D" . "18") ("WT*E" . "9") ("WT*F" . "0")))) -> always nil
(cdr (assoc "WT*A" '(("WT*A" . "48") ("WT*B" . "36") ("WT*C" . "27") ("WT*D" . "18") ("WT*E" . "9") ("WT*F" . "0")))) -> "48"
kruuger

Kruuger, thank you very much, main program I have set breakpoint check no problem, so I made a very serious problem, data file editing problems, resulting in the program have been wrong, I'll pay attention, thank you for your kind help.
CAB, thank you very much for your advice, I will consider to add some fault-tolerant processing, previous tests are set breakpoints for inspection, and you in processing program is used when there error check?Thank you for you advise!
Never give up !

kruuger

  • Swamp Rat
  • Posts: 637
Re: CAB,LEE,Help me,code appear "stringp nil"
« Reply #12 on: December 16, 2012, 04:45:37 PM »
Kruuger, thank you very much...
:kewl: