Author Topic: Change the look of an icon without recompiling the menu  (Read 4226 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Change the look of an icon without recompiling the menu
« on: March 16, 2015, 11:55:15 AM »
Can I change the look of an icon without recompiling the menu?

this is the sintax of my MNU:
[_Button("Layer 11", LR11.bmp, LR11.bmp)]

my idea is to overwrite the file bmp and "regenerate" only the "button"...
is it possible?

trogg

  • Bull Frog
  • Posts: 255
Re: Change the look of an icon without recompiling the menu
« Reply #1 on: March 16, 2015, 12:32:34 PM »
Check this out:
If you have 7zip installed (which is free) you can easily open a CUIX file and the drag in a bitmap (.bmp) file and replace the button/icon (shown below).
Note 1: If you don't have 7zip and don't want to use it, change the cui file extension from .cuix to .zip and then double click to open it with Windows Explorer. DON'T EXTRACT THE NEW .ZIP FILE AND THEN RE-ZIP THE FILE!!!

Note 2: Sometimes the bitmap is renamed when there are spaces in the bitmap's name. So make sure to copy the name of the icon as it is shown when you view it in it's zip view (See top picture)
« Last Edit: March 16, 2015, 12:51:59 PM by trogg »

hmspe

  • Bull Frog
  • Posts: 362
Re: Change the look of an icon without recompiling the menu
« Reply #2 on: March 16, 2015, 12:39:57 PM »
If you want to change an icon with lisp you can do something like the following.  I use this to change button #18 on toolbar "enco draw" to show the current drawing scale.

Code - Auto/Visual Lisp: [Select]
  1. (defun set_scale_icon ( / *acad bitmap3 button18 ds e_menu e_menus e_toolbar e_toolbars
  2.                        ts)
  3.   (setq ds (getvar "dimscale"))
  4.   (setq ts (getvar "textsize"))
  5.   (if (or (/= ds 1.0) (and (= ds 1.0) (/= ts 0.2)))
  6.     (progn
  7.       (setq *acad (vlax-get-acad-object))
  8.       (setq e_menus (vla-get-menugroups *acad))
  9.       (setq e_menu (vla-item e_menus "enco"))                                                       ; menu name to work with
  10.       (setq e_toolbars (vla-get-toolbars e_menu))
  11.       (setq e_toolbar (vla-item e_toolbars "enco draw"))                                            ; toolbar name to work with
  12.       (setq button18 (vla-item e_toolbar 18))                                                       ; gets the scales button
  13.       (setq bitmap3 "")
  14.       (cond ((= ds 96) (setq bitmap3 "S:\\_2010 BitMaps\\e_1_8.bmp"))
  15.             ((= ds 192) (setq bitmap3 "S:\\_2010 BitMaps\\e_1_16.bmp"))
  16.             ((= ds 128) (setq bitmap3 "S:\\_2010 BitMaps\\e_3_32.bmp"))
  17.             ((= ds 64) (setq bitmap3 "S:\\_2010 BitMaps\\e_3_16.bmp"))
  18.             ((= ds 48) (setq bitmap3 "S:\\_2010 BitMaps\\e_1_4.bmp"))
  19.             ((= ds 32) (setq bitmap3 "S:\\_2010 BitMaps\\e_3_8.bmp"))
  20.             ((= ds 24) (setq bitmap3 "S:\\_2010 BitMaps\\e_1_2.bmp"))
  21.             ((= ds 16) (setq bitmap3 "S:\\_2010 BitMaps\\e_3_4.bmp"))
  22.             ((= ds 12) (setq bitmap3 "S:\\_2010 BitMaps\\e_1.bmp"))
  23.             ((= ds 60) (setq bitmap3 "S:\\_2010 BitMaps\\e_5.bmp"))
  24.             ((= ds 120) (setq bitmap3 "S:\\_2010 BitMaps\\e_10.bmp"))
  25.             ((= ds 180) (setq bitmap3 "S:\\_2010 BitMaps\\e_15.bmp"))
  26.             ((= ds 240) (setq bitmap3 "S:\\_2010 BitMaps\\e_20.bmp"))
  27.             ((= ds 360) (setq bitmap3 "S:\\_2010 BitMaps\\e_30.bmp"))
  28.             ((= ds 480) (setq bitmap3 "S:\\_2010 BitMaps\\e_40.bmp"))
  29.             ((= ds 600) (setq bitmap3 "S:\\_2010 BitMaps\\e_50.bmp"))
  30.             ((= ds 720) (setq bitmap3 "S:\\_2010 BitMaps\\e_60.bmp"))
  31.             ((= ds 1200) (setq bitmap3 "S:\\_2010 BitMaps\\e_100.bmp"))
  32.             ((= ds 2400) (setq bitmap3 "S:\\_2010 BitMaps\\e_200.bmp"))
  33.             ((= ds 1) (setq bitmap3 "S:\\_2010 BitMaps\\e_1to1.bmp"))
  34.       )
  35.       (if (/= bitmap3 "")
  36.         (vla-setbitmaps button18 bitmap3 bitmap3)
  37.       )
  38.     )
  39.   )
  40.   (princ)
  41. )
  42.  
"Science is the belief in the ignorance of experts." - Richard Feynman

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Change the look of an icon without recompiling the menu
« Reply #3 on: March 16, 2015, 01:01:13 PM »
If you want to change an icon with lisp you can do something like the following.  I use this to change button #18 on toolbar "enco draw" to show the current drawing scale.
...
thanks for the reply, very interesting.  I think that's what I wanted, now do a look.
Grazie mille to trogg too.

Crank

  • Water Moccasin
  • Posts: 1503
Re: Change the look of an icon without recompiling the menu
« Reply #4 on: March 22, 2015, 06:07:07 AM »
If you change the .cuix file , that doesn't mean you also change the .mnr file(s). So I think this is not possible without recompiling the .cuix.
Vault Professional 2023     +     AEC Collection

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Change the look of an icon without recompiling the menu
« Reply #5 on: March 22, 2015, 04:58:24 PM »
If you change the .cuix file , that doesn't mean you also change the .mnr file(s). So I think this is not possible without recompiling the .cuix.

> (vla-setbitmaps button bitmap bitmap) Tested on 2012: works but when restart all changes are gone... (this ok for my needs)

john_waggs

  • Guest
Re: Change the look of an icon without recompiling the menu
« Reply #6 on: June 15, 2015, 12:28:17 PM »
in the "Set Scale" code listed above, is there a way to use this code for SNAP ON or OFF by showing a green colored swatch on the ribbon panel if SNAP is ON and a red colored swatch if Snap is OFF? If so, can someone show me what that would look like in code?

Thanks,

John

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Change the look of an icon without recompiling the menu
« Reply #7 on: June 17, 2015, 09:01:18 AM »
If you change the .cuix file , that doesn't mean you also change the .mnr file(s). So I think this is not possible without recompiling the .cuix.
If I copy my cuix to a new computer, the icons on custom toolbars, even though they're all native commands/icons, I have to reset the icons (add/delete something) before it will display the icons again. Is this a result of only copying the cuix file when I should be copying the mnr file as well?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

hmspe

  • Bull Frog
  • Posts: 362
Re: Change the look of an icon without recompiling the menu
« Reply #8 on: June 17, 2015, 11:35:29 AM »
in the "Set Scale" code listed above, is there a way to use this code for SNAP ON or OFF by showing a green colored swatch on the ribbon panel if SNAP is ON and a red colored swatch if Snap is OFF? If so, can someone show me what that would look like in code?

Thanks,

John

That code is for toolbars, not for the ribbon.  I'm in the "I hate ribbons" camp so I can't specifically address what might be required to change a ribbon icon.

To change a toolbar button color you would need to have two icons, one of each color.  The best approach would be to have a reactor which fires when SNAP is changed.  You could try something like the following.  Note that this is taken from a lisp function that I have not used in several years and that it is untested, but it might get you started. 
Code: [Select]
;; defun a lisp call back function
(defun monitorSysVar (rObject vName / *error*)             ; vName is the list returned by the reactor
                                                                               ; First parameter is a string identifying the system variable name.
                                                                               ; Second parameter is symbol indicating whether or not the change
                                                                               ; was successful (T if successful, nil if not).
  (defun *error* (msg)
    (princ (strcat "\nError: " msg))
  )

  (if (= (car vName) "SNAP")
    (set_buttons)
  )
)

(defun c:activateSysVarMonitor ()
  (setq rObj (vlr-sysvar-reactor
              nil
             '((:vlr-sysvarchanged . monitorSysVar))
             )
  )
)

(defun c:deActivateSysVarMonitor ()
  (vlr-remove rObj)
)

;;; activate monitor by default
(c:activateSysVarMonitor)
(set_buttons)
"Science is the belief in the ignorance of experts." - Richard Feynman