2 Replies Latest reply on May 15, 2014 3:12 PM by Danny Bradford

    I would like a Dynamic command list based on file type

    Danny Bradford

      Greetings,

       

      I am adding 6 commands to Solidworks interface, but not all of them are for 3D and 2D. How do I set up Solidworks to only allow certain commands based on the file type?

       

      So in other words the command which creates Planes in 3D space would either be disabled or missing if the user is in a drawing.

       

      I am fine with disabled or missing. I have tried MANY variations of logic statements and variable trick but nothing is working.

       

      Thanks in advance!

       

      Danny B

        • Re: I would like a Dynamic command list based on file type
          Patrick O'Hern

          iModelDoc2::GetType will allow you to get the current document type (Part, Assy, Drawing).

            • Re: I would like a Dynamic command list based on file type
              Danny Bradford

              That is definitely a start, but where would I leverage? Here are severage locations where the command icon group is set:

               

              Section for defining the icons:

               

              cmdGroup = iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, cmdGroupErr)

                      If cmdGroup Is Nothing Or thisAssembly Is Nothing Then

                          Throw New NullReferenceException()

                      End If

               

               

                      cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("AACSolidWorksAddInMain.AAC_Icons_Large.bmp", thisAssembly)

                      cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("AACSolidWorksAddInMain.AAC_Icons_Small.bmp", thisAssembly)

                      cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("AACSolidWorksAddInMain.AAC_Icons_Large.bmp", thisAssembly)

                      cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("AACSolidWorksAddInMain.AAC_Icons_Small.bmp", thisAssembly)

               

               

                      Dim menuToolbarOption As Integer = swCommandItemType_e.swMenuItem Or swCommandItemType_e.swToolbarItem

               

               

                      cmdIndex0 = cmdGroup.AddCommandItem2("747-8 Reference Planes", -1, "Opens Dialog for 747-8 Reference Planes", "747-8 Reference Planes", 0, "CreatePlanes", 0, mainItemID1, menuToolbarOption)

                      cmdIndex1 = cmdGroup.AddCommandItem2("Custom Properties Tool", -1, "Display Custom Property Tool", "Custom Properties Tool", 1, "StartCustomProperties", 0, mainItemID2, menuToolbarOption)

                      cmdindex2 = cmdGroup.AddCommandItem2("Drawing Notes Tool", -1, "Start Drawing Notes Tool", "Custom Notes Tool", 2, "StartSWNotes", 0, mainItemID3, menuToolbarOption)

                      cmdindex3 = cmdGroup.AddCommandItem2("Export Drawing to ACAD", -1, "Exports active drawing to an ACAD file", "Export Drawing to ACAD", 3, "ExportToACAD", 0, mainItemID4, menuToolbarOption)

                      cmdindex4 = cmdGroup.AddCommandItem2("BOM Tool", -1, "Starts SolidWorks BOM Application", "BOM Tool", 4, "StartBOMTool", 0, mainItemID5, menuToolbarOption)

                      cmdindex5 = cmdGroup.AddCommandItem2("Add BOM Rows", -1, "Add BOM Rows to Drawings", "Add BOM Rows", 5, "AddBOMRows", 0, mainItemID6, menuToolbarOption)

               

               

                      cmdGroup.HasToolbar = True

                      cmdGroup.HasMenu = True

                      cmdGroup.Activate()

               

               

              Section for building the list:

               

              For Each docType As Integer In docTypes

                          Dim cmdTab As ICommandTab = iCmdMgr.GetCommandTab(docType, Title)

                          Dim bResult As Boolean

               

               

                          If Not cmdTab Is Nothing And Not getDataResult Or ignorePrevious Then 'if tab exists, but we have ignored the registry info, re-create the tab.  Otherwise the ids won't matchup and the tab will be blank

                              Dim res As Boolean = iCmdMgr.RemoveCommandTab(cmdTab)

                              cmdTab = Nothing

                          End If

               

               

                          If cmdTab Is Nothing Then

                              cmdTab = iCmdMgr.AddCommandTab(docType, Title)

               

               

                              Dim cmdBox As CommandTabBox = cmdTab.AddCommandTabBox

               

               

                              Dim cmdIDs(5) As Integer

                              Dim TextType(5) As Integer

               

               

                              cmdIDs(0) = cmdGroup.CommandID(cmdIndex0)

                              TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

               

               

                              cmdIDs(1) = cmdGroup.CommandID(cmdIndex1)

                              TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

               

               

                              cmdIDs(2) = cmdGroup.CommandID(cmdindex2)

                              TextType(2) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

               

               

                              cmdIDs(3) = cmdGroup.CommandID(cmdindex3)

                              TextType(3) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

               

               

                              cmdIDs(4) = cmdGroup.CommandID(cmdindex4)

                              TextType(4) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

               

               

                              cmdIDs(5) = cmdGroup.CommandID(cmdindex5)

                              TextType(5) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

               

               

                              bResult = cmdBox.AddCommands(cmdIDs, TextType)

               

               

                              Dim cmdBox1 As CommandTabBox = cmdTab.AddCommandTabBox()

                              ReDim cmdIDs(1)

                              ReDim TextType(1)

               

               

                              ' cmdIDs(0) = flyGroup.CmdID

                              '  TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

               

               

                              ' bResult = cmdBox1.AddCommands(cmdIDs, TextType)

               

               

                              'cmdTab.AddSeparator(cmdBox1, cmdIDs(0))

               

               

                          End If