Jump to content

Opening a toolbar with Lisp or VBA in 2009?


muck

Recommended Posts

AutoCAD version 2009.

 

Is it possable to open a toolbar using lisp or vba in AutoCAD 2009?

Is it possable to close a toolbar using lisp or vba in AutoCAD 2009?

Can this be done to a group of toolbars at once

Can the toolbars be called out by name?

Thank you,

Link to comment
Share on other sites

AutoCAD version 2009.

 

Is it possable to open a toolbar using lisp or vba in AutoCAD 2009?

Is it possable to close a toolbar using lisp or vba in AutoCAD 2009?

Can this be done to a group of toolbars at once

Can the toolbars be called out by name?

Thank you,

 

Yes you can open and close the toolbars to when the drawing is opened and closed.

Link to comment
Share on other sites

Is it possable to open a toolbar using lisp or vba in AutoCAD 2009?

Is it possable to close a toolbar using lisp or vba in AutoCAD 2009?

Can this be done to a group of toolbars at once

Can the toolbars be called out by name?

Thank you,

 

Yes it possible. For example you can to define function for tollbars togle:

 

(defun ToolbarTogle(Menu Toolbar)
 (vl-load-com)
 (setq mCol(vla-get-MenuGroups
      (vlax-get-acad-object)))
 (if
   (not
     (vl-catch-all-error-p
(setq mObj(vl-catch-all-apply 'vla-Item
	    (list mCol Menu)))))
   (if
     (not
(vl-catch-all-error-p
  (setq tObj(vl-catch-all-apply 'vla-Item
	      (list(vla-get-Toolbars mObj)Toolbar)))))
(if(= :vlax-true(vla-get-Visible tObj))
  (vla-put-Visible tObj :vlax-false)
  (vla-put-Visible tObj :vlax-true)
  ); end if
     (princ(strcat "\n<!> Can't to find toolbar: " Toolbar " <!>"))
); end if
   (princ(strcat "\n<!> Can't to find menu group: " Menu " <!>"))
   ); end if
 (princ)
 ); end of ToolbarTogle

 

Open/close "Modify" toolbar of standard "ACAD" group:

 

(ToolbarTogle "ACAD" "Modify")

Link to comment
Share on other sites

Yes it possible. For example you can to define function for tollbars togle:

 

(defun ToolbarTogle(Menu Toolbar)
 (vl-load-com)
 (setq mCol(vla-get-MenuGroups
         (vlax-get-acad-object)))
 (if
   (not
     (vl-catch-all-error-p
   (setq mObj(vl-catch-all-apply 'vla-Item
           (list mCol Menu)))))
   (if
     (not
   (vl-catch-all-error-p
     (setq tObj(vl-catch-all-apply 'vla-Item
             (list(vla-get-Toolbars mObj)Toolbar)))))
   (if(= :vlax-true(vla-get-Visible tObj))
     (vla-put-Visible tObj :vlax-false)
     (vla-put-Visible tObj :vlax-true)
     ); end if
     (princ(strcat "\n<!> Can't to find toolbar: " Toolbar " <!>"))
   ); end if
   (princ(strcat "\n<!> Can't to find menu group: " Menu " <!>"))
   ); end if
 (princ)
 ); end of ToolbarTogle

Open/close "Modify" toolbar of standard "ACAD" group:

 

(ToolbarTogle "ACAD" "Modify")

very nice, i'm wondering, what's the coding to specify placement point for toolbar?

Link to comment
Share on other sites

very nice, i'm wondering, what's the coding to specify placement point for toolbar?

 

You can to use Float method to change toolbar position freely or Dock method to dock it in Top/Bottom/Left/Right screen side. Function with Float:

 

(defun ToolbarPosition(Menu Toolbar Top Left)
 (vl-load-com)
 (setq mCol(vla-get-MenuGroups
      (vlax-get-acad-object)))
 (if
   (not
     (vl-catch-all-error-p
(setq mObj(vl-catch-all-apply 'vla-Item
	    (list mCol Menu)))))
   (if
     (not
(vl-catch-all-error-p
  (setq tObj(vl-catch-all-apply 'vla-Item
	      (list(vla-get-Toolbars mObj)Toolbar)))))
     (vla-Float tObj Top Left 1)
     (princ(strcat "\n<!> Can't to find toolbar: " Toolbar " <!>"))
); end if
   (princ(strcat "\n<!> Can't to find menu group: " Menu " <!>"))
   ); end if
 (princ)
 ); end of ToolbarPosition

 

Move "Modify" toolbar to Top - 200 pixels and Left 50 pixels position:

 

(ToolbarPosition "ACAD" "Modify" 200 50)

 

Be carefull! You can move toolbar outside of screen area!

Link to comment
Share on other sites

I tryed using the first routine but I find that the toolbars do not

come back to their positions? I will try routine two. Is there a lisp

routine that retains orginal toolbar postions?

Link to comment
Share on other sites

Is there any routines that keep the toolbars in orginal postions when

toolbars are toggle back on. The first two routines seem to move the

toolbars???

Thank you,

Link to comment
Share on other sites

I tryed using the first routine but I find that the toolbars do not

come back to their positions?

 

:?: The first function should not change toolbar position it only swich on/off toolbar visibility. Probably such effect exists in 2009. I unfortunately cannot check up it.

 

I will try routine two. Is there a lisp

routine that retains orginal toolbar postions?

 

There isn't. Because position has not been kept where or. This is example code only. If you need you can to save old values of Top and Left properties to restore it in next session. For example:

 

(setq oldTop(vla-get-Top tObj)
       oldLeft(vla-get-Left tObj)
        ); end setq

Link to comment
Share on other sites

I think is depends on the order that the tool bars are removed. I think they

shift up and out. I have been using the following to remove/insert

tool bars.

 

;AUTOCAD 2009 TOOL BAR TOGGLE

(DEFUN C:Tbar()

(ToolbarTogle "ACAD" "Standard")

(ToolbarTogle "EQUIP" "Tanks/Vessels/Pumps/Nozzles")

(ToolbarTogle "EZ-PIPE" "Flanged Valves")

(ToolbarTogle "STLPLUS" "SteelPlus VR14")

 

(ToolbarTogle "ACAD" "Properties")

(ToolbarTogle "ACAD" "Layers")

(ToolbarTogle "ACAD" "Standard")

(ToolbarTogle "ACAD" "Styles")

(ToolbarTogle "ACAD" "Layers")

(ToolbarTogle "ACAD" "WorkSpaces")

(ToolbarTogle "ACAD" "Modify")

(ToolbarTogle "ACAD" "View")

'(ToolbarTogle "ACAD" "Draw Order")

 

 

(If (= tg 1)

(setq tg 0)

(setq tg 1)

)

 

(if (= tg 1)

(command "ribbonclose")

(command "ribbon")

)

 

 

)

 

(defun ToolbarTogle(Menu Toolbar)

(vl-load-com)

(setq mCol(vla-get-MenuGroups

(vlax-get-acad-object)))

(if

(not

(vl-catch-all-error-p

(setq mObj(vl-catch-all-apply 'vla-Item

(list mCol Menu)))))

(if

(not

(vl-catch-all-error-p

(setq tObj(vl-catch-all-apply 'vla-Item

(list(vla-get-Toolbars mObj)Toolbar)))))

(if(= :vlax-true(vla-get-Visible tObj))

(vla-put-Visible tObj :vlax-false)

(vla-put-Visible tObj :vlax-true)

); end if

(princ(strcat "\n Can't to find toolbar: " Toolbar " "))

); end if

(princ(strcat "\n Can't to find menu group: " Menu " "))

); end if

(princ)

); end of ToolbarTogle

 

 

 

(defun ToolbarTogleFIRST(Menu Toolbar)

(vl-load-com)

(setq mCol(vla-get-MenuGroups

(vlax-get-acad-object)))

(if

(not

(vl-catch-all-error-p

(setq mObj(vl-catch-all-apply 'vla-Item

(list mCol Menu)))))

(if

(not

(vl-catch-all-error-p

(setq tObj(vl-catch-all-apply 'vla-Item

(list(vla-get-Toolbars mObj)Toolbar)))))

(if(= :vlax-true(vla-get-Visible tObj))

(vla-put-Visible tObj :vlax-false)

(vla-put-Visible tObj :vlax-true)

); end if

(princ(strcat "\n Can't to find toolbar: " Toolbar " "))

); end if

(princ(strcat "\n Can't to find menu group: " Menu " "))

); end if

(princ)

); end of ToolbarTogle

Link to comment
Share on other sites

I think you can use ToolbarSwich function instead ToolbarTogle function:

 

(defun ToolbarSwich(Menu Toolbar Visible)
 (vl-load-com)
 (setq mCol(vla-get-MenuGroups
      (vlax-get-acad-object)))
 (if
   (not
     (vl-catch-all-error-p
(setq mObj(vl-catch-all-apply 'vla-Item
	    (list mCol Menu)))))
   (if
     (not
(vl-catch-all-error-p
  (setq tObj(vl-catch-all-apply 'vla-Item
	      (list(vla-get-Toolbars mObj)Toolbar)))))
(if Visible
  (vla-put-Visible tObj :vlax-true)
  (vla-put-Visible tObj :vlax-false)
  ); end if
     (princ(strcat "\n<!> Can't to find toolbar: " Toolbar " <!>"))
); end if
   (princ(strcat "\n<!> Can't to find menu group: " Menu " <!>"))
   ); end if
 (princ)
 ); end of ToolbarSwich

 

To swich on:

 

(ToolbarSwich "ACAD" "Layers" T)

 

To swich off:

 

(ToolbarSwich "ACAD" "Layers" nil)

 

And use FOREACH function for toolbar list. For example:

 

(setq tLst(list "Properties" "Layers" "Standard" "Styles" "WorkSpaces"))

 

Swich off all toolbar in list:

 

(foreach tb tLst
 (ToolbarSwich "ACAD" tb nil)
 )

 

Swich on all toolbar in list:

 

(foreach tb tLst
 (ToolbarSwich "ACAD" tb T)
 )

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...