If/expression/true/false logic for a layer color toggle

If/expression/true/false logic for a layer color toggle

dpierson6B4ETP
Participant Participant
454 Views
4 Replies
Message 1 of 5

If/expression/true/false logic for a layer color toggle

dpierson6B4ETP
Participant
Participant

In a previous post, I presented an issue that needs to be solved by a DIESEL expression. The task is to create a macro that toggles the current layer color between red and green.

 

I set up USERI1 and USERI2 via -setvar as values "1", and "3" to act as their respective color values for red and green. Then I created a layer command to set the layer color via the variable vice a straight, typed-in value (in this case "1" for "red" using the -layer color command). I also set the cecolor to "bylayer", so both the block and layer match.

 

I know my variable works, because when I use this macro, the layer turns red (from any color):

 

^C^C-layer;c;$M=$(getvar, USERI1);;;

 

However, I don't know enough about DIESEL syntax to set up the logic toggle between layer color red and green properly. I am not a programmer nor do I have any experience beyond a week or so of Autocad automation.  What mistakes am I making below?  Is the logic sound?

 

^C^C-layer;c;$M=$(if,$(=,$(getvar,USERI1),getvar,USERI2);;,getvar,USERI1;;)

 

I also toyed with this which sets up the layer color in red first, then moves on to the logic toggle:

 

^C^C-layer;c;$M=$(getvar, USERI1)^C;$M=$(if,$(=,$(getvar,USERI1),getvar,USERI2;;,getvar,USERI1;;)

 

Beyond the first macro listed above, none of the others work. Any CONCRETE, non-cryptic, help would be appreciated. Even a tangential example using a USERI variable working properly would help. I'm a working family guy, taking night school classes so my ability to spend hours trying to learn DIESEL is limited, but I'm trying!

0 Likes
Accepted solutions (1)
455 Views
4 Replies
Replies (4)
Message 2 of 5

cadffm
Consultant
Consultant
Accepted solution

You can't check the current-Layer color, so it will never work for the "current layer" (not with diesel only).

If you need it for "current layer", you need Lisp or any other API.

 

For a specific layer, lets say layer "MyFavLayer" it is possible (by accepting one small issue, because you still can check the initial layer color).

Sample to toggle between freeze and thawed, Layername "TET"

$M=$(if,$(eq,$(getvar,USERR1),0),USERR1;1;_.-LAYER;_f;TET;,USERR1;0;_.-LAYER;_th;TET; )

 

Sebastian

Message 3 of 5

paullimapa
Mentor
Mentor

I remember your previous post. So did you learn the answer on your class assignment from that post?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 5

dpierson6B4ETP
Participant
Participant

SUCCESS...sorta...

 

I co-opted your DIESEL and came up with this:

 

$M=$(if,$(eq,$(getvar,USERR1),0),USERR1;1;_.-LAYER;_c;3;0;,USERR1;0;_.-LAYER;_c;1;0; )

 

It will toggle either red or green to the opposite color and back, then it stops.  However, if I do this:

 

$M=$(if,$(eq,$(getvar,USERR1),0),USERR1;1;_.-LAYER;_c;3;0;,USERR1;0;_.-LAYER;_c;1;0;^C )

 

It toggle indefinitely. I know that last ^C is a kludge to make it stop working...is there another command to "reset" the toggle, or is that it?

0 Likes
Message 5 of 5

dpierson6B4ETP
Participant
Participant

Oh, and THANK YOU!!!  You have NO idea how long (embarrassingly) I have been working on this.  I really appreciate the assist.

0 Likes