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

variable to a manipulative text sting

8 REPLIES 8
Reply
Message 1 of 9
kpennell
507 Views, 8 Replies

variable to a manipulative text sting

Say I want to get the current dimstyle of a drawing.
Well, I want to set that to a variable, so that I can take bits and pieces of the name by using "substr" and then connecting what I take with something else with "strcat." There are no entities to select. I thought this would work...

(setq ssccurrent (getvar "dimstyle"))
(setq length (strlen ssccurrent))

(cond
((= length 13)(setq dimscale (substr 6 1)))
((= length 14)(setq dimscale (substr 6 2)))
((= length 15)(setq dimscale (substr 6 3)))
);cond

...bloody hell
8 REPLIES 8
Message 2 of 9
jbecker-vector
in reply to: kpennell

change "length" to something else.
it is a AutoLisp function like "last" was

this change should do it

P.S. you just can't stay away from built-in fuction names can you 🙂
Message 3 of 9
kpennell
in reply to: kpennell

i changed it to "txtlen" still the same error
Message 4 of 9
jbecker-vector
in reply to: kpennell

sorry, I did not read completely through the code...

change

((= length 15)(setq dimscale (substr 6 3)))

to

((= length 15)(setq dimscale (atoi (substr 6 3))))

need to change the sub string to an integer (or real, but assumed that it would be an integer) because dimscale is a number not a string

what is an example dimstyle name?

it will all be over soon!
Message 5 of 9
Anonymous
in reply to: kpennell

mnash wrote:
> Say I want to get the current dimstyle of a drawing.
> Well, I want to set that to a variable, so that I can take bits and pieces of the name by using "substr" and then connecting what I take with something else with "strcat." There are no entities to select. I thought this would work...
>
> (setq ssccurrent (getvar "dimstyle"))
> (setq length (strlen ssccurrent))
>
> (cond
> ((= length 13)(setq dimscale (substr 6 1)))
> ((= length 14)(setq dimscale (substr 6 2)))
> ((= length 15)(setq dimscale (substr 6 3)))
> );cond
>
> ...bloody hell

You're not providing the (substr) function with a string to chew on.
Message 6 of 9
kpennell
in reply to: kpennell

again I have the name of a variable set to a built-in function, so may be there is confusion about what the "dimscale" is suppose to represent, it's suppose to represent a string of text that has letters and number, not the actual scale of the dim
Message 7 of 9
jbecker-vector
in reply to: kpennell

Now that I have screwed you up enough...

(setq ssccurrent (getvar "dimstyle"))
(setq dlength (strlen ssccurrent))
(cond
((= dlength 13)(setvar "dimscale" (atoi (substr sscurrent 6 1))))
((= dlength 14)(setvar "dimscale" (atoi (substr sscurrent 6 2))))
((= dlength 15)(setvar "dimscale" (atoi (substr sscurrent 6 3))))
)
Message 8 of 9
Anonymous
in reply to: kpennell

You're missing naming the string in the (substr) functions. Try:

((= length 13)(setq dimscale (substr length 6 1)))
((= length 14)(setq dimscale (substr length 6 2)))
((= length 15)(setq dimscale (substr length 6 3)))

But I agree you should avoid using 'length' as a variable name, and also
'dimscale'.
--
Kent Cooper


wrote...
Say I want to get the current dimstyle of a drawing.
Well, I want to set that to a variable, so that I can take bits and pieces
of the name by using "substr" and then connecting what I take with something
else with "strcat." There are no entities to select. I thought this would
work...

(setq ssccurrent (getvar "dimstyle"))
(setq length (strlen ssccurrent))

(cond
((= length 13)(setq dimscale (substr 6 1)))
((= length 14)(setq dimscale (substr 6 2)))
((= length 15)(setq dimscale (substr 6 3)))
);cond

...bloody hell
Message 9 of 9
Anonymous
in reply to: kpennell

>you should avoid using 'length' as a variable name, and also
'dimscale'

Kent, I sort of agree, in a general way. There's a difference between the two, though, in that length is a "reserved word" in lisp, whereas dimscale is an Acad variable. Using a symbol named dimscale doesn't stomp on the variable:

Command: (setq dimscale 100)
100
Command: (getvar 'dimscale)
48.0

Whereas misusing the lisp function length does do harm:
Command: (setq length 100)
100
Command: (length '(x y z))
; error: bad function: 100

I don't think this would especially matter outside the present function if the variable length is declared local, but nevertheless it's bad practice to redefine built-in functions. I think it will triggger warnings in VLIDE and compiler errors.

Some people think it's confusing to use local variables matching the names of system variables, but personally I don't have a problem with it. It just means that your local variable name is the same as the sysvar:

Command: (setq dimscale (getvar 'dimscale))
48.0

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

Post to forums  

Autodesk Design & Make Report

”Boost