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

USERS1 Help

24 REPLIES 24
Reply
Message 1 of 25
pokey302
763 Views, 24 Replies

USERS1 Help

Hey all,

I am sorry if i am using the wrong terminology but, I am trying to run a macro on a custom button to where i can input a USERS1 variable and it will input that variable into my find/replace string. The problem is, its not entering the variable that i assign, it is only displaying the code.

Here is my button:
^CUSERS1;\CHT;all;;t;g;F1;F1(getvar "USERS1");;

(CHT is a find and replace LISP I use btw)

Here is what I want it to do:
Find any occurance of “F1” and add the variable I assign to USERS1 after “F1” to make one string of text.

Example: I hit my button, it asks for the USERS1 value, I type "ABC" and hit enter.

The end result should be “F1ABC”

Here is what the result is instead:
“F1(getvar "USERS1")”

Any idea how I can make it input the USERS1 instead of the code? One person suggested that I set TEXTEVAL to (1) but this did not help.
24 REPLIES 24
Message 2 of 25
Anonymous
in reply to: pokey302

Try (strcat "F1" (getvar "USERS1"))
Message 3 of 25
pokey302
in reply to: pokey302

The result of that is still the same result. It is displaying the code, not the USERS1 variable.

“F1(strcat "F1" (getvar "USERS1"))”
Message 4 of 25
Anonymous
in reply to: pokey302

^C^CUSERS1;\CHT;all;;t;g;F1;(strcat "F1" (getvar "USERS1"));;
Message 5 of 25
pokey302
in reply to: pokey302

It it the same result. Here is a copy of what it does:


Command: USERS1
Enter new value for USERS1, or . for none <"">: 123
Command: CHT
Change text, Version 1.02, (c) 1990-1993 by Autodesk, Inc.
Select text to change.
Select objects: all
677 found
Select objects:
Verifying the selected entities -- please wait.
190 text entities found.
Height/Justification/Location/Rotation/Style/Text/Undo/Width: t
Search and replace text. Individually/Retype/:g
Match string : F1
New string : (strcat "F1" (getvar "USERS1"))
Can't reenter LISP.
Changed 8 text lines.

ORIGINAL STRING ON SCREEN:
F1-1

RESULT ON SCREEN:
(strcat "F1" (getvar "USERS1"))-1
Message 6 of 25
Anonymous
in reply to: pokey302

It's that old "Can't reenter LISP" thing, by which it doesn't evaluate the (strcat) function but
returns it unevaluated. You might try defining the new text string using (strcat), and saving it as
a variable, *before* getting into the CHT command, and then feeding that variable into CHT the way
you feed F1 in. But (without trying it) I wonder whether that might return the variable name
instead of the value stored in it, since your F1 is not a variable but an actual text string, and it
seems to accept that without the ""s that you need to use in Lisp expressions.
--
Kent Cooper


wrote...
It it the same result. Here is a copy of what it does:

Command: USERS1
Enter new value for USERS1, or . for none <"">: 123
Command: CHT
Change text, Version 1.02, (c) 1990-1993 by Autodesk, Inc.
Select text to change.
Select objects: all
677 found
Select objects:
Verifying the selected entities -- please wait.
190 text entities found.
Height/Justification/Location/Rotation/Style/Text/Undo/Width: t
Search and replace text. Individually/Retype/:g
Match string : F1
New string : (strcat "F1" (getvar "USERS1"))
Can't reenter LISP.
Changed 8 text lines.

ORIGINAL STRING ON SCREEN:
F1-1

RESULT ON SCREEN:
(strcat "F1" (getvar "USERS1"))-1
Message 7 of 25
Anonymous
in reply to: pokey302

Yeah, that's what happens, at least doing CHT on-screen -- it uses the variable name itself as the
text replacement, not the value stored in it.

Look into something like (vl-string-subst), which will accept either a variable name or an internal
(strcat) function, instead of using CHT.

Or would simply using FIND with its 'Replace with:' option work for you?
--
Kent Cooper


"Kent Cooper" wrote...
.... But (without trying it) I wonder whether that might return the variable name
instead of the value stored in it, since your F1 is not a variable but an actual text string, and it
seems to accept that without the ""s that you need to use in Lisp expressions.
--
Kent Cooper

....
Message 8 of 25
Anonymous
in reply to: pokey302

...and its 'Replace All' sub-option, of course....
--
Kent Cooper


"Kent Cooper" wrote...
....
Or would simply using FIND with its 'Replace with:' option work for you?
....
Message 9 of 25
Anonymous
in reply to: pokey302

try using diesel
$(getvar, USERS1)

or $(getenv, XXXX)


wrote in message news:5827486@discussion.autodesk.com...
Hey all,

I am sorry if i am using the wrong terminology but, I am trying to run a
macro on a custom button to where i can input a USERS1 variable and it will
input that variable into my find/replace string. The problem is, its not
entering the variable that i assign, it is only displaying the code.

Here is my button:
^CUSERS1;\CHT;all;;t;g;F1;F1(getvar "USERS1");;

(CHT is a find and replace LISP I use btw)

Here is what I want it to do:
Find any occurance of "F1" and add the variable I assign to USERS1 after
"F1" to make one string of text.

Example: I hit my button, it asks for the USERS1 value, I type "ABC" and hit
enter.

The end result should be "F1ABC"

Here is what the result is instead:
"F1(getvar "USERS1")"

Any idea how I can make it input the USERS1 instead of the code? One person
suggested that I set TEXTEVAL to (1) but this did not help.
Message 10 of 25
pokey302
in reply to: pokey302

^C^CUSERS1;\CHT;all;;t;g;F1;$(getvar, USERS1);;

ORIGINAL STRING:
F1-1

NEW STRING:
USERS1)-1
Message 11 of 25
pokey302
in reply to: pokey302

FIND will not work because i need this to all be able to work from the command prompt. Once i get the first substitution to work, i plan on adding about 10 more so they will all run at once. I am trying to understand the (vl-string-subst) thing so maybe that will help.

I saw on another thread something about using -attedit to replace text but i believe that is only for blocks.
Message 12 of 25
Anonymous
in reply to: pokey302

Kent had the best idea I think - go ahead and stick the F1 prefix in USERS1 before feeding it to the CHT routine.

The problem you had was that you can't use a lisp function like strcat to rovide answers to another lisp function like your CHT. Try this:

^C^CUSERS1;\(setvar "users1" (strcat "F1" (getvar "USERS1")));CHT;all;;t;g;F1;(getvar "USERS1");;

It's considered good practice to put two cancels at the beginning of a macro to make sure that subcommands are cancelled.
Message 13 of 25
pokey302
in reply to: pokey302

Tom,

I tried what you had posted and unfortunately it’s the same results in the end. I think I need to get away from the CHT command but then im just stuck with searching for a find and replace alternate that will work from the command prompt. But from what i have seen on this forum, it doesn’t exist. That’s why i was hoping to use the CHT command.
Message 14 of 25
Anonymous
in reply to: pokey302

I agree life would be simpler if you could use the routine you have. Why don't you post the results of the using the macro I posted above.

All it's doing is adding "F1" to whatever the user assigns to the USERS1 variable.

Obviously, you could just require the user to type the whole string, including the F1.
Message 15 of 25
pokey302
in reply to: pokey302

^C^CUSERS1;\(setvar "users1" (strcat "F1" (getvar "USERS1")));CHT;all;;t;g;F1;(getvar "USERS1");;

ORIGINAL STRING:
F1-4

RESULTING STRING:
(getvar "USERS1")-4


I am trying to avoid any typing because i want to repeat the command over many different text variations one after another.
Message 16 of 25
pokey302
in reply to: pokey302

This is basically what it is doing (see attached). The end result varies depending on the code i used.

I want to do this for F1, B1, T1, S1, etc. And some more that are not shown on that screen shot all by just inputing the USERS1 once and it will recall it over and over again each time i execute the CHT.
Message 17 of 25
Anonymous
in reply to: pokey302

Well, I'm about to give up. I don't have your routine to test, and I have to go back to 2004 to test anything, to avoid the nightmare of customizing a button in 2007. I do know, so far, that as per someone else's suggestion, the macro

$M=F1$(getvar, USERS1)

does return "F1" prepended to whatever is stored in USERS1.

Maybe you really need to modify your CHT to work without prompting the user.
Message 18 of 25
Anonymous
in reply to: pokey302

The problem, as I realized in my post following the one in which I suggested that, is that the
(getvar) in there is as much a Lisp function as (strcat), which I assume is why it doesn't work
either. That's why I think CHT isn't going to be the way to go in this instance.

[And by the way, it isn't "his" (or maybe "her") CHT -- that's the command-line invocation for an
old AutoCAD Bonus Tools routine (CHTEXT.LSP) from back in the late '80s/early '90s, and it's
actually pretty cool. I keep it around and still use it sometimes. While Find and the Properties
Box will do much of what it does, it still does some things that they won't, such as replace text in
all instances among a *selected group* of text entities, without having to confirm the replacement
for each, but without doing it in the entire drawing. It seems to use (substr) and (strcat) and
(entmod) to do it -- maybe it predates (vl-string- ) functions which might be able to do this kind
of thing better now. I have the .LSP file if anyone would like to consider whether it can be
modified to do this with a saved Lisp variable value, but it's more than I can tackle right now.]

--
Kent Cooper


wrote...
Kent had the best idea I think - go ahead and stick the F1 prefix in USERS1 before feeding it to the
CHT routine.

The problem you had was that you can't use a lisp function like strcat to rovide answers to another
lisp function like your CHT. Try this:

^C^CUSERS1;\(setvar "users1" (strcat "F1" (getvar "USERS1")));CHT;all;;t;g;F1;(getvar "USERS1");;

....
Message 19 of 25
Anonymous
in reply to: pokey302

My mistake, Kent. I meant to use diesel to retrieve the variable after using lisp to set it. Or use dieseel in both cases. But diesle's really not my strong suit.

Per my last post, I tend to agree with you that doing the whole shooting match in lisp, rather than trying to automate it in the menu macro, would be the way to go. I don't have time to look at it either, except maybe over a weekend, but it probably wouldn't be hard to revise the cht routine to do whatever's intended.
Message 20 of 25
Anonymous
in reply to: pokey302

[...spoke too soon -- Find will do that particular trick after all, but CHT still does some other
cool stuff, like give you the choice of whether to change text content (or Height or Justification
or Style or Width Factor or some other things) globally or individually within the selected group of
text entities, or to do certain things by retyping in a dialog box or at the command line, it
combines aspects of Find and the Properties Box into one command, etc.]
--
Kent Cooper


"Kent Cooper" wrote...
....While Find and the Properties
Box will do much of what it does, it still does some things that they won't, such as replace text in
all instances among a *selected group* of text entities, without having to confirm the replacement
for each, but without doing it in the entire drawing....

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

Post to forums  

Autodesk Design & Make Report

”Boost