Author Topic: Menu and Toolbars via Lisp  (Read 3664 times)

0 Members and 1 Guest are viewing this topic.

reltro

  • Guest
Menu and Toolbars via Lisp
« on: November 11, 2012, 05:01:29 AM »
Hey,
I have a lil Problem with my custom menu's and Toolbar's

I create the .mns from a Lisp and compile them after to a .mnr an .cuix, save them in a custom Folder an at the first run they are loaded and visible as wished.
But, if I start acad again, the .cuix is loaded but they aren't visible. they are either included in the drawing. If I try (command "_-toolbar" name) the Toolbar isn't found.

If i unload them and reload them again while starting they are loaded correctly and also visible.
But, the Problem is that I start the loading-Lisp wich each start (appload -> startUpSuite) and the unload and reload is a lil leggy...

Whats a good way to load them correctly at the first time, so i don't have to load them again and again?

I don't know why, but the .mns-file is empty...

any advice?

Greets reltro

[edit]
Its maybe possilbe to add a bitmap to a menuItem?
(vla-set-bitmaps ... ... ...) does not work =(
« Last Edit: November 11, 2012, 06:38:06 AM by reltro »

reltro

  • Guest
Re: Menu and Toolbars via Lisp
« Reply #1 on: November 11, 2012, 09:09:51 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun SS::CreateMenu (name menulst toolbarlst / newMenu newToolbarButton  flag FileName acadobj thisdoc menus fn #createMenu #createToolbar currMenuGroup path)
  2.      ;; name                     ... Name of the Menu
  3.      ;; menulst/toolbarlst     ... ((name, macro, helpString,bitmapPath) (... , ... , ... , ...) ...)
  4.      ;;     -> 'nil ... seperator
  5.      ;;               name  ... String
  6.      ;;               macro ... String
  7.      ;;               helpString      ... String
  8.      ;;               bitmapPath     ... String
  9.      (setq path "D:\\")
  10.      
  11.      (defun #createToolbar ( / SeperatorPos nameLst macroLst helpLst BitmapLst)
  12.           (setq newToolbarButton (vla-add (vla-get-toolbars currMenuGroup) name))
  13.          
  14.           (     (lambda (lst / i)
  15.                     (setq i 0)
  16.                     (foreach group lst
  17.                          (if (not group)
  18.                               (setq SeperatorPos (cons i SeperatorPos))
  19.                               (progn
  20.                                    (setq      nameLst      (cons (nth 0 group) nameLst)
  21.                                              macroLst     (cons (nth 1 group) macroLst)
  22.                                              BitmapLst     (cons (nth 3 group) BitmapLst)
  23.                                              helpLst          (cons (nth 2 group) helpLst)
  24.                                    )
  25.                               )
  26.                          )
  27.                          (setq i (1+ i))
  28.                     )                        
  29.                     (setq      SeperatorPos      (reverse SeperatorPos)
  30.                               nameLst               (reverse nameLst)
  31.                               macroLst          (reverse macroLst)
  32.                               helpLst               (reverse helpLst)
  33.                               BitmapLst          (reverse BitmapLst)
  34.                     )
  35.                )
  36.                toolbarlst
  37.           )
  38.      
  39.           (mapcar
  40.                '(lambda (name macro bitmap helpString / newToolbarButtonItem openMacro SmallBitmapName LargeBitmapName)
  41.                     (setq openMacro (strcat (chr 3) (chr 3) macro (chr 32)))
  42.                    
  43.                     (setq newToolbarButtonItem
  44.                             (vla-addToolbarButton
  45.                                    newToolbarButton
  46.                                    (1+ (vla-get-count newToolbarButton))
  47.                                    name
  48.                                    name
  49.                                    openMacro
  50.                             )
  51.                     )
  52.                    
  53.                     (if bitmap
  54.                          (progn
  55.                               (setq SmallBitmapName bitmap)
  56.                               (setq LargeBitmapName bitmap)
  57.                               (vla-setBitmaps newToolbarButtonItem SmallBitmapName LargeBitmapName)
  58.                          )
  59.                     )
  60.                    
  61.                     (vla-put-helpString newToolbarButtonItem helpString)
  62.                )
  63.                nameLst
  64.                macroLst
  65.                BitmapLst
  66.                helpLst
  67.           )
  68.           (vl-cmdf "_-toolbar" name "_bottom" "")
  69.      )
  70.      
  71.      (defun #createMenu ( / SeperatorPos nameLst macroLst helpLst)
  72.           (setq newMenu (vla-add (vla-get-menus currMenuGroup) name))
  73.          
  74.           (     (lambda (lst / i)
  75.                     (setq i 0)
  76.                     (foreach group lst
  77.                          (princ group)
  78.                          (terpri)
  79.                          (if (not group)
  80.                               (setq SeperatorPos (cons i SeperatorPos))
  81.                               (progn
  82.                                    (setq      nameLst      (cons (nth 0 group) nameLst)
  83.                                              macroLst     (cons (nth 1 group) macroLst)
  84.                                              helpLst          (cons (nth 2 group) helpLst)
  85.                                              bitmapLst     (cons (nth 3 group) bitmapLst)
  86.                                    )
  87.                               )
  88.                          )
  89.                          (setq i (1+ i))
  90.                     )                        
  91.                     (setq      SeperatorPos      (reverse SeperatorPos)
  92.                               nameLst               (reverse nameLst)
  93.                               macroLst          (reverse macroLst)
  94.                               helpLst               (reverse helpLst)
  95.                     )
  96.                )
  97.                menulst
  98.           )
  99.      
  100.           (mapcar
  101.                '(lambda (name macro helpString bitmap / newMenuItem openMacro SmallBitmapName LargeBitmapName)
  102.                     (setq openMacro (strcat (chr 3) (chr 3) macro (chr 32)))
  103.                     (setq newMenuItem
  104.                             (vla-addMenuItem
  105.                                newMenu
  106.                                (1+ (vla-get-count newMenu))
  107.                                name
  108.                                openMacro
  109.                             )
  110.                     )
  111.                    
  112.                     (if bitmap
  113.                          (progn
  114.                               (setq SmallBitmapName bitmap)
  115.                               (setq LargeBitmapName bitmap)
  116.                              
  117.                               ;;;error for menu  =(
  118.                               ;-> (vla-setBitmaps newMenuItem SmallBitmapName LargeBitmapName)
  119.                          )
  120.                     )
  121.                    
  122.                     (vla-put-helpString newMenuItem helpString)
  123.                )
  124.                nameLst
  125.                macroLst
  126.                helpLst
  127.                bitmapLst
  128.           )
  129.          
  130.           (foreach Pos SeperatorPos
  131.                 (vla-AddSeparator newMenu Pos)
  132.           )
  133.          
  134.           (progn
  135.                ;; insert the pulldown menu into the menu bar, at the end
  136.                (vla-insertInMenuBar
  137.                  newMenu
  138.                  (vla-get-count (vla-get-menuBar acadobj))
  139.                )
  140.           )    
  141.      )
  142.      
  143.      (setq      flag                nil
  144.                FileName           (strcat path name ".mns")
  145.                acadobj           (vlax-get-acad-object)
  146.                thisdoc           (vla-get-activeDocument acadobj)
  147.                menus                (vla-get-menuGroups acadobj)
  148.      )
  149.  
  150.      (vlax-for n menus
  151.           (if (= (vla-get-name n) name)
  152.                (setq flag T)
  153.           )
  154.           ;(terpri)
  155.           ;(princ (vla-get-name n))
  156.      )
  157.      
  158.      (if (not (findfile FileName))
  159.           (progn
  160.                (setq fn (open FileName "w"))
  161.                (close fn)
  162.           )
  163.      )
  164.      
  165.                (vl-catch-all-apply
  166.                     '(lambda ( / )
  167.                          (if (null flag)
  168.                               (vla-load menus FileName)
  169.                          )
  170.                     )
  171.                )
  172.           )
  173.           (princ "\nThe menu is already loaded")
  174.           (progn    
  175.                (setq currMenuGroup (vla-item menus name))
  176.                
  177.                (if (<= (vla-get-count (vla-get-menus currMenuGroup)) 0)
  178.                     (progn
  179.                          (if menulst
  180.                               (#createMenu)
  181.                          )
  182.                          (if toolbarlst
  183.                               (#createToolbar)
  184.                          )
  185.                          ;; re-compile the VBAMENU menu - VBAMENU.MNC
  186.                          (vla-save currMenuGroup acMenuFileCompiled)
  187.  
  188.                          ;; save it as a MNS file
  189.                          (vla-save currMenuGroup acMenuFileSource)
  190.                     )
  191.                     (princ "\nThe menu is already loaded")
  192.                )              
  193.           )
  194.      )
  195.      (princ)
  196. )
  197.  

(SS::CreateMenu "thats_a_menu" '(("nr1" "_move" "helpme" 'nil) ("nr2" "_rotate" "whirligig" 'nil)) '(("Tool1" "_move" "helpme" "D:\\bitmaps\\move.bmp") ("Tool2" "whatEver" "something" "some.bmp"))

andy_lee

  • Newt
  • Posts: 147
Re: Menu and Toolbars via Lisp
« Reply #2 on: May 11, 2015, 09:31:29 AM »
Now ,It's ok ?
andy.
Best regards.