How to create a display tool for a current variable value?

How to create a display tool for a current variable value?

rapidcad
Collaborator Collaborator
3,016 Views
24 Replies
Message 1 of 25

How to create a display tool for a current variable value?

rapidcad
Collaborator
Collaborator

Hi everyone, I felt like I needed to proceed with this post even though I didn't research it much - because I'm not really sure how to describe it so here we go!

 

I am setting up a system of controlling a faux elevation property - one that only holds the value as a (real) variable (not actually using the AutoCAD elevation property due to users - some outside of our organization - experience level with 3D concepts). I am placing dynamic blocks which will have attributes and properties that adopt the current value of this "elevation" variable and calculate through lisp programs during insertion, what size support dynamic blocks will need to have their height range settings set to in order to hold our equipment at the right level. I already have a system to read the blocks in the drawing and collect their properties and set the new block properly to go with it.

 

What I want to do is find a way to have a button in a toolbar, tool palette or ribbon panel that could display the current value of this elevation variable. It would work just like the current layer or current dimstyle or current color control toolbar object. I'd like it to be a real-time editable button to always be in the user's interface to display the current value of my elevation variable and even change it on the fly. I would assume that .net has ways of doing this, but we are restricted to lisp methods since many users are outside the organization and using AutoCAD 2010 and anything newer.

 

Any ideas?

ADN CAD Developer/Operator
0 Likes
3,017 Views
24 Replies
Replies (24)
Message 2 of 25

Shneuph
Collaborator
Collaborator

As far as displaying variables in realtime the best way I know if is to use your modemacro.  You could still create a toolbar button to change the elevation variable and the modemacro will reflect the change.

 

(setvar "modemacro" "\"Elevation: \" $(getvar,YOURVARIABLENAME)")

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

rapidcad
Collaborator
Collaborator

Thanks Shneuph! I'll have a look at that idea and get back to you.

ADN CAD Developer/Operator
0 Likes
Message 4 of 25

rapidcad
Collaborator
Collaborator

Well, I looked up what I could find on this old function - hadn't seen anything using it since the 90's. There is some possibilities there with the idea, but I can't quite code it correctly to evaluate a variable and my variable is a REAL anyway, so my code would look more like this:

(setvar "modemacro" "\"TOR Elevation: \" $(rtos,TGWTOR-EL,2,6)" )

but what this places on the status bar is:

TOR Elevation:  $(RTOS, ??)

 

Can MODEMACRO evaluate variables? I saw no examples of this, only getvar manipulations.I have a feeling that variables are not allowed because I found no examples of them in use, and it seems to only work anyway with SYSTEM VARIABLES. Is that correct?

ADN CAD Developer/Operator
0 Likes
Message 5 of 25

Shneuph
Collaborator
Collaborator

My apologies.. You may be correct that you can only use system variables in modemacro and not lisp variables.  I made a field with the lisp variable and tried inputting the diesel code into modemacro to no avail.

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

ВeekeeCZ
Consultant
Consultant

Try 

(grtext -1 StringVariableName)

0 Likes
Message 7 of 25

Ranjit_Singh
Advisor
Advisor
Since this variable is something you will always need, setup a environment variable. You can call environment variable in mode macro

getenv_modemacro.gif

0 Likes
Message 8 of 25

rapidcad
Collaborator
Collaborator

BeeKeeCZ, do you mean along with modemacro?

 

I can load the following but it just displays the code, no evaluation

 

(setvar "modemacro" "\"TOR Elevation: \" $(grtext -1 (rtos TGWTOR-EL 2 6 ))" )

 

Staus bar says....

 

TOR Elevation  $(GRTEXT -1 (RTOS TGWTOR-EL 2 6 ))??

 

(setvar "modemacro" "\"TOR Elevation: \" $(grtext -1 (rtos,TGWTOR-EL,2,6))" )

results the same way..

ADN CAD Developer/Operator
0 Likes
Message 9 of 25

rapidcad
Collaborator
Collaborator

Thanks Ranjit - that may work, but I've never tried one before. I'll have to check out what the limitations are

ADN CAD Developer/Operator
0 Likes
Message 10 of 25

ВeekeeCZ
Consultant
Consultant

@rapidcad wrote:

BeeKeeCZ, do you mean along with modemacro?

 

...

No, instead of...

 

(grtext -1 (strcat "TOR Elevation: " (rtos TGWTOR-EL 2 6)))

0 Likes
Message 11 of 25

rapidcad
Collaborator
Collaborator

Thanks BeeKeeCZ! Now I see what you mean. Just include the code whenever I set the variable and it works just like modemacro would have worked!

I like it!

Of course, I wish users could just click on it to change it but it is better than nothing!

ADN CAD Developer/Operator
Message 12 of 25

rapidcad
Collaborator
Collaborator

Hmm, that seems to work until I begin to insert other blocks and run other lisp routines. I wonder how to make it persistent? I would hate to have to add the line of code to every operation in my menus.

ADN CAD Developer/Operator
0 Likes
Message 13 of 25

Ranjit_Singh
Advisor
Advisor

You may want to consider that most of the gr... functions are temporary graphics. Grvecs will clear out as soon as you redraw or switch layouts. Same with grtext. It clears out as soon as you switch layouts or even if you move your autocad window. Mode macro is a permanent thing, atleast for that session, and will in fact update when the variable updates.

0 Likes
Message 14 of 25

scot-65
Advisor
Advisor

Take your variable and stuff it into a USER key.
Now, make a call to that user key...

 

Set this/these inside acdddoc.lsp:
(setvar "USERS1" (strcat "Elevation: " (rtos YourValue)))

(setvar "MODEMACRO" "$(getvar,USERS1)")

The USERS#, USERR# and USERI# were initially designed for this very use!!!

Modemacro is just for display. If you want to "click" on
the "button", go into the CUI and create a command
however, the clickable part is limited to a Menu Bar item.
I do not know if it will work in the ribbon.

 

 

USER1593ad96b.jpg

USER2593ada21.jpg

Once you populate the Menu Bar tree (first pane of the CUI), highlight the item and

in the bottom-right pane adjust the "Name" as shown above.

 

Each time you update the USER key, the display will update as well.

 

I was just now thinking... I have not tried to populate the "Command Display Name"

to see if the tooltip shows the value correctly... so as to use this on a toolbar button...


???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 15 of 25

rapidcad
Collaborator
Collaborator

Thanks Ranjit and Scott. I'll try to experiment with the ideas today if I can get all the Monday morning fires put out! I hope to report back when I dig into it.

ADN CAD Developer/Operator
0 Likes
Message 16 of 25

rapidcad
Collaborator
Collaborator

Ok Scott, I'm starting with an attempt to get the modemacro portion to work first, without venturing into any CUI changes yet. If I get it working, I'll try to add a button or something. However, I get this error when I try to evaluate your code in the vlide editor:

"bad variable name in SETQ: "USERS1".

Not being very familiar with the whole modemacro to lisp communication process (looks sorta like menucode, but I've forgotten a lot of that), I realized that I would need to change your variable name "USERS1" into just USERS1 - like any other variable assignment. That passes correctly into AutoCAD, but the subsequent call to (setvar "MODEMACRO" "$(getvar,USERS1)") yields nothing in the status bar.

I don't know if this makes any difference, but I am setting my modemacro in my own custom .mnl file instead of acaddoc.lsp - I cannot be assured that some of my users (outside the organization) are not using acaddoc.lsp already. In fact, I have run into this problem with users outside our organization who are using some other 3rd party programs and menus which dictate their custom acaddoc.lsp and acad.lsp be used, so I make it my practice to keep my loads to our menu's own .mnl file.

I don't think that is my issue though. I think something is wrong with the syntax of the variable name in your callback...(setvar "MODEMACRO" "$(getvar,USERS1)")... because this evaluates as "$(getvar,USERS1)" - and does nothing to the status bar, instead of evaluating "TOR Elevation: 30.00000", which is what (grtext -1 (strcat "TOR Elevation: " (rtos TGWTOR-EL 2 6))) evaluates as (and does display in the status bar - only without persisting).

 

ADN CAD Developer/Operator
0 Likes
Message 17 of 25

Ranjit_Singh
Advisor
Advisor

Note that @scot-65 does mention the userr# variable. Since you are displaying a real value you should be using userr and not users. The below works at my end

(setvar 'modemacro "ELEVATION: $(getvar, userr1)")

userr1.png

 

Message 18 of 25

rapidcad
Collaborator
Collaborator

Thanks Ranjit! I feel so stupid! It was a simple error on my part of using setq instead of setvar!  (setvar "USERR1"  TGWTOR-EL )
(setvar 'modemacro "TOR Elevation: $(getvar, USERR1)"). Seems to work just fine! I'll look into the idea of use in the CUI after lunch.

 

Thanks for all your help.

ADN CAD Developer/Operator
0 Likes
Message 19 of 25

scot-65
Advisor
Advisor
I too believe in the MNL.
All of our "Menu Functions" are loaded using this interface point.

Sometimes the DIESEL expression is stubborn when "regular" text
is squeezed in between $(getvar's. To compensate, use $(SUBSTR...
as shown in the image I have provided above.

Who here has NOT mistaken setq with setvar?
Or even perhaps the setvar with the obsolete SETCFG?

🙂

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 20 of 25

john.uhden
Mentor
Mentor

I have never confused setqueue with sitvar!  They are not even pronounced the same.  Plus I think one is French and the other is Russian.

John F. Uhden

0 Likes