Better menu macro for toggle groups?

Better menu macro for toggle groups?

JamesMaeding
Advisor Advisor
2,148 Views
16 Replies
Message 1 of 17

Better menu macro for toggle groups?

JamesMaeding
Advisor
Advisor

For a while, the typical acad.cuix macros for toggle groups and other vars look like:

 

'_setvar;pickstyle;$M=$(if,$(eq,$(getvar,pickstyle),0),1,$(if,$(eq,$(getvar,pickstyle),1),0,$(if,$(eq,$(getvar,pickstyle),2),3,2)))

 

I want it to say "Groups On" or "Groups Off" as I hit ctrl-H or whatever I assign that command to (ctrl-A for me!).

 

I don't mess with this kind of code too much. Can we add the statements "in line", or do I have to add a lisp statement at the end like:

 

'_setvar;pickstyle;$M=$(if,$(eq,$(getvar,pickstyle),0),1,$(if,$(eq,$(getvar,pickstyle),1),0,$(if,$(eq,$(getvar,pickstyle),2),3,2)));(if (= (getvar "pickstyle") 0)(princ "\nGroups Off")(princ "\nGroups On"))

 

lookin for ideas.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Accepted solutions (1)
2,149 Views
16 Replies
Replies (16)
Message 2 of 17

Shneuph
Collaborator
Collaborator

I've suggested the use of modemacro before and I will again.  Instead of having a message when the variable is changed as you are trying to do you could have the variable status always shown using the modemacro variable.   I've edited my modemacro to display variables I like to keep my eye on:

pstylemode, osnapz, textsize, dimscale, ltscale, cprofile, mtexted, centermt.  It updates automatically when any of them change.

 

You would type modemacro and paste this:

$(if,$(eq,$(getvar,pickstyle),0),"Groups Off" ,"Groups On")

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 3 of 17

JamesMaeding
Advisor
Advisor

I already do, but dumb acad does not expand it enough to see all I want:

thanksacad.jpg

Besides, I don't want my users to be looking away from the command line to the middle of the screen.

Wish I could control that layout tab blank area width, I'd do what you said, but still want it echoed on command line.

 

Of course, Bricscad does not suffer from the issue, though it does use a full row for layout tabs:

bcad.jpg

Those real words for settings is something I long to get back in acad, having to support 100 people and glance at their screen to see what is on or off.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 4 of 17

Shneuph
Collaborator
Collaborator

Used one I had for testing and this should give you the desired result.  No diesel, just lisp.  You can put directly into your command macro.

 

(setvar "pickstyle" (1- (getvar "pickstyle")))(if (= (getvar "pickstyle") 0)(princ "Groups Off")(princ "Groups On"))(princ)

 

EDIT:

 

I set menuecho to 1

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 5 of 17

JamesMaeding
Advisor
Advisor

I will try, but a subtle detail in the original is the single quote '_setvar....

That runs transparently. I'll see if yours does as that is necessary.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 6 of 17

Shneuph
Collaborator
Collaborator

Good point.  To my surprise, it DOES seem to run transparently.  Mine is changing the snapstyle variable but I can use the button in the middle of the line command w/o it interrupting.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 7 of 17

JamesMaeding
Advisor
Advisor

more compactly:

(if (= (setvar "pickstyle" (- 1 (getvar "pickstyle"))) 0)(princ "Groups Off")(princ "Groups On"))(princ)

 

it works though, very nice!

Now to change all the toggle things in menus to do that (coords...)


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 8 of 17

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

more compactly:

(if (= (setvar "pickstyle" (- 1 (getvar "pickstyle"))) 0)(princ "Groups Off")(princ "Groups On"))(princ)

 

...

(princ (if (= 0 (setvar 'pickstyle (- 1 (getvar 'pickstyle)))) "Groups Off" "Groups On"))(princ)

Message 9 of 17

JamesMaeding
Advisor
Advisor

uh oh, I'm in one of those LISPing wars.

Love the (getvar 'pickstyle) thing - pared down two quotes for a single. 

I'm not worthy!


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 10 of 17

JamesMaeding
Advisor
Advisor

one more shot!

 

I realized the MENUECHO requirement is a problem, as this does not behave:

(setvar "menuecho" 1)(if (= (setvar "pickstyle" (- 1 (getvar "pickstyle"))) 0)(princ "Groups Off")(princ "Groups On"))(setvar "menuecho: 0)(princ)

That will echo the ugly whole line as menuecho is always 0 when it starts.

 

I do need MENUECHO as 0 so my users see _qsave on command line when they crtl-s. Scares them if missing.

I then recalled the funny ^c^c^p thing you see in old menu code, and tried the ^P:

 

^P(if (= (setvar "pickstyle" (- 1 (getvar "pickstyle"))) 0)(princ "Groups Off")(princ "Groups On"))(princ)

 

That works! (and is more compact to boot).

Mission accomplished Pokey! Thanks Gumby.

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 11 of 17

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

'_setvar;pickstyle;$M=$(if,$(eq,$(getvar,pickstyle),0),1,$(if,$(eq,$(getvar,pickstyle),1),0,$(if,$(eq,$(getvar,pickstyle),2),3,2)))

 

I want it to say "Groups On" or "Groups Off" as I hit ctrl-H or whatever I assign that command to (ctrl-A for me!).

....


I'm not well-enough versed in Diesel, but if I'm reading that right, and if you can do this with AutoLisp, there's a much more concise way, avoiding all those nested (if) functions evaluating for four possible current values.  It can toggle directly between Pickstyle value pairs of either 0 and 1 or 2 and 3, without caring what the specific current value is, i.e. without having to distinguish whether or not Associative-Hatch selection is on [whether or not the 2 bit is part of the value]:

 

(setvar 'pickstyle (boole 6 1 (getvar 'pickstyle)))

 

[I don't know whether Diesel can use boolean operations, but if so, you should be able to make an equivalent Diesel function.]

 

If the 1 bit is part of the value, the (boole 6) operation removes it, but if not, it adds it, i.e. 0 becomes 1, 1 become 0, 2 becomes 3, 3 becomes 2.  It leaves the Associative-Hatch selection part [0 or 2] as it is.

 

Then you can notify the User more concisely, too, based not on the specific value, but on simply whether the value is even [Group selection off] or odd [on]:

 

(prompt (strcat "\nGroups " (if (= (rem (getvar 'pickstyle) 2) 1) "On" "Off")))

Kent Cooper, AIA
0 Likes
Message 12 of 17

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....(setvar "pickstyle" (- 1 (getvar "pickstyle")))....


That's fine if you can be sure the Associative-Hatch selection part is never active, that is, that the PICKSTYLE value is always and only either 0 or 1.  If Associate-Hatch selection is on, PICKSTYLE will be 2 or 3, and that code will set it to -1 or -2, which AutoCAD won't accept.  [Oddly, I'm finding it doesn't give me any invalidity message, and it returns those negative numbers, but they are rejected without comment -- the PICKSTYLE value is not changed.]  The boolean approach avoids that possibility.

Kent Cooper, AIA
0 Likes
Message 13 of 17

JamesMaeding
Advisor
Advisor

hmm, so this is as compact as I could get it so far:

^P(setvar 'pickstyle (if (= 1 (logand 1 (getvar 'pickstyle)))(progn (princ "Groups Off")(- (getvar 'pickstyle) 1))(progn (princ "Groups On")(+ (getvar 'pickstyle) 1))))(princ)

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 14 of 17

Kent1Cooper
Consultant
Consultant

^P(prompt (strcat "\nGroups " (if (= (rem (setvar 'pickstyle (boole 6 1 (getvar 'pickstyle))) 2) 1) "On" "Off"))) (princ)

Kent Cooper, AIA
0 Likes
Message 15 of 17

Kent1Cooper
Consultant
Consultant

Two whole characters shorter:

 

^P(prompt (strcat "\nGroups " (nth (rem (setvar 'pickstyle (boole 6 1 (getvar 'pickstyle))) 2) '("Off" "On")))) (princ)

Kent Cooper, AIA
0 Likes
Message 16 of 17

TomBeauford
Advisor
Advisor
Accepted solution

The shortest is still the one that's worked since before the newfangled Windows versions.

^A

It also displays <Group On> or <Group Off> at the command line to let you know the status.

For Windows compatibility you cannot use Ctrl+A to toggle from the command line, but the macro shortcut is still hardwired into AutoCAD.  

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
Message 17 of 17

JamesMaeding
Advisor
Advisor

@TomBeauford 

I was about to reply "No, you misunderstand, we do not want select all..." but lo and behold, ^A works!

Love it! thanks for mentioning.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties