Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Toggle by macro

Shay.Gaghe
Advocate

Toggle by macro

Shay.Gaghe
Advocate
Advocate

Hi

Can I set a toggle in a macro? For example, in the Toggle Coords command i see in the macro

'_.coords $M=$(if,$(and,$(getvar,coords),2),0,$(+,$(getvar,coords),1))

 

i belive its a toggle condition.

 

can someone translate it so i can understand the logic?

 

Thanks

Shay

Using Autocad 2018, Autocad Architecture.
Please accept as solution if i solved your problem
0 Likes
Reply
Accepted solutions (3)
1,037 Views
3 Replies
Replies (3)

Moshe-A
Mentor
Mentor
Accepted solution

@Shay.Gaghe  hi,

 

it's a diesel macro that toggle from 0 to 2. the diesel AND function is a bitwise logical AND of the integers. only when all supply arguments are 2, the function return 2. so when COORDS is 2 the macro set COORDS to 0 otherwise it add 1 to current COORDS value 😀

 

Moshe

 

 

 

0 Likes

Kent1Cooper
Consultant
Consultant
Accepted solution

That one is actually a cycling  routine, not strictly a toggle [which, in my mind anyway, switches between two  values, such as 0 and 1 for System Variables that have only those two -- on/off situations].  If the value is 2 it sets it to 0; if it's 0, it sets it to 1, if it's 1, it sets it to 2.  Operationally, if it's 2, it sets it to 0, otherwise it sets it to one more than its current value.

 

Another way to do that is to use a (rem) [remainder] function -- here in AutoLisp format [the Diesel functions reference doesn't list an equivalent]:

(setvar 'coords (rem (1+ (getvar 'coords)) 3))

Kent Cooper, AIA
0 Likes

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

.... here in AutoLisp format [the Diesel functions reference doesn't list an equivalent]....


... but some AutoLisp expressions can  be used in Tool Palette buttons, including this one -- it doesn't need to be Diesel language to work in a macro.

Kent Cooper, AIA
0 Likes