Author Topic: Another Menu question  (Read 8556 times)

0 Members and 1 Guest are viewing this topic.

pmvliet

  • Guest
Another Menu question
« on: January 28, 2005, 02:23:21 PM »
My menu saga continues but I am seeing the light at the end of the tunnel.

I have loaded all my main menu's and now I want to be able to load and unload client menu's.

in psuedo code as Mark would say:
I need to select a client from a menu pulldown which is easy.
This will then call to load a specific menu which I can do. I can then add this into the pulldown which I can do.

Now the part I don't get. When the user goes to select another client, how do I get AutoCad to know what the previous client menu was to unload?
Basically I want to do a swap from Client A to Client B or Client C.
Order cannot matter as any combination may occur.

Withe the help of Mark from a little while ago I have this
Code: [Select]
(defun c:riteaid ()
  (setq client "riteaid")
       (command
   "menuload"
   (strcat "i:\\standards\\retail\\" client "\\menu\\" client)
   )
  (menucmd (strcat "p16=-" client ".pop1"))
  (
   (menucmd (strcat "p16=+" client ".pop1"))
   (alert "Notice:\nThe riteaid Workspace has been loaded!")
   )


I need to re-organize it a little and test for the result of the variable client.
if client comes back nil, then it can go ahead and load the menu and set it in the pulldown. If client comes back with something other then nil, I need to unload that client menu, redefine client and then proceed.

Am I thinking on the right line or way off? Am I making this way too complicated?

Thanks,
pieter

pmvliet

  • Guest
Another Menu question
« Reply #1 on: January 28, 2005, 03:00:05 PM »
Here I got the first part and it works. :D
Code: [Select]

(if (not (getenv "client"))
  (progn
    (setenv "client" "Riteaid")
(command "menuload" (strcat "i:\\autodesk\\ro sbu\\retail\\" (getenv "client") "\\menu\\" (getenv "client") ))
(menucmd (strcat "p15=+" (getenv "client") ".pop1"))
(alert (strcat "Notice:\nThe" (getenv "client") "Workspace has been loaded!"))
  )
)


How do I get it to do something different if the return from client is not "nil" ?? Hmmm, back to all the functions...

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Another Menu question
« Reply #2 on: January 28, 2005, 03:25:14 PM »
Maybe this ............
Code: [Select]

(if (not (getenv "client"))
  (progn
    (setenv "client" "Riteaid")
    (command "menuload" (strcat "i:\\autodesk\\ro sbu\\retail\\" (getenv "client") "\\menu\\" (getenv "client") ))
      (menucmd (strcat "p15=+" (getenv "client") ".pop1"))
         (alert (strcat "Notice:\nThe" (getenv "client") "Workspace has been loaded!"))
    )
; else "client" is T
(progn
 (do more stuff here)
 )
)
TheSwamp.org  (serving the CAD community since 2003)

pmvliet

  • Guest
Another Menu question
« Reply #3 on: January 28, 2005, 05:05:10 PM »
thanks mark.
I don't know when I will get back as it is a friday and on Monday/Tuesday I'll be in another office.

pmvliet

  • Guest
Another Menu question
« Reply #4 on: January 28, 2005, 09:27:16 PM »
I have it so that if it is not nil, it will then clear that menu and the set my variable "client" to nil. But I need it to start over, So I need a loop?

Code: [Select]

(if (not (getenv "client"))
  (progn
    (setenv "client" "lowes")
    (command "menuload" (strcat "i:\\autodesk\\ro sbu\\retail\\" (getenv "client") "\\menu\\" (getenv "client") ))
      (menucmd (strcat "p15=+" (getenv "client") ".pop1"))
         (alert (strcat "Notice:\nThe" (getenv "client") "Workspace has been loaded!"))
    )
   ; else "client" is T
   (progn
     (command "menuunload" (strcat (getenv "client")))
(setenv "client" "")
     )


I am also thinking that I need several variables because at the end when I set client to "nil" I really need it to be "lowes" in this case... So I need to swap variables. I have it set to "nil" as one option. Another will be "current client" and then I will have the "new client". So this one variable has 3 different instances.

psuedo code:
if "client" is set to nil, load the client menu.
if "client" is set to a new client, I need to remove the current client and then load in the new client.

Hmm... This sure seems complicated but I really like what it is allowing me to do :D I should go home...

Pieter

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Another Menu question
« Reply #5 on: January 29, 2005, 12:59:51 AM »
You may benefit from the cond statement.
But I'm not sure where you are going with this.
Can you post a more complete pseudo code?
What did you mean by 'I need to loop'

Code: [Select]
(cond
  ((null client); "client" is set to nil
    (load the client menu)
  )
  ((= clent "New Client")
    (remove the current client)
    (load in the new clien)
  )
  ((= clent "Client A")
    (remove the current client)
    (load in client A)
  )
  ((= clent "Client B")
    (remove the current client)
    (load in client B)
  )
  (T
    (do default action?)
  )
)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Another Menu question
« Reply #6 on: January 31, 2005, 07:37:13 AM »
just a thought but could he not create a dcl that could have a load and unload column with all of your menus and load and unload whichever one you need. gotta run...

pmvliet

  • Guest
Another Menu question
« Reply #7 on: January 31, 2005, 09:33:57 AM »
Cab,

I am looking at a way to load specific client menu when choosen via a menu pulldown or any other user selection. Just using menu pulldowns as it is the most basic.

The user starts Autocad. Then they can select the client that they are going to be doing work for. When they select the client, colortables, search paths and other variables will be set for that client.
The user works for a while and after lunch they need to work for another client. When they go to select their new client, it needs to unload the previous client. Then it will load in the new client menu and set all the system variables that it needs.

Maybe I am making this more complicated??? I probably have 30 different clients all with specific needs, colortables etc. This is my way to eliminate the use of profiles and have more control over variables and other things.

ELOQUINTET, I like the DCL idea, but I still need the code to load and unload menu's.

Thanks guys!

Pieter

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Another Menu question
« Reply #8 on: January 31, 2005, 09:49:10 AM »
I think I'm starting to understand..............  :D

Well you're using a system variable already as in;
Code: [Select]
(setenv "client" "Riteaid")

So in your program you would read that variable unload the menu that is named (Riteaid in this case), then load the next menu and set the 'client' variable to that. I hope this is making sense!!
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Another Menu question
« Reply #9 on: January 31, 2005, 10:13:09 AM »
Something like this?
Code: [Select]
;;  variable "newclient" is passed here with the new client name

(if (or (null newclient) (= newclient ""))
  (setq newclient "lowes") ; default client
)
       
;;  check for new client
(if (= (strcase newclient) (strcase (getenv "client")))
  (alert "\r Client already Loaded")
  ;; else load client
  (cond
    ((= (strcase newclient) "LOWES")
      (setenv "client" newclient)
      (command "menuload" (strcat "i:\\autodesk\\ro sbu\\retail\\" newclient "\\menu\\" newclient ))
        (menucmd (strcat "p15=+" newclient ".pop1"))
          (alert (strcat "Notice:\nThe" newclient "Workspace has been loaded!"))
    )
    ;;  repeat for other clients
    ((= (strcase newclient) "ABC") ; stay with upper case
      (setenv "client" newclient)
      (command "menuload" (strcat "i:\\autodesk\\ro sbu\\retail\\" newclient "\\menu\\" newclient ))
        (menucmd (strcat "p15=+" newclient ".pop1"))
          (alert (strcat "Notice:\nThe" newclient "Workspace has been loaded!"))
    )
   
   (t ; if newclient is not found
     (alert "\r Client data missing nothing Loaded")
   )
  )
)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Anonymous

  • Guest
Another Menu question
« Reply #10 on: January 31, 2005, 10:19:21 AM »
mark, I think you are getting it. Or at least what I am striving for.

Cab, thanks for that. It's going to take me a little while to read through it and understand and try it out.

I will post back what I find when I can.

Thanks guys!

Pieter

pmvliet

  • Guest
Another Menu question
« Reply #11 on: January 31, 2005, 10:50:27 AM »
ok, that was me previously but my cookie or something wasn't set...

ok a sidebar question.
Cab you are setting the variable "newclient" with setq.
is there a benefit to use setq rather then creating an environment variable
such as (setenv "client") ??

should I make them all setq variables?

Thanks,
Pieter

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Another Menu question
« Reply #12 on: January 31, 2005, 11:03:40 AM »
My though was this, That your menu choice wiould do this
(DO_MENU_CHANGE "lowes"); ONE FOR EACH MENU BUTTON

Code: [Select]
(defin do_menu_choice (newclient)
(if (or (null newclient) (= newclient ""))
  (setq newclient "lowes") ; default client
)
       
;;  check for new client
(if (= (strcase newclient) (strcase (getenv "client")))
  (alert "\r Client already Loaded")
  ;; else load client
  (cond
    ((= (strcase newclient) "LOWES")
      (setenv "client" newclient)
      (command "menuload" (strcat "i:\\autodesk\\ro sbu\\retail\\" newclient "\\menu\\" newclient ))
        (menucmd (strcat "p15=+" newclient ".pop1"))
          (alert (strcat "Notice:\nThe" newclient "Workspace has been loaded!"))
    )
    ;;  repeat for other clients
    ((= (strcase newclient) "ABC") ; stay with upper case
      (setenv "client" newclient)
      (command "menuload" (strcat "i:\\autodesk\\ro sbu\\retail\\" newclient "\\menu\\" newclient ))
        (menucmd (strcat "p15=+" newclient ".pop1"))
          (alert (strcat "Notice:\nThe" newclient "Workspace has been loaded!"))
    )
   
   (t ; if newclient is not found
     (alert "\r Client data missing nothing Loaded")
   )
  )
)
)


No setq.
If you use setq it is only valid for the current drawing.
If you change drawings it uses another variable of the sane name where as setenv is good
for all drawing in that session.
So you see my post was not meant to be the final solution but code to help you get there.
you would have to turn my code into  a lisp.

Perhaps if you posted you menu code for client changes we could get closer to your problem.
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

pmvliet

  • Guest
Another Menu question
« Reply #13 on: January 31, 2005, 12:55:29 PM »
ok, I am having a hard time re-writing my psuedo code. here is a simple way I wrote down. There are issues but maybe it will help you guys understand.

So far I have two variables:
"client" is the existing loaded client. This could be nil or a specific client.
"newclient" is the newly selected client by the user

The user selects a pulldown menu and selects a client and which needs to set the variable "newclient"

We need to check if "newclient" equals "client"
Code: [Select]
(if (= (strcase newclient)(strcase (getenv "client")))
  (alert "\r Client already Loaded")
)

(I don't know that this will ever happen but that is fine)

then if "newclient" does not equal "client"
Code: [Select]

((/= newclient (strcase (getenv "client"))

we need to unload "client"
Code: [Select]

(command "menuunload" (strcat (getenv "client")))

then, pass the value of "newclient" to "client"
Code: [Select]

(setenv "client" "newclient")

then, we need to load "client"
Code: [Select]

(command "menuload" (strcat "i:\\autodesk\\ro sbu\\retail\\" (getenv "client") "\\menu\\" (getenv "client")))
  (menucmd (strcat "p15=+" (getenv "client") ".pop1"))
  (alert (strcat "Notice:\nThe" (getenv "client") "Workspace has been loaded!"))


As far as how I am calling this, that I am still working on. Right now I am defining this routine with the client name.
My menu looks like this right now.
Code: [Select]

[->Retail]
[Lowe's]^c^clowes;
[Circuit City]
[Riteaid]^c^criteaid;
[Walgreen's]
[Petsmart]
[Meijer]
[Albertsons]
[Tippmann]
[GE Fuel]
[Retail]
[Dominicks]
[Westfield-in]
[<-Westfield-out]


The lowes or riteaid calls the following
Code: [Select]

(defun c:LOWES ()
  (load "i:\\autodesk\\ro sbu\\retail\\lowes\\support\\LOWES.lsp")
)


The lowes lisp is

Code: [Select]

;;;This is to see how the new system works
;;;sets's newclient variable to lowes
(setq newclient "lowes")
;;;Check to see if the "newclient" is already loaded
(if (= (strcase newclient) (strcase (getenv "client")))
  (alert "\r Client already Loaded")
)
;;;Check to see if "newclient" does not equal "client"
;;;if is does, unnload "client" and re-define "client" to be "newclient"
(cond
  ((/= newclient (strcase (getenv "client")))
   ((progn (command "menuunload" (strcat (getenv "client")))
  (setenv "client" "newclient")
;;;Load in "client"
  (command "menuload" (strcat "i:\\autodesk\\ro sbu\\retail\\" (getenv "client") "\\menu\\" (getenv "client")))
  (menucmd (strcat "p15=+" (getenv "client") ".pop1"))
  (alert (strcat "Notice:\nThe" (getenv "client") "Workspace has been loaded!"))
;;;If client is not found, alert user
  (t
    (alert "\r Client Data not found")
  )
    )
   )
  )
)


i really want the routine to be called straight from the pulldown menu but for some reason
Code: [Select]
^c^c(load "i:\\autodesk\\ro sbu\\retail\\lowes\\support\\LOWES.lsp")
does not want to work


Maybe some of this will help you understand.
This also does not eliminate the setq as I think that really should be a setenv variable.

Thanks,
Pieter

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Another Menu question
« Reply #14 on: January 31, 2005, 07:47:54 PM »
Try this, menu code

Code: [Select]
[->Retail]
         [Lowe's]^c^c^P(if (null menu_change) (load menu_change));(menu_change "lowes");
         [Circuit City]^c^c^P(if (null menu_change) (load menu_change));(menu_change "Circuit City");
         [Riteaid]^c^c^P(if (null menu_change) (load menu_change));(menu_change "Riteaid");
         [Walgreen's]^c^c^P(if (null menu_change) (load menu_change));(menu_change "Walgreen's");
         [Petsmart]^c^c^P(if (null menu_change) (load menu_change));(menu_change "Petsmart");
         [Meijer] ^c^c^P(if (null menu_change) (load menu_change));(menu_change "Meijer");
         [Albertsons]^c^c^P(if (null menu_change) (load menu_change));(menu_change "Albertsons");
         [Tippmann] ^c^c^P(if (null menu_change) (load menu_change));(menu_change "Tippmann");
         [GE Fuel] ^c^c^P(if (null menu_change) (load menu_change));(menu_change "GE Fuel");
         [Retail] ^c^c^P(if (null menu_change) (load menu_change));(menu_change "Retail");
         [Dominicks] ^c^c^P(if (null menu_change) (load menu_change));(menu_change "Dominicks");
         [Westfield-in] ^c^c^P(if (null menu_change) (load menu_change));(menu_change "Westfield-in");
         [<-Westfield-out] ^c^c^P(if (null menu_change) (load menu_change));(menu_change "<-Westfield-out");


Put this lisp in the ACAD search path
Code: [Select]
;;  Menu_change.lsp
(defun menu_change (newclient)
  (if (or (null newclient) (= newclient ""))
    (setq newclient "lowes") ; default client
  )

  ;;  check for new client
  (if (= (strcase newclient) (strcase (getenv "client")))
    (alert "\r Client already Loaded")
    ;; else load client
    (if (member (strcase newclient)
                (list
                  "LOWE'S"
                  "CIRCUIT CITY"
                  "RITEAID"
                  "WALGREEN'S"
                  "PETSMART"
                  "MEIJER"
                  "ALBERTSONS"
                  "TIPPMANN"
                  "GE FUEL"
                  "RETAIL"
                  "DOMINICKS"
                  "WESTFIELD-IN"
                  "<-WESTFIELD-OUT"
                ) ; list
        ); member
     (progn
        ;; Check / Unload existing menugroup
        (if (/= (menugroup (getenv "client")) nil)
           (command "_MENUUNLOAD" (getenv "client"))
        ); end if
        (setenv "client" newclient)
        (command "menuload"
                (strcat "i:\\autodesk\\ro sbu\\retail\\" newclient "\\menu\\" newclient))
        (menucmd (strcat "p15=+" newclient ".pop1"))
        (alert (strcat "Notice:\nThe" newclient "Workspace has been loaded!"))
      ); progn
      (alert "\r Client data missing nothing Loaded")
    ); endif
  ); endif
); end defun


No error checking, path must exist.
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.