TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Cawaugh on January 02, 2007, 11:06:45 AM

Title: Strcat text with a list
Post by: Cawaugh on January 02, 2007, 11:06:45 AM
(write-line (strcat "(find_replace " includetxt " " mdwg " " mstringlist " " SearchAtt " " case " " firstonly ")") Ofil)

The above gives me an error which I believe is due to trying to strcat text with lists. mstringlist and SearchAtt are lists. How can I get these lists into a script file with write-line? What I am trying to do is pass a list as an argument to the find_replace function. When the script is run it has this as a line to be read:
(find_replace "1" "y" list-of-strings-to-look-for list-of-atts-to-search-through "1" "1")
Thanks in advance for any help. :-)
Title: Re: Strcat text with a list
Post by: T.Willey on January 02, 2007, 11:27:28 AM
Chuck,

  When you want to string characters (strcat) and an item is a list, use 'vl-princ-to-string' for that item.  So something like
Code: [Select]
(strcat
 "Happy"
 (vl-princ-to-string '(1 2 3 45))
 (setq Test " This is a test. ")
)
Returns
Quote
"Happy(1 2 3 45) This is a test. "

Hope that helps.
Title: Re: Strcat text with a list
Post by: CAB on January 02, 2007, 11:54:26 AM
Breaking this down:
Code: [Select]
(write-line (strcat "(find_replace " includetxt " " mdwg " " mstringlist "
                                           " SearchAtt " " case " " firstonly ")") Ofil)

It would appear that find_replace takes several string arguments
Code: [Select]
(find_replace " includetxt " " mdwg " " mstringlist " " SearchAtt " " case " " firstonly ")
And returns a string that is then written to a file.

If that is the case then no strcat is needed.
Code: [Select]
(write-line (find_replace " includetxt " " mdwg " " mstringlist " " SearchAtt " " case " " firstonly ") Ofil)
If that is not the case then more information on the find_replace function is needed.
Title: Re: Strcat text with a list
Post by: Cawaugh on January 03, 2007, 09:57:46 AM
Chuck,

  When you want to string characters (strcat) and an item is a list, use 'vl-princ-to-string' for that item.  So something like
Code: [Select]
(strcat
 "Happy"
 (vl-princ-to-string '(1 2 3 45))
 (setq Test " This is a test. ")
)

Returns
Quote
"Happy(1 2 3 45) This is a test. "

Hope that helps.

What I am finding out is that I cannot get a list written out so that when the script is run the below setq will not work. I'm trying to set the variable mstringlist to a list but the strcat won't let me.
(write-line (strcat "(setq " "mstringlist " mstringlist ")") Ofil)
Title: Re: Strcat text with a list
Post by: T.Willey on January 03, 2007, 11:15:29 AM
Maybe this
Code: [Select]
(write-line
 (strcat
  "(find_replace "
  includetxt
  " "
  mdwg
  " "
  (vl-princ-to-string mstringlist)
  " "
  (vl-princ-to-string SearchAtt)
  " "
  case
  " "
  firstonly
  ")"
 )
 Ofil
)
Title: Re: Strcat text with a list
Post by: CAB on January 03, 2007, 11:59:28 AM
Boy, I sure missed that one. :-o
Title: Re: Strcat text with a list
Post by: T.Willey on January 03, 2007, 12:14:08 PM
Boy, I sure missed that one. :-o
Thats okay, you can have the next one then  Alan.   :-D