Jump to content

Recommended Posts

Posted

HELLO. :)

 

I need help with this code please, The text command can't insert the variable due to the parentheses .

 

So how can I convert the variable to string to be free from parentheses ? :lol:

 

(setq p1 '(1 2 3 4))
(command "._text" pause "" "" p1)

 

*** THANK YOU ALL GUYS and maybe GIRLS ***

 

Sweety

Posted

Hi

 

What way do you want the list to be formatted in the text?

 

'(1 2 3 4) - >

Posted

Thanks.

 

Actually is there any function to remove the parentheses and keep the string alone ?

 

In this case I want the result to be without parentheses like this ...

 

1 2 3 4

 

Thanks

Posted

You could have a look at visual basic string parsing, this is a good page http://www.rentron.com/parsingstrings.htm

 

dim charcount as integer

dim s as string

 

s="(0 1 2 3 4)"

s=mid$(s,2,len(s)-2)

 

 

'now s should have a value of "0 1 2 3 4"

Posted

In short, 'No' there isn't a single command to convert a list to a string.

 

 

If you are dealing with file outputs: (prin1 list file) does output a list in strings format to an external file

 

 

Converting a list to a concatenated string can be very difficult if the atoms in the list are not the same type or are things like enames or other lists. -David

Posted (edited)

Not a very intelligent routine but maybe as a test

 

(defun list->str (<list> / tempStr )
 (vl-load-com)
 (setq tempStr (vl-prin1-to-string <list>))

 (if
   (wcmatch  tempStr "(*)")
   (substr tempStr 2 (- (strlen tempStr) 2))
   tempStr
 )
 )

(list->str '(1 2 3 4 ))

 

I would however agree with Daivd. Ideally you should process each item in the list & filter as you go along. Maybe try writing your own version bearing that in mind & post if you have any difficulties

Edited by jammie
Posted

Thank you David.

 

And also the following codes are not combing the numbers .

 

(setq p1 '(1 2 3 4)
     )
(setq one (nth 0 p1)
     two (nth 1 p1)
     three (nth 2 p1)
     four (nth 3 p1)
     )
(command "._text" pause "" "" (strcat one "" two "" three "" four))

 

Thankxxxxx

Posted

And also the following codes are not combing the numbers .

 

(setq p1 '(1 2 3 4)
     )
(setq one (nth 0 p1)
     two (nth 1 p1)
     three (nth 2 p1)
     four (nth 3 p1)
     )
(command "._text" pause "" "" (strcat one "" two "" three "" four))

 

The items stored in p1 are integers, your will need to convert them to strings before you can use strcat

 

(setq nr 2)
(setq str (rtos nr 2 0))

Posted
The items stored in p1 are integers, your will need to convert them to strings before you can use strcat

(setq nr 2)
(setq str (rtos nr 2 0))

 

Exactly. you're right .

 

Here it goes .....

 

(setq p1 '(1 2 3 4)
     )
(setq one (nth 0 p1)
     two (nth 1 p1)
     three (nth 2 p1)
     four (nth 3 p1)
     )
(command "._text" pause "" "" (strcat (rtos one 2 0) " " (rtos two 2 0) " " (rtos three 2 0) " " (rtos four 2 0)))

 

Thankxxxxxxxxxxxxxxxx

Posted
Not a very intelligent routine but maybe as a test

(defun list->str (<list>/ tempStr )
(vl-load-com)
(setq tempStr (vl-prin1-to-string <list>))
(if (wcmatch tempStr "(*)")
   (substr tempStr 2 (- (strlen tempStr) 2))
tempStr
))
(list->str '(1 2 3 4 ))

I would however agree with Daivd. Ideally you should process each item in the list & filter as you go along. Maybe try writing your own version bearing that in mind & post if you have any difficulties

 

Thank you so much, Your codes are really perfect and amazing . :thumbsup:

I use it with this.

(setq p1 '(1 2 3 4)
     )
(command "_.text" pause "" "" (list->str p1))

 

greatly appreciated.

 

Sweety

Posted

A REALLY ugly way to go about the task:

 

[b][color=BLACK]([/color][/b]setq l1 [b][color=FUCHSIA]([/color][/b]list [b][color=NAVY]([/color][/b]entlast[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
      l2 [b][color=FUCHSIA]([/color][/b]cons '[b][color=NAVY]([/color][/b]62 . 5[b][color=NAVY])[/color][/b] l1[b][color=FUCHSIA])[/color][/b]
      l3 [b][color=FUCHSIA]([/color][/b]cons 123 l2[b][color=FUCHSIA])[/color][/b]
      l4 [b][color=FUCHSIA]([/color][/b]append l3 [b][color=NAVY]([/color][/b]list [color=#2f4f4f]"ABC"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
      l5 [b][color=FUCHSIA]([/color][/b]cons nil l4[b][color=FUCHSIA])[/color][/b]
      l6 [b][color=FUCHSIA]([/color][/b]cons 'a l5[b][color=FUCHSIA])[/color][/b]
      l7 [b][color=FUCHSIA]([/color][/b]cons '[b][color=NAVY]([/color][/b]0.0 0.0 1.0[b][color=NAVY])[/color][/b] l6[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

[b][color=BLACK]([/color][/b]setq wf [b][color=FUCHSIA]([/color][/b]open [color=#2f4f4f]"test.txt"[/color] [color=#2f4f4f]"w"[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]prin1 l7 wf[b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]close wf[b][color=BLACK])[/color][/b]

[b][color=BLACK]([/color][/b]setq rf [b][color=FUCHSIA]([/color][/b]open [color=#2f4f4f]"test.txt"[/color] [color=#2f4f4f]"r"[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]setq str [b][color=FUCHSIA]([/color][/b]read-line rf[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]close rf[b][color=BLACK])[/color][/b]

[b][color=BLACK]([/color][/b]prin1 l7[b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]terpri[b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]princ str[b][color=BLACK])[/color][/b]

 

-David

Posted

another way of doing it...

 

 
(defun c:test (/ p1 ins)
 (setq p1 '(1 2 3 4))
 (setq ins (getpoint "\nSpecify insertion point: "))
 (entmakex
   (list
     (cons 0  "text")
     (cons 1  (strcat (itoa (car p1)) " " (itoa (cadr p1)) " " (itoa (caddr p1)) " " (itoa (cadddr p1))))
     (cons 7  (getvar 'textstyle))
     (cons 8  (getvar 'clayer))
     (cons 10 ins)
     (cons 40 (getvar 'textsize))
     (cons 41 1.0)
   )
 )
 (princ)
)

Posted
another way of doing it...

 

 
(defun c:test (/ p1 ins)
(setq p1 '(1 2 3 4))
(setq ins (getpoint "\nSpecify insertion point: "))
(entmakex
(list
(cons 0 "text")
(cons 1 (strcat (itoa (car p1)) " " (itoa (cadr p1)) " " (itoa (caddr p1)) " " (itoa (cadddr p1))))
(cons 7 (getvar 'textstyle))
(cons 8 (getvar 'clayer))
(cons 10 ins)
(cons 40 (getvar 'textsize))
(cons 41 1.0)
))
(princ)
)

 

Thank you Dan's. :)

 

A very nice technique of works .

 

Appreciated.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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