Jump to content
juicyorange

If a var is a SYM, convert to string

Recommended Posts

juicyorange

Hey all,

 

I am having an issue where I grab an element from a list and set it to a var and the var is a "SYM" data type.

 

I am trying to test for that data type and then convert it into a string. However, my current test:

 

    (if (= (type PtNo) "SYM")

      (setq PtNo (vl-symbol-name PtNo))

      ;;end if
      )

Doesn't return true.

 

Any and all insights into this are welcome.

 

 

Share this post


Link to post
Share on other sites
dlanorh

It works for me with minimum testing. What string are you expecting (vl-symbol-name PtNo) to return?

Share this post


Link to post
Share on other sites
juicyorange
Posted (edited)

Sorry, I should be more clear.

 

When I test for "SYM" it isn't returning true when it actually is a data type "SYM", it just skips over the "then" part of the if function.

 

Here's the full code:

NOTE: I am still working on proof of concept, I'll be doing all of the error trapping when I can get it to work the way I need it to. I also haven't cleaned it up yet.

 

;; This lisp routine xxx

(vl-load-com)
(defun c:ImportCSV (/ csvfile Opencsvfile csvdataline readline ctr n readlinestring readlinelist xval yval zval ptno descr coord coordtext test)
;-----------------------------------------------------------------------;
  
  ;; error handler
  (defun *error* (msg)
    (princ "\nError: ")
    (princ msg)
    (princ)
  )
;-----------------------------------------------------------------------;
 
  (setq csvfile (getfiled "Select CSV File"
			  "C:/Users/Jesse/Desktop/"
			  "csv"
			  10
			  )

	;;end setq
	)

  (setvar "CMDECHO" 0)
  
  (setq OpenCsvFile (open csvfile "r"))

  (while

    (setq CsvDataLine (read-line OpenCsvFile)
	  ReadLine CSVDataLine
	  )
    
    (setq ctr 0)

    ;;delete "

        (while

      (if (setq n (vl-string-search "\"" Readline 0))

	(setq Readline (vl-string-subst " " "\"" Readline ctr)
	      ctr n
	      )
	

	;;end if
	)

      ;;end while
      )
    
    (setq ctr 0)

    ;;delete spaces
    (while

      (if (setq n (vl-string-search " " Readline 0))

	(setq Readline (vl-string-subst "" " " Readline ctr)
	      ctr n
	      )
	
	;;end if
	)

      ;;end while
      )

    (setq ctr 0)

    ;;replace commas with spaces
    (while

      (if (setq n (vl-string-search "," Readline 0))

	(setq Readline (vl-string-subst " " "," Readline ctr)
	      ctr n
	      )
	
	;;end if
	)

      ;;end while
      )

    (setq ReadLineString (strcat "(" Readline ")")
	  ReadLineList (read ReadLineString)
	  XVal (cadr ReadLineList)
	  YVal (caddr ReadLineList)
	  ZVal (cadddr ReadLineList)
	  PtNo (car ReadLineList)
	  Coord (list XVal YVal ZVal)
	  )

    (setq test (type PtNo))
    (if (= (type PtNo) "SYM")

      (setq PtNo (vl-symbol-name PtNo))

      ;;end if
      )
    (setq test (type PtNo))

    (if ( = (length ReadLineList) 5)
      (progn
      (setq Descr (nth 4 ReadLineList)
	     Descr (vl-symbol-name Descr)
	    )

      (command
	  "_.point" Coord
	  "_.text" Coord ".1" "" PtNo
	  "_.text" Coord ".1" "" Descr
	  )
      
      (setq txtbx (entlast))
      
      (command "_.move" txtbx "" "0,0" "0,-0.12")
      
      
      ;;end progn
      )

       (command
	 "_.point" Coord
	 "_.text" Coord ".1" "" PtNo
	 )

     ;;end if
      )

    ;;end while
    )

  (close OpenCSVFile)

  (setvar "PDMODE" 35)
  (setvar "PDSIZE" 0.2)
  (setvar "CMDECHO" 1)
 
  ;;End Defun
  )

 

Edited by juicyorange

Share this post


Link to post
Share on other sites
ronjonp
Posted (edited)

If you're reading a CSV and looking at the (type) it will always return 'STR ? Maybe you're trying to see if the text = "SYM" ?

 

If so then this should work:

(if	(= ptno "SYM")
      (setq ptno (vl-symbol-name ptno))
      ;;end if
    )

 

Edited by ronjonp

Share this post


Link to post
Share on other sites
juicyorange

Per the attached debug screenshot, you can see when i test for the type of the PtNo var I get "SYM"

debug1.png

Share this post


Link to post
Share on other sites
ronjonp
Posted (edited)

Hmmm .. then all you have to do is change your syntax: 

 

(= 'sym (type ptno))

I did not read all your code to see this part that converts to numbers and a symbol:

(setq ReadLineString (strcat "(" Readline ")")
	  ReadLineList (read ReadLineString)

 

Edited by ronjonp

Share this post


Link to post
Share on other sites
Lee Mac

The type function returns a symbol, not a string (regardless of the data type held by a variable), therefore you need to compare the value returned by the type function with a symbol, not a string as in your current code.

 

Observe the following:

_$ (setq a "string")
"string"
_$ (type a)
STR
_$ (type (type a))
SYM

_$ (setq a 'b)
B
_$ (type a)
SYM
_$ (type (type a))
SYM
_$ (= 'sym (type a))
T

 

Share this post


Link to post
Share on other sites
juicyorange
Posted (edited)

that worked swimmingly!

thanks ronjonp!

Edited by juicyorange

Share this post


Link to post
Share on other sites
juicyorange
28 minutes ago, Lee Mac said:

The type function returns a symbol, not a string (regardless of the data type held by a variable), therefore you need to compare the value returned by the type function with a symbol, not a string as in your current code.

 

Observe the following:


_$ (setq a "string")
"string"
_$ (type a)
STR
_$ (type (type a))
SYM

_$ (setq a 'b)
B
_$ (type a)
SYM
_$ (type (type a))
SYM
_$ (= 'sym (type a))
T

 

Thanks for the explanation, this makes more sense now!

Share this post


Link to post
Share on other sites
ronjonp
On 6/6/2019 at 3:58 PM, juicyorange said:

that worked swimmingly!

thanks ronjonp!

Glad to help :)

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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