Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Combining Strings

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
ssexton
1166 Views, 11 Replies

Combining Strings

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

11 REPLIES 11
Message 2 of 12
hmsilva
in reply to: ssexton

Try

 

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

 

Cheers

 

Henrique

EESignature

Message 3 of 12
Kent1Cooper
in reply to: ssexton


@Anonymous 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, AIA
Message 4 of 12
hgasty1001
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

 

 

Message 5 of 12
ssexton
in reply to: ssexton

Thanks everyone for the solutions!!

Message 6 of 12
ssexton
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?

Message 7 of 12
hmsilva
in reply to: ssexton

ssexton,

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

EESignature

Message 8 of 12
ssexton
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]:

Message 9 of 12
hmsilva
in reply to: ssexton

Try

 

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

 

Cheers

Henrique

EESignature

Message 10 of 12
Kent1Cooper
in reply to: ssexton


@Anonymous 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, AIA
Message 11 of 12
ssexton
in reply to: hmsilva

I appreciate everyone's help. This is going to automate some things for us!

Message 12 of 12
hmsilva
in reply to: ssexton

You're welcome, ssexton.

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost