"Remove add-in's upon exit" macro

Discussion in 'SolidWorks' started by google, Mar 1, 2006.

  1. google

    google Guest

    Our design studio has twenty floating licenses of SW and three of SW
    office.
    We make use of the office licenses for occasional Photoworks, animator
    and eDrawings pro usage.

    We have an issue with the way that licenses are given out in that the
    Office licenses can inadvertantly be hogged by users who aren't aware
    that they still have add-ins activated.
    A solution would be to have a 'remove add-ins components on exit'
    script to ensure that all users begin with 'Standard' Solidworks, then
    Office license will only be taken out when they are needed.

    Our reseller is quoting us a price for writing a macro. I'm sure it's
    a pretty straightforward script and would like to have a crack at it
    myself. However, I've never done anything like this before and wondered
    if anyone can help.

    Thanks,

    Kettle
     
    google, Mar 1, 2006
    #1
  2. google

    That70sTick Guest

    A macro can do the job, but everyone needs to remember to run the
    macro.

    An addin can be programmed to run when SW closes. However, I have seen
    that SW often fails to trigger events that signal that SW is closing.

    If you get a macro, it would be a simple thing to create an addin that
    triggers the macro. Then you can decide whether to trigger the macro
    at startup (more reliable) or shutdown. That, or you can convert the
    macro to an addin, maybe with built-in options to control how the addin
    is triggered and what addins are released.

    Template for creating an addin in VB. Follow the comments, shake and
    stir as needed:
    <http://www.esoxrepublic.com/devtools>
     
    That70sTick, Mar 1, 2006
    #2
  3. google

    Heikki Leivo Guest

    A macro can do the job, but everyone needs to remember to run the
    Well I don't think it is that straightforward. You can use a macro to load
    and unload addins, but if you want to know what addins there are, you need
    to tweak with registry. Of course you can write a quick-n-dirty solution if
    you know what addins to close, but if you want the macro to work regardless
    of what addins are installed and running, be prepared for some registry
    programming.

    -h-
     
    Heikki Leivo, Mar 1, 2006
    #3
  4. google

    SteveT Guest

    since these on/off settings are stored in the registry it seems like you
    only need to write a program to restore an exported registry key

    open solidworks
    set all addins to OFF
    close solidworks
    Then backup the addins key in the registry
    then write a batch file to apply the back up registry
    then the batch file would call the solidworks.exe

    change all the solidworks shortcuts on everyone's box to point to the batch
    file instead. This should change the registry first & then start solidworks
    with all addins off -- this way there should be no need to monitor
    solidworks shutting down.

    What I don't know of is how to mechanically do this -- or if you need to
    write a windows script instead.

    I hope this gets you going in the right direction though

    Steve T.
     
    SteveT, Mar 1, 2006
    #4
  5. google

    That70sTick Guest

    <http://www.esoxrepublic.com/devtools/>

    Same web page, different module. Feel free to use the registry
    utilities (plug into VB program).

    I assumed there was an API to access a list of available addins. It
    appears there is no such animal.
     
    That70sTick, Mar 1, 2006
    #5
  6. google

    Cliff Guest

    Use a timer .....?
     
    Cliff, Mar 2, 2006
    #6
  7. google

    Heikki Leivo Guest

    since these on/off settings are stored in the registry it seems like you
    Oh gosh, now _that_ was clever.

    No scripting is needed. You could use normal windows scheluded tasks to
    apply the registry values eg. every morning. You can apply a registry file
    silently by command "regedit.exe /s c:\foo\bar.reg"

    -h-
     
    Heikki Leivo, Mar 2, 2006
    #7
  8. google

    Kvick Guest

    However, I've never done anything like this before and wondered
    I'v made (with the help of this NG) a macro for loading or unloading a
    addin DLL. The way it works that it chacks if the defined DLL is loaded
    it unloads it and vice versa...

    Now I have a cleared all my addins from starting with SW and only start
    them whenever I need them. the advantage with this is that it does not
    write anything at the registry, so next time the addin is not started...
    so I would gather that it's just what you need... only it's not the
    exact solution you asked :p


    ------------------------------------------------------
    Dim swApp As Object

    Dim RetVal As Long


    'Path to the add in DLL
    Const strAddInPath As String = "C:\Program Files\whatever\example.dll"

    Sub main()

    Set swApp = Application.SldWorks
    If Not swApp Is Nothing Then
    RetVal = swApp.LoadAddIn(strAddInPath) 'Load Add in
    If RetVal = 2 Then 'add in already loaded
    'Unload the add in
    swApp.UnloadAddIn strAddInPath
    End If
    End If
    Set swApp = Application.SldWorks
    End Sub
    -------------------------------------------------------
     
    Kvick, Mar 2, 2006
    #8
  9. google

    TOP Guest

    I added something so it only removes a specific addin. In this case it
    removes photoworks from SW2004.

    I noticed that when this macro is run the checkbox on the photoworks
    addin does not accurately reflect the actual status of the addin, but
    the change actually happens as evidenced by the photowork toolbar
    disappearing.

    I wasn't able to find an API call that lists loaded addins.

    I think it is possible to get SW to read a macro on startup. Haven't
    checked this out though.

    'TOGGLE SPECIFIC ADDIN
    '
    ' KVICK 060301 TOGGLES ADDIN
    ' PBK 060302 ADDED ERROR CHECK AND ONLY REMOVES ADDIN
    '
    '
    Dim swApp As Object
    Dim BoolStatus As Boolean
    Dim RetVal As Long

    'Path to the add in DLL
    Const strAddInPath As String = "C:\Program
    Files\SolidWorks2004\photoworks\pworks.dll"

    Sub main()

    Set swApp = Application.SldWorks
    If Not swApp Is Nothing Then
    RetVal = swApp.LoadAddIn(strAddInPath) 'Load Add in
    Select Case RetVal
    Case 0, 1, 2 'add in already loaded
    'Unload the add in
    swApp.UnloadAddIn strAddInPath
    Case -1
    BoolStatus = MsgBox("An Error Occured Loading" & strAddInPath,
    vbInformation, "DLL Unload Status")
    End Select
    End If
    Set swApp = Application.SldWorks
    End Sub

    ' 0: Success. Add-In load was successful.
    '
    ' 1: Add-In not loaded. However, this is not an error condition.
    '
    ' -1: Add-In not loaded. Unknown error occurred.
    '
    ' 2: Add-In not loaded. Add-In is already loaded.
     
    TOP, Mar 2, 2006
    #9
  10. google

    Kvick Guest

    Nice... Here's the "commandline" for running macros on startup...

    "C:\Program Files\SolidWorks\SLDWORKS.exe" /m "X:\Macros\what.swp"
     
    Kvick, Mar 2, 2006
    #10
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.