problem with creating buttons and toolbar
Hi    
                                            
                                                  
 
                    i have problem with creating new buttons 
    below two function i use 
    functions sometimes works, sometimes not, then bricscad returns 
 error : Automation Error 80020009; [IAcadToolbars] Error accessing [ADD] method. ErrIndex=0;
i dont know why, is seems hazard but maybe there is a reason why those function returns error tested on V12, V13, V14 (same results)
           [code]      
                     (defun AddButtons (tgname button_lst / Toolbar newToolbarButton) ; tgname - toolbar group name button_lst - list of buttons         
                         ;;;; Createas buttons in toolbar group          
                         ;;;; example            
                         ; (AddButtons           
                         ; "DJTT"            
                         ; (list   "Apps"           
                         ; (list         
                           ; (list          
                           ; "app12" ;name          
                           ; "(load(findfile \"app12.LSP\"))" ;command          
                           ; (strcat main_cad_folder "Icony\\" "KalkulatorTMZ.bmp") ;path to icon           
                           ; (strcat main_cad_folder "Icony\\" "KalkulatorTMZ.bmp") ;path to icon           
                           ; "This button ..."                        ; help text          
                           ; )          
                         ; )         
                         ; )         
                         ; )         
                         (setq Toolbar nil)          
                         (vlax-for n (vla-get-toolbars (vla-item (vla-get-menuGroups (vlax-get-acad-object)) tgname))            
                           (if (= (vla-get-name n) (car button_lst))            
                               (setq Toolbar n)         
                           )            
                         )           
                         (if (not Toolbar)(setq Toolbar (vla-add (vla-get-toolbars (vla-item (vla-get-menuGroups (vlax-get-acad-object)) tgname)) (car button_lst)))) ; tworzy nowy toolbar          
                         (foreach button (nth 1 button_lst)          
                           (progn           
                               (print (nth 0 button))           
                               (setq newToolbarButton           
                                   (vla-addToolbarButton            
                                       Toolbar          
                                       (1+ (vla-get-count Toolbar))         
                                       (nth 0 button) (nth 0 button) (nth 1 button)   ; name and command           
                                   )            
                               )            
                               (setq SmallBitmapName (nth 2 button))      ; path to icon           
                               (setq LargeBitmapName (nth 2 button))            
                               (vla-setBitmaps newToolbarButton SmallBitmapName LargeBitmapName)            
                               (vla-put-helpString newToolbarButton (nth 3 button)) ; help          
                           )            
                         )           
                         ;; re-compile the tgname menu, this part doesn't work on bricscad           
                         ; (vla-save (vla-item (vla-get-menuGroups (vlax-get-acad-object)) tgname) acMenuFileCompiled)           
                         ; save it as a MNS file         
                         ; (vla-save (vla-item (vla-get-menuGroups (vlax-get-acad-object)) tgname) acMenuFileSource)         
                         )           
                         [/code]         
                         [code]          
                             (defun createToolbarGroup (tgname toolbarlist / fn flag) ;(createToolbarGroup "DJTT" '("Aplikacje" "Narzędzia"))                
                                 ;;;; Createas toolbar Group             
                                 ;;;; example (createToolbarGroup "DJTT" '("Apps"))              
                                 (setq flag nil)             
                                 (if (not (findfile (strcat tgname ".mns")))             
                                   (progn               
                                     (setq fn (open (strcat main_cad_folder tgname ".mns") "w"))                
                                     (close fn)             
                                   )                
                                 )               
                                 (vlax-for n (vla-get-menuGroups (vlax-get-acad-object))             
                                   (if (= (vla-get-name n) tgname)              
                                     (setq flag T)              
                                   )                
                                   (terpri)             
                                   (princ (vla-get-name n))             
                                 )               
                                 (if (null flag)             
                                   (vla-load (vla-get-menuGroups (vlax-get-acad-object)) (strcat tgname ".mns"))                
                                 )               
                                 (foreach tb toolbarlist             
                                   (vla-add (vla-get-toolbars (vla-item (vla-get-menuGroups (vlax-get-acad-object)) tgname)) tb)                
                                 )               
                                 )               
                 [/code]  
  0    
            Comments
- 
            0
 - 
            it is, but now it is problem with add method (maybe i shouldn't start new topic)i need to find any alternative for that addbuttons function, any tips?0
 - 
            Your functions are case-sensitive for names. Maybe that causes your problem.0
 - 
            can You explain case-sensitive problem, i don't understand what You mean.0
 - 
            Example:
Your functions will try to create a toolbar "MYTOOLBAR" if a toolbar with the name "MyToolbar" already exists. Which will cause an error.
To avoid this you can do something like this:
[code](= (strcase (vla-get-name n)) (strcase (car button_lst)))[/code]
And:
[code](= (strcase (vla-get-name n)) (strcase tgname))[/code]0 - 
            thanks guysi menage that by unload menugroup (if it already exist) and create new one0
 
This discussion has been closed.