Author Topic: vl-substr doesn't recognize string or symbol  (Read 1381 times)

0 Members and 1 Guest are viewing this topic.

dubb

  • Swamp Rat
  • Posts: 1105
vl-substr doesn't recognize string or symbol
« on: February 07, 2017, 06:18:32 PM »
I can't find a good subject line for this post.

About my script.
The script takes the contents of a text file and pre-fills a quickleader's mtext contents.
The .txt files contain tags such as <FT> for foot, <L> for length, <W> for width, etc.
An example command to issue would be
Code: [Select]
(smleader opt "name of .txt file")
I don't know how to use apostrophe's, mapcar, lambda. Those function are still difficult for me to understand.

There is a nested condition that I am still trying to figure out in the code. I bypassed the condition and try to pass arguments straight to main function which assembles my pre-formatted text.

Any help would be appreciated.

Code: [Select]
;Preformatted text
;
;
;Rectangle Example
;COMMAND: (smleader rrsw "rect")
;rect.txt file contents
;THIS IS A <L>' X <W>' RECTANGLE

;Length Example
;COMMAND (smleader len "length")
;length.txt file contents
;THIS IS A <FT>' LONG LINE

;Equipment Example
;COMMAND: (smleader equip "new-equipment")
;new-equipment.txt contents
;THE NEW EQUIPMENT IS <FT>', <OFFSET>
;STA. <STA>
(defun smleader (opt file)
  (setq *file* file)
  (setq *opt* opt)
;;opt options
  (cond
    ((= opt equip)
     (offsetfunc)
     (station)
     )
    ((= opt trench)
     (lenghthfunc)
     )
    ((= opt RRSW)
     (RRSW)
     )
    )
  (drawleader)
  )
(defun drawleader (/ newstr offset ft sta fn ltext)   
  (setq newstr "")
  (setq filename (strcat *file*".txt"))
    (if (setq fn (open filename  "r"))
      (progn
        (while (setq ltext (read-line fn))
          (setq newstr (strcat newstr "\n" ltext))
        )
        (close fn)
(setq newstr (substr newstr 2 (strlen newstr)))
(princ newstr)
(setq newstr (vl-string-subst ft "<FT>" newstr 0))
(setq newstr (vl-string-subst offset "<OFFSET>" newstr 0))
(setq newstr (vl-string-subst (rtos sta 2 2) "<STA>" newstr 0))
(setq newstr (vl-string-subst L "<L>" newstr 0))
(setq newstr (vl-string-subst W "<W>" newstr 0))
      )
    )
    (command "leader" pause pause "" "" "" newstr "")
    (princ)
  )


;;length function
(defun lengthfunc()
  (setq ft (getint "\nWhat is the length"))
  )
;;end
 


;;offset option
(defun offsetfunc ()
  (initget "B\\CF F\\CF B\\EOP F\\EOP")
    (setq offset (getkword "\nWhich curb offset [B\\CF/F\\CF/B\\EOP/F\\EOP]:")
      )
(cond
  ((= offset "B\\CF")
   (setq offset "B/CF")
   )
  ((= offset "F\\CF")
   (setq offset "F/CF")
   )
  ((= offset "B\\EOP")
   (setq offset "B/EOP")
   )
  ((= offset "F\\EOP")
   (setq offset "F/EOP")
   )
  )
(setq ft (itoa (getint "\nHow many feet offset:")))
  (princ)
)
    ;;end offset option

;;station option
(defun station()
  (setq sta (getreal "\nenter station number"))
  (princ)
  )
  ;;end station option

;;station option
(defun RRSW()
  (setq L (rtos (getint "\nenter length")2 0))
  (setq W (rtos (getint "\nenter width")2 0))
  (princ)
  )
  ;;end station option


Code: [Select]
error: bad argument type: (or stringp symbolp): nil

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vl-substr doesn't recognize string or symbol
« Reply #1 on: February 07, 2017, 06:50:12 PM »
I don't have time to examine your code but do yourself a solid and define your error handler like this:

(defun *error* (m) (vl-bt))

9/10 you'll find the source of the problem faster tho it may take you a little bit to familiarize yourself with its output.

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: vl-substr doesn't recognize string or symbol
« Reply #2 on: February 07, 2017, 06:56:46 PM »
Symbols such as 'ft' are declared local to drawleader, therefore such symbols will be nil unless defined within the scope of this function - I would instead suggest declaring the symbols local to the smleader function.

dubb

  • Swamp Rat
  • Posts: 1105
Re: vl-substr doesn't recognize string or symbol
« Reply #3 on: February 07, 2017, 07:04:38 PM »
Thanks, note taken.

dubb

  • Swamp Rat
  • Posts: 1105
Re: vl-substr doesn't recognize string or symbol
« Reply #4 on: February 09, 2017, 04:21:57 PM »
I have edited my code now. It seems to work better. However I can't seem to localize these variables.
Code: [Select]
(defun smleader(opt file / ltext ft offset l w newstr)

Code: [Select]
;Preformatted text
;
;
;Example: Rectangle
;COMMAND: (smleader "RECT "big-rect")
;big-rect.txt file contents
;THIS IS A <L>' X <W>' RECTANGLE

;Example: Length
;COMMAND (smleader "Length" "the-length")
;the-length.txt file contents
;THIS IS A <FT>' LONG LINE

;Example: Equipment
;COMMAND: (smleader "EQUIP" "new-equipment")
;new-equipment.txt contents
;THE NEW EQUIPMENT IS <FT>', <OFFSET>
;STA. <STA>


(defun smleader(opt file / ltext)
  (cond
    ((= opt "EQUIP")
     (progn
       (initget "B\\CF F\\CF B\\EOP F\\EOP")
       (setq offset (getkword "\nWhich curb offset [B\\CF/F\\CF/B\\EOP/F\\EOP]:"))
       (cond
((= offset "B\\CF")
  (setq offset "B/CF")
  )
((= offset "F\\CF")
  (setq offset "F/CF")
  )
((= offset "B\\EOP")
  (setq offset "B/EOP")
  )
((= offset "F\\EOP")
  (setq offset "F/EOP")
  )
)
       (setq ft (rtos (getint "\nWhat is the offset distance?: ")2 0))
       (setq sta (getstring "\nEnter station number: "))
       )
     )
    ((= opt "LENGTH")
     (setq ft (rtos (getint "\nHow many feet in length?: ")2 0))
     )
    ((= opt "RECT")
     (setq l (rtos (getint "\nEnter length")2 0))
     (setq w (rtos (getint "\nEnter width")2 0))
     )
    )
  (setq filename (findfile (strcat file".txt")))
  (setq newstr "")
    (if (setq fn (open filename  "r"))
      (progn
        (while (setq ltext (read-line fn))
          (setq newstr (strcat newstr "\n" ltext))
        )
        (close fn)
(setq newstr (substr newstr 2 (strlen newstr)))
(setq newstr (vl-string-subst ft "<FT>" newstr 0))
(setq newstr (vl-string-subst offset "<OFFSET>" newstr 0))
(setq newstr (vl-string-subst sta "<STA>" newstr 0))
(setq newstr (vl-string-subst l "<L>" newstr 0))
(setq newstr (vl-string-subst w "<W>" newstr 0))
      )
    )
    (command "leader" pause pause "" "" "" newstr "")
    (princ)
  )