Selecting when Addin is visible - API

Discussion in 'SolidWorks' started by AllanRaun, Jul 14, 2006.

  1. AllanRaun

    AllanRaun Guest

    I've created an Addin by using the VB.net Addin template from the SW
    website.

    It seems to be working fine, but i can't figure out how to change it's
    availability. if SW has no file open, or a part file open, the menu is
    visible. as soon as i open an assembly, the menu disappears.

    i did find the 'CommandGroup' object, and it's methods, in the help
    file, but none of the links there work, and the 'ShowInDocumentType'
    property didn't help me either...

    has anyone worked with the addin template? do you know where in the
    code it determines what type of document it's available for? It doesn't
    even use the 'ShowInDocumentType' property anywhere.

    Any ideas?
     
    AllanRaun, Jul 14, 2006
    #1
  2. AllanRaun

    Heikki Leivo Guest

    I.M.O it is "documented" in the API help, altough with no details:

    Output: (long ) *ShowInDocumentType
    Types of documents in which to show this CommandGroup as defined in
    swDocTemplateTypes_e

    When the addin loads, you get a command manager for the addin
    (SldWorks::GetCommandManager). Then you can create command groups by calling
    CommandManager::CreateCommandGroup. After adding individual command items
    (CommandManager::CreateCommandItems) you can define the document types in
    which the command group should be visible
    (CommandGroup::ShowInDocumentType). For example,

    Dim foo as SldWorks.CommandGroup
    ....
    foo.ShowInDocumentType = swConst.swDocTemplateTypes_e.swDocTemplateTypePART

    As swDocTemplateTypes_e is a bitmask, you can combine document types by
    ORring them together.

    I have used the command manager api, and IMO it works rather well; it is
    much better than the original SldWorks::AddMenu and SldWorks::AddMenuItem
    methods since you can easily create both menus and toolbars with same
    function calls.

    Hope this helps!

    -h-
     
    Heikki Leivo, Jul 14, 2006
    #2
  3. AllanRaun

    AllanRaun Guest

    i tried the ShowInDocumentType, setting it to the assembly option, but
    it didn't work. with that setting it should ONLY show in assembly
    documents, but it still shows in everything BUT assembly documents.

    the stranger thing is that the Addin template you can download from
    solidworks is available in all document types except assemblies, but
    ShowInDocumentType is never used. i can't find in their code how it's
    decided when it's shown and when it's not.

    has anyone successfully changed the template to show in assemblies?

    here's a link to the template:
    http://www.solidworks.com/downloads/API/Downloads/00000/0300s/0373/VBTemplate.zip

    Allan
     
    AllanRaun, Jul 18, 2006
    #3
  4. AllanRaun

    Heikki Leivo Guest

    Hello,
    Check if you have used swDocumentTypes_e.swDocAssembly instead of
    swDocTemplateTypes_e.swDocTemplateTypeAssembly. It is mentioned in the API
    help that

    swDocTemplateTypes_e.swDocTemplateTypeAssembly equals 4, whereas
    swDocumentTypes_e.swDocAssembly equals 2. Quite confusing, huh?
    swDocumentTypes_e is a normal enum (1, 2, 3, ..) but swDocTemplateTypes_e is
    a bitmask (1, 2, 4, 8...).

    I tested with Visual Studio 2005 and SW 2006 Add-In template and it works as
    expected.

    -h-
     
    Heikki Leivo, Jul 18, 2006
    #4
  5. AllanRaun

    AllanRaun Guest

    getting closer, but still no luck... i can now control wether it's
    shown in parts, or if nothing's open, but i still can't get it to show
    in assemblies.

    in AddCommandMgr(), I've add a line just before:
    cmdGroup.HasToolbar = True
    which is now:
    cmdGroup.ShowInDocumentType =
    swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY +
    swDocTemplateTypes_e.swDocTemplateTypeNONE

    which should mean, the addin is visible in assemblies, and when nothing
    is open, but it's only visible when nothing is open.


    i think somehow my ShowInDocumentType is overridden in the
    eventhandling section. when an assembly is opened, it goes through a
    load of modelview connections that i don't understand, and the menu
    disappears.

    Ok, revelation... the toolbar works as expected, but the 'VBAddin' Menu
    still disappears.

    need to find out how that happens....
     
    AllanRaun, Jul 19, 2006
    #5
  6. AllanRaun

    CS Guest

    This is how to do it using a command group
    Vb.Net 2005 Example

    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, "FireWorks",
    "FireWorks", "", -1)
    cmdGroup.LargeIconList =
    iBmp.CreateFileFromResourceBitmap("FireWorks.Prop-n-ExcelLarge.bmp")
    cmdGroup.SmallIconList =
    iBmp.CreateFileFromResourceBitmap("FireWorks.Prop-n-ExcelSmall.bmp")
    cmdGroup.LargeMainIcon =
    iBmp.CreateFileFromResourceBitmap("FireWorks.AE-Logo.bmp")
    cmdGroup.SmallMainIcon =
    iBmp.CreateFileFromResourceBitmap("FireWorks.AE-Logo.bmp")

    cmdGroup.AddCommandItem("Edit Material", -1, "Allows you to
    select a material to apply to the active document", "Edit Material", 0,
    "EditMaterial", "EnableEditMaterial", 0)
    cmdGroup.AddCommandItem("Estimate material", -1, "Estimates the
    material used in this body and saves the data to Excel", "Estimate
    Material", 2, "EstimateMaterial", "EnableEstimateMaterial", 2)

    cmdGroup.HasToolbar = True
    cmdGroup.HasMenu = True
    cmdGroup.Activate()

    thisAssembly = Nothing
    iBmp.Dispose()
    End Sub


    ''' <summary>
    ''' This method is used to Enable Edit Materials controls depending
    on the open document
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function EnableEditMaterial() As Integer
    Dim MD As SldWorks.ModelDoc2
    MD = iSwApp.ActiveDoc
    Select Case MD.GetType
    Case SwConst.swDocumentTypes_e.swDocPART
    Return 1
    Case Else
    Return 0
    End Select
    If MD Is Nothing Then
    Return 0
    End If
    End Function
     
    CS, Jul 21, 2006
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.