assigning icons to toolbars through VBA

assigning icons to toolbars through VBA

a.kouchakzadeh
Advocate Advocate
952 Views
5 Replies
Message 1 of 6

assigning icons to toolbars through VBA

a.kouchakzadeh
Advocate
Advocate

Hello people

 

Im wondering if there is any way that I can assign icons to a newly created toolbar?

this is my code, its running perfect, but when the toolbar is created, it just shows the default Icons and all the same.

How can I assign icons to this toolbar with vba?

like giving a FilePath and a File name ex. *wmf file.

 

Public Sub CreateToolbar()
Dim MenuGroupObject As AcadMenuGroup
Dim ToolbarObject As AcadToolbar
Dim ToolbarItemObject As AcadToolbarItem
Dim ButtonObject As AcadToolbarItem
Set MenuGroupObject = ThisDrawing.Application.MenuGroups.Item(0)
Set ToolbarObject = MenuGroupObject.Toolbars.Add("New Dimensions")
Set ButtonObject = ToolbarObject.AddToolbarButton(0, "Align", "alignment dimension", "-vbarun ThisDrawing.AlignedDimension" & vbCr)
Set ButtonObject = ToolbarObject.AddToolbarButton(1, "Ordinate", "ordinate dimension", "-vbarun ThisDrawing.OrdinateDimension" & vbCr)
10 Set ButtonObject = ToolbarObject.AddToolbarButton(2, "Rotate", "rotate dimension", "-vbarun ThisDrawing.RotateDimension" & vbCr)
Set ButtonObject = ToolbarObject.AddSeparator(2)
12 Set ButtonObject = ToolbarObject.AddToolbarButton(4, "Angular", "angular dimension", "-vbarun ThisDrawing.AngularDimension" & vbCr)
13 Set ButtonObject = ToolbarObject.AddToolbarButton(5, "Diametric", "diametric dimension", "-vbarun ThisDrawing.DiametricDimension" & vbCr)
14 Set ButtonObject = ToolbarObject.AddToolbarButton(6, "Radial", "radial dimension", "-vbarun ThisDrawing.RadialDimension" & vbCr)
15 ToolbarObject.Visible = True
16 End Sub

 

by the way, how can i fix my toolbar position? is there anyway this can be done by code?

0 Likes
Accepted solutions (1)
953 Views
5 Replies
Replies (5)
Message 2 of 6

seabrahenrique
Advocate
Advocate

I guess the best way to do that u need is the CUI command.... I have been use this function to created my own plug-ins in AutoCAD...

 

Use the comand "CUI" in your AutoCAD command line and explore it!

 

Check here: https://knowledge.autodesk.com/support/autocad-lt/learn-explore/caas/CloudHelp/cloudhelp/2019/ENU/Au... Or even another material with the "CUI" comand.

 

I hope can help u 🙂

0 Likes
Message 3 of 6

a.kouchakzadeh
Advocate
Advocate

Hello

yeah that does work out and I'm currently I'm doing the job using CUI.

my challenge is, having many computers and many commands which takes too much time to do the same process for each command on each computer

0 Likes
Message 4 of 6

seabrahenrique
Advocate
Advocate
Accepted solution

In this case u can export and import a .CUIX file, u know?

 

henriqueseabra_1-1625259297049.png

 

This process will transfer u customization to another computers.

 

Message 5 of 6

a.kouchakzadeh
Advocate
Advocate

that was Great!!

Thansk alot Sir.

Message 6 of 6

Anonymous
Not applicable

Hello,

This topic is solved, but there is a method in vba to assign an image to each button you create.

 

For that, you have to know the path of the image files (.bmp) and use the property .setBitmaps of the buttons.

 

Exemple :

--------------

Set MyToolBar = currMenuGroup.Toolbars.add ("MyToolbar")

Set MyButton = MyToolBar.addToolbarButton ("","xxxx","xxxxx",Macro)

MyImage = "image.bmp" (or the complete path of the image)

MyButton.SetBitmaps MyImage, MyImage

---------------

 

And to set the position of your toolbar, use the property .Dock of the toolbar

MyToolBar.dock acToolbarDockRight (the toolbar il set to the right of the Autocad window)

 

Jerome.

 

0 Likes