Working with Toolbars

From the SWAddin Template...

SW2007 x64...

I am trying to figure out the toolbar or UI functions.

In this function:

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,

"SW Custom Tools", "Custom SolidWorks Macros", "", -1)

cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap(

"SWCustomTools2007.ToolbarLarge.bmp")

cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap(

"SWCustomTools2007.ToolbarSmall.bmp")

cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap(

"SWCustomTools2007.MainIconLarge.bmp")

cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap(

"SWCustomTools2007.MainIconSmall.bmp")

'cmdGroup.AddCommandItem("Link2BOM", -1, "Link all relevant views to BOM", "Link all relevant views to BOM", 0, "Link2BOM", "EnableLink2BOM", 0)

cmdGroup.AddCommandItem(

"CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", 0)

cmdGroup.AddCommandItem(

"Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "EnablePMP", 2)

cmdGroup.HasToolbar =

True

cmdGroup.HasMenu =

True

cmdGroup.Activate()

thisAssembly =

Nothing

iBmp.Dispose()

End Sub

EnablePMP is the call to enable or diasable this button, this function was named PMPEnable in the template which I am assuming was wrong.

Function EnablePMP() As Integer

If iSwApp.ActiveDoc = Nothing Then

EnablePMP = 0

Else

EnablePMP = 1

End If

End Function

so if there is no doc open then the button is disabled.

running this in debug mode the following appears in the Immediate Window:

A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

If I comment out everything in the EnablePMP() function then the msg in the immediate window does not appear but then the button does not get enabled or disabled. I am trying to get a button the I am adding to only be anabled when a drawingdoc is active but I came across this message. How do I fix it?

thanks in advance...

SolidworksApi macros