Visual LISP, AutoLISP and General Customization

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

Combining Strings

332 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

*Expert Elite*
hmsilva
Posts: 2,667
Registered: ‎12-17-2004
Message 2 of 12 (327 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,264
Registered: ‎09-13-2004
Message 3 of 12 (322 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
Valued Mentor
gasty1001
Posts: 444
Registered: ‎04-11-2010
Message 4 of 12 (319 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 (311 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 (251 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: 2,667
Registered: ‎12-17-2004
Message 7 of 12 (241 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 (235 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: 2,667
Registered: ‎12-17-2004
Message 9 of 12 (233 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,264
Registered: ‎09-13-2004
Message 10 of 12 (229 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community