Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Using concatenated variable-names with 'foreach'
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Using concatenated variable-names with 'foreach' (Read 1297 times)
0 Members and 1 Guest are viewing this topic.
Peter2
Swamp Rat
Posts: 654
Using concatenated variable-names with 'foreach'
«
on:
March 21, 2015, 02:57:24 PM »
Maybe a crazy idea (or a simple with the right function ..), but I would like to know if variable-names can be used in a concatenated (and simple ...) form.
I have a code like this:
Code - Auto/Visual Lisp:
[Select]
(
if
(
=
rad_AA
1
)
(
setq
val_AA
(
+
top_AA left_AA
)
)
)
(
if
(
=
rad_BB
1
)
(
setq
val_BB
(
+
top_BB left_BB
)
)
)
....
and
20
more ...
Can it be done in a kind of loop like
Code - Auto/Visual Lisp:
[Select]
(
foreach
MyValue
(
list
AA BB
)
(
if
(
=
rad_MyValue
1
)
(
setq
val_MyValue
(
+
top_MyValue left_MyValue
)
)
)
)
Have a fine weekend.
Logged
Peter
AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23
Lee Mac
Seagull
Posts: 12927
London, England
WWW
Re: Using concatenated variable-names with 'foreach'
«
Reply #1 on:
March 21, 2015, 03:40:05 PM »
Code - Auto/Visual Lisp:
[Select]
(
foreach
suf '
(
"AA"
"BB"
)
(
if
(
=
1
(
eval
(
read
(
strcat
"rad_"
suf
)
)
)
)
(
set
(
read
(
strcat
"val_"
suf
)
)
(
+
(
eval
(
read
(
strcat
"top_"
suf
)
)
)
(
eval
(
read
(
strcat
"left_"
suf
)
)
)
)
)
)
)
Though using lists is usually a far better approach.
Logged
Lee Mac Programming
•
Twitter
•
Exchange App Store
Peter2
Swamp Rat
Posts: 654
Re: Using concatenated variable-names with 'foreach'
«
Reply #2 on:
March 21, 2015, 03:46:44 PM »
Hi Lee
thanks a lot.
Quote from: Lee Mac on March 21, 2015, 03:40:05 PM
Though using lists is usually a far better approach.
?? Can you gave a simple example?
Logged
Peter
AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Using concatenated variable-names with 'foreach'