Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
ssexton
Posts: 11
Registered: ‎06-06-2005
Message 1 of 12 (357 Views)
Accepted Solution

Combining Strings

357 Views, 11 Replies
05-16-2012 07:52 AM

I'm trying to combine two user inputs and a constant with setq without spaces so I can use it in an AutoCAD command.

I haven't seen a string command that does this. It always has spaces in between the fetched valvues.

 

Thanks for any help


ssexton wrote:

I'm trying to combine two user inputs and a constant with setq without spaces so I can use it in an AutoCAD command.

I haven't seen a string command that does this. It always has spaces in between the fetched valvues.

 

Thanks for any help


I wonder how you're doing it.  For me, it doesn't do that if I don't include spaces in what I enter for the User inputs [a2 is the 'constant' in this case]:

 

Command: (setq a1 (getstring))
What <--- typed in
"What"

Command: (setq a2 "The" a3 (getstring))
Heck <--- typed in
"Heck"

Command: (strcat a1 a2 a3)
"WhatTheHeck"

 

Am I misunderstanding the problem?  Am I at least correct that you want to put strings together without spaces in the first place, rather than remove spaces from the result after the fact, as others' suggestions are designed to do?

Try

 

(setq e (strcat a b aa))
 (command "insert" e "0,0" "" "" "" "")      
)

 

Cheers

Henrique

*Expert Elite*
hmsilva
Posts: 3,019
Registered: ‎12-17-2004
Message 2 of 12 (352 Views)

Re: Combining Strings

05-16-2012 08:10 AM in reply to: ssexton

Try

 

(setq newstring (vl-list->string (vl-remove 32 (vl-string->list yourstring))))

 

Cheers

 

Henrique

*Expert Elite*
Kent1Cooper
Posts: 5,612
Registered: ‎09-13-2004
Message 3 of 12 (347 Views)

Re: Combining Strings

05-16-2012 08:28 AM in reply to: ssexton

ssexton wrote:

I'm trying to combine two user inputs and a constant with setq without spaces so I can use it in an AutoCAD command.

I haven't seen a string command that does this. It always has spaces in between the fetched valvues.

 

Thanks for any help


I wonder how you're doing it.  For me, it doesn't do that if I don't include spaces in what I enter for the User inputs [a2 is the 'constant' in this case]:

 

Command: (setq a1 (getstring))
What <--- typed in
"What"

Command: (setq a2 "The" a3 (getstring))
Heck <--- typed in
"Heck"

Command: (strcat a1 a2 a3)
"WhatTheHeck"

 

Am I misunderstanding the problem?  Am I at least correct that you want to put strings together without spaces in the first place, rather than remove spaces from the result after the fact, as others' suggestions are designed to do?

Kent Cooper
Distinguished Mentor
gasty1001
Posts: 534
Registered: ‎04-11-2010
Message 4 of 12 (344 Views)

Re: Combining Strings

05-16-2012 08:33 AM in reply to: ssexton

Hi,

 

Not sure, but somthing like: (vl-remove-if (function (lambda(x)(= x 32)) (vl-string->list MyString)) will remove the spaces from a string, and (vl-list->string listOfChar) will concatenate back the list.

 

You can put that on a function:

 

(defun StripOutBlanks(MyString)
    (vl-list->string (vl-remove-if
     (function
      (lambda(x)(= x 32)))
      (vl-string->list MyString)
)
)
)

 

use: (StripOutBlanks "Hi There")

return: "HiThere"

 

Gaston Nunez

 

 

Contributor
ssexton
Posts: 11
Registered: ‎06-06-2005
Message 5 of 12 (336 Views)

Re: Combining Strings

05-16-2012 09:03 AM in reply to: ssexton

Thanks everyone for the solutions!!

Contributor
ssexton
Posts: 11
Registered: ‎06-06-2005
Message 6 of 12 (276 Views)

Re: Combining Strings

05-23-2012 07:42 AM in reply to: Kent1Cooper

This worked well. Thanks!

But the insert command wont accept "0,0" as an input. I've also tried:

(setq d1 '(0 0))  and set d1 in the command line for coordinate input but AutoCAD wont accept either.

 

ideas?

*Expert Elite*
hmsilva
Posts: 3,019
Registered: ‎12-17-2004
Message 7 of 12 (266 Views)

Re: Combining Strings

05-23-2012 07:58 AM in reply to: ssexton

ssexton,

can you  post some of your code, so I can see where it gives error...

Contributor
ssexton
Posts: 11
Registered: ‎06-06-2005
Message 8 of 12 (260 Views)

Re: Combining Strings

05-23-2012 08:03 AM in reply to: hmsilva

This is the code line:

 

(setq e (strcat a b aa))
 (command "insert" e "" "0,0" "" "" "" "")
         
)

 

This is the reply I get:

 

Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Point or option keyword required.
; error: Function cancelled
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:

*Expert Elite*
hmsilva
Posts: 3,019
Registered: ‎12-17-2004
Message 9 of 12 (258 Views)

Re: Combining Strings

05-23-2012 08:09 AM in reply to: ssexton

Try

 

(setq e (strcat a b aa))
 (command "insert" e "0,0" "" "" "" "")      
)

 

Cheers

Henrique

*Expert Elite*
Kent1Cooper
Posts: 5,612
Registered: ‎09-13-2004
Message 10 of 12 (254 Views)

Re: Combining Strings

05-23-2012 08:25 AM in reply to: ssexton

ssexton wrote:

This is the code line:

 

(setq e (strcat a b aa))
 (command "insert" e "" "0,0" "" "" "" "") 
)

....


As hmsilva suggested, you don't want that Enter [""] between the Block name and the insertion point.  [It's not like object selection in an editing command, where you need to tell it you're done selecting -- you can't Insert more than one Block name at a time.]

 

Also, I think you have more Enters at the end than you need, unless maybe the Block includes an Attribute that you want to accept a default value for, and you have ATTDIA set to 0.  And unless you need to have it saved for some later use, the Block name could just be "built" right inside the Insert command, with no need for the 'e' variable:

 

(command "insert" (strcat a b aa) "0,0" "" "" "")

Kent Cooper
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.