.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding a Toolbar

4 REPLIES 4
Reply
Message 1 of 5
vampirefromtheITcave2
844 Views, 4 Replies

Adding a Toolbar

I'm writing a function for AutoCAD that needs a button to run the command. Most of it works, but the button just puts the command text in the command line and does not run it (no enter). I've tried the space recommended by the help sites, but it doesn't change anything. How do I make it work without having to go into the command line and hit enter? Here are the things I've tried:

loadPostButton = newToolBar.AddToolbarButton(0, "LoadPost", "Operations and Posting", "LoadPost")
loadPostButton = newToolBar.AddToolbarButton(0, "LoadPost", "Operations and Posting", "LoadPost" & " ")
loadPostButton = newToolBar.AddToolbarButton(0, "LoadPost", "Operations and Posting", "LoadPost\n")
loadPostButton = newToolBar.AddToolbarButton(0, "LoadPost", "Operations and Posting", "LoadPost ")
loadPostButton = newToolBar.AddToolbarButton(0, "LoadPost", "Operations and Posting", "LoadPost;") Edited by: vampirefromtheitcave2 on Jan 6, 2010 9:15 PM
4 REPLIES 4
Message 2 of 5

First comment... My preference is to use the semicolon, rather than a space. Both would work under most circumstances. I also am in the habit of putting two Ctrl-C's (^C^C) on the front of any macro that can not be run transparently (while another command is prompting). That will make sure that if the user clicks the button while a command is in progress, it will cancel the previous command before attempting to run the new one.

Second, I can't find the signature for this AddToolbarButton Method in the object browser, so either you are on an older version than me, or have something referenced that I don't, or it's one of your own functions. (I'm on 2010, AcCui and AcCustomize referenced)

Anyway, this is some code I have which will create a new .CUIX file with a toolbar and three buttons if it does not exist. This code will not load the new menu, though. This is all I've got that deals with menus in Managed code. I had to edit some of the strings to shorten the lines, but I tried to leave enough to tell what's going on.

Theoretically, this code could be slightly adapted to add the toolbar and buttons to the main customization section af the acad menu, instead of a separate partial menu, but I tend to avoid adding things to the acad base menu.

{code}
Dim pcs As CustomizationSection = New CustomizationSection
pcs.MenuGroupName = "SR2GMTRS"
Dim mg As MacroGroup = New MacroGroup("SR2GMTRSMacros", pcs.MenuGroup)
mg.CreateMenuMacro("Name", "^C^Cmcp-loc;", "ID_MCPLOC", "Tooltip", Any, "1.bmp", "1.bmp", Nothing)
mg.CreateMenuMacro("Name", "^C^Cmod-pnl;", "ID_MODPNL", "Tooltip", Any, "2.bmp", "2.bmp", Nothing)
mg.CreateMenuMacro("Name", "^C^Cmcpol;", "ID_MCPOL", "Tooltip", Any, "3.bmp", "3.bmp", Nothing)
Dim sc As New Collections.Specialized.StringCollection
sc.Add("SR2G Mtrs Main")
Dim tb As New Toolbar("TBname", "Description", "ID", sc, True, floating, 200, 200, 1, pcs.MenuGroup)
Dim btn1 As New ToolbarButton("ID_MCPLOC", "Locate MCP Panels", tb, -1)
Dim btn2 As New ToolbarButton("ID_MODPNL", "Modify MCP Panel", tb, -1)
Dim btn3 As New ToolbarButton("ID_MCPOL", "Draw MCP Oneline", tb, -1)
tb.ToolbarItems.Add(btn1)
tb.ToolbarItems.Add(btn2)
tb.ToolbarItems.Add(btn3)
pcs.SaveAs(My.Application.Info.DirectoryPath & "\SR2Gelec.cuix")
{code}

Edited by: chiefbraincloud on Jan 6, 2010 5:52 PM

So much for attempting to make the formatting readable... but I also forgot to mention this code was written for Acad2009, not 2010, the only difference being that the file extension should be .CUI for 2009 instead of .CUIX. That said, I'm not 100% sure, but I think some of these Objects and/or methods were new to the 2009 API, so I don't think it could be made to work for 2008 or before.
Dave O.                                                                  Sig-Logos32.png
Message 3 of 5

I'm using AutoCAD 2007 for my testing, but some machines that I will be installing on use AutoCAD 2010. I retried all of the options I listed before with the two control C's. The function AddToolbarButton is in Autodesk.AutoCAD.Interop. I could try including the customization files, but I'd rather do it the way I've been attempting if possible because it seems simpler.
Message 4 of 5

What imports or references do you need for customizationsection. I get an undefined type error when trying to use it.

 

Thanks

Message 5 of 5

Never mind, I figured it out.

 

Reference required is AcCui.dll

Imports Autodesk.AutoCAD.Customization

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost