|
add-in icons [vb.net 2008 express]
i am creating an add-in with multiple "features". i would like each feature to have a specific icon related to it. how or where would i add this in the code? i am making the assumption that it would be here:
vb code:
public sub addcommandmgr()
dim cmdgroup as icommandgroup
dim ibmp as new bitmaphandler
dim thisassembly as assembly
thisassembly = system.reflection.assembly.getassembly(me.gettype())
cmdgroup = icmdmgr.createcommandgroup(1, "emteq", "emteq add-in", "", -1)
cmdgroup.largeiconlist = ibmp.createfilefromresourcebitmap("emteq.toolbarlarge.bmp")
cmdgroup.smalliconlist = ibmp.createfilefromresourcebitmap("emteq.toolbarsmall.bmp")
cmdgroup.largemainicon = ibmp.createfilefromresourcebitmap("emteq.mainiconlarge.bmp")
cmdgroup.smallmainicon = ibmp.createfilefromresourcebitmap("emteq.mainiconsmall.bmp")
cmdgroup.addcommanditem("custom properties", -1, "add and modify custom properties", "custom properties", 0, "customproperties", "", 0)
cmdgroup.addcommanditem("pdf creator", -1, "create pdf from current drawing", "pdf creator", 1, "pdfcreator", "", 1)
cmdgroup.hastoolbar = true
cmdgroup.hasmenu = true
cmdgroup.activate()
thisassembly = nothing
ibmp.dispose()
end sub
tony szuta
cswa, cswp, cswp-smtl
the fifth parameter of the "addcommanditem" method is the icon index. it is the index of the picture in your bmps. the command items in the bmp splits every 16 pixels in small bitmaps guide and 24 pixels in large ones.
thanks,
artem
answer thanks artem. i just took a look at the image file and figured that out.
tony szuta
cswa, cswp, cswp-smtl
there was a post a while back where someone re-wrote the icon handler. i tried searching but it seems impossible to search just the api subforum??
originally posted by: matthew cempa
there was a post a while back where someone re-wrote the icon handler. i tried searching but it seems impossible to search just the api subforum??
this function is broken since the beginning of the new forum.
i'm having the same problem... and i've implemented the reworked bitmap handler code as well.
my code is:
public sub addcommandmgr()
dim oiconfiles as iconfiles
oiconfiles = new iconfiles
dim cmdgroup as icommandgroup
dim thisassembly as assembly
thisassembly = system.reflection.assembly.getassembly(me.gettype())
cmdgroup = icmdmgr.createcommandgroup(1, "invotec", "invotec engineering tools", "invotec engineering tools", -1)
cmdgroup.largeiconlist = oiconfiles.createfilefromicon(my.resources.toolbarlarge)
cmdgroup.smalliconlist = oiconfiles.createfilefromicon(my.resources.toolbarsmall)
cmdgroup.largemainicon = oiconfiles.createfilefromicon(my.resources.mainiconlarge)
cmdgroup.smallmainicon = oiconfiles.createfilefromicon(my.resources.mainiconsmall)
cmdgroup.addcommanditem("export bom", 0, "export bill of material to csv", "export bom", 0, "exportbom", "", 0)
cmdgroup.addcommanditem("clear exported bom", 1, "clear exported bom", "clear exported bom", 1, "clearexportedbom", "", 1)
cmdgroup.addcommanditem("print drawing release set", 2, "print drawing release set", "print drawing release set", 2, "printdrwrelset", "", 2)
cmdgroup.hastoolbar = true
cmdgroup.hasmenu = false
cmdgroup.activate()
thisassembly = nothing
ibmp.dispose()
end sub
which is pretty much straight out of the template w/ some modifications. however... in the end i get, in this case since i'm adding three commands, three icons... all the same and w/ all the same command... the last one. i don't see anything wrong w/ the code according to everything i've read. i am running swx 2008 x64 sp4ev (testing purposes) which i suppose could have something to do w/ it... but i doubt it.
any help would be appreciated.
thx,
eric
hello,
i also use the new bitmabhandler from the post and hope that it would be the soluten for my problem, but i doesn't.
my problem ist that the icons aren't shown in the customize menu. i added a screenshot to this post. what can be the problem?
my code:
public sub addcommandmgr()
dim cmdgroup as icommandgroup
dim ibmp as new newbitmaphandler
dim thisassembly as assembly
dim cmdindex0 as integer
dim cmdindex1 as integer
dim cmdindex2 as integer
dim cmdindex3 as integer
dim cmdindex4 as integer
dim title as string = "ct"
dim tooltip as string = "construction tools by georg draxler"
dim doctypes() as integer = {swdocumenttypes_e.swdocassembly, _
swdocumenttypes_e.swdocdrawing, _
swdocumenttypes_e.swdocpart}
thisassembly = system.reflection.assembly.getassembly(me.gettype())
cmdgroup = icmdmgr.createcommandgroup(1, title, tooltip, "", -1)
cmdgroup.largeiconlist = ibmp.createfilefromicon(my.resources.toolbarlarge) '("construction_tools.toolbarlarge.bmp", thisassembly)
cmdgroup.smalliconlist = ibmp.createfilefromicon(my.resources.toolbarsmall) '("construction_tools.toolbarsmall.bmp", thisassembly)
cmdgroup.largemainicon = ibmp.createfilefromicon(my.resources.mainiconlarge) '("construction_tools.mainiconlarge.bmp", thisassembly)
cmdgroup.smallmainicon = ibmp.createfilefromicon(my.resources.mainiconsmall) '("construction_tools.mainiconsmall.bmp", thisassembly)
cmdindex0 = cmdgroup.addcommanditem("stücklistensymbole prüfen", -1, "prüft ob alles stücklistenpositionen positioniert sind", "", 0, "raise_boomballooncheck", "pmpenable", 0)
cmdindex1 = cmdgroup.addcommanditem("schleißleisten konfiguration", -1, "erstell in einer schurrenbaugruppe die schleißleistenkonfiguration", "", 1, "raise_add_wearplates", "pmpenable", 1)
cmdindex2 = cmdgroup.addcommanditem("abmaße ermitteln", -1, "ermittelt in einer baugruppe die abmaße der blechteile", "", 2, "raise_get_measure", "pmpenable", 2)
cmdindex3 = cmdgroup.addcommanditem("schraubverbindung", -1, "einfügen von schraubverbindungen", "", 3, "showpmp", "pmpenable", 3)
'cmdindex4 = cmdgroup.addcommanditem2("stücklistensymbole prüfen", -1, "prüft ob alles stücklistenpositionen positioniert sind", "", 0, "raise_boomballooncheck", "pmpenable", 4, swcommanditemtype_e.swtoolbaritem)
cmdgroup.hastoolbar = true
cmdgroup.hasmenu = true
cmdgroup.activate()
for each doctype as integer in doctypes
dim cmdtab as icommandtab = icmdmgr.getcommandtab(doctype, title)
dim bresult as boolean
if cmdtab is nothing then
cmdtab = icmdmgr.addcommandtab(doctype, title)
dim cmdbox as commandtabbox = cmdtab.addcommandtabbox
dim cmdids(3) as integer
dim texttype(3) as integer
cmdids(0) = cmdgroup.commandid(cmdindex0)
texttype(0) = swcommandtabbuttontextdisplay_e.swcommandtabbutton_texthorizontal
cmdids(1) = cmdgroup.commandid(cmdindex1)
texttype(1) = swcommandtabbuttontextdisplay_e.swcommandtabbutton_texthorizontal
cmdids(2) = cmdgroup.toolbarid
texttype(2) = swcommandtabbuttontextdisplay_e.swcommandtabbutton_texthorizontal
bresult = cmdbox.addcommands(cmdids, texttype)
dim cmdbox1 as commandtabbox = cmdtab.addcommandtabbox()
redim cmdids(1)
redim texttype(1)
cmdids(0) = cmdgroup.toolbarid
texttype(0) = swcommandtabbuttontextdisplay_e.swcommandtabbutton_textbelow
bresult = cmdbox1.addcommands(cmdids, texttype)
cmdtab.addseparator(cmdbox1, cmdgroup.toolbarid)
end if
next
thisassembly = nothing
ibmp.dispose()
end sub
click for full image
it isn't really a big thing, i think solidworks just made things very messy for most beginners by loading in files from resources within an assembly.
basically, all that you need to do to use images in the toolbar is to provide the full path to a bitmap file located on in a folder that solidworks has access to, such as "c:\mytoolbaricons.bmp". the methods of the bitmap handlers just take in resource full names, extracts the images from the assembly, saves it out as an actual bitmap to a temporary folder, and returns the path to where this temporary image is located. then when it is disposed it deletes the temporary image files from the harddrive.
so... basically all that needs to be done is to pass the path of a file to use to the command groups largeiconlist, smalliconlist, largemainicon and smallmainicon in any way you like.
the simplest thing is to place the image in the location of the add-in itself, or a fixed location, and tell it to use that. the other way is to embed the file in the assembly or library like is done in the example, then load it to an actual file and save it like the bitmap handler does, but it does it in a very messy way. when i get 5 i will write a new simple bitmap handler that can load from a resource, an icon, multiple icon files stripped into a toolbar bitmap etc... and post it here.
*sorry* for late replay, but i was not in the office last week. i will give your soluten a try. thank you!
quick |
|