Discussion:
"Remove add-in's upon exit" macro
(too old to reply)
g***@stimulus.freeserve.co.uk
2006-03-01 09:20:39 UTC
Permalink
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
That70sTick
2006-03-01 14:02:06 UTC
Permalink
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>
Heikki Leivo
2006-03-01 21:23:05 UTC
Permalink
Post by That70sTick
A macro can do the job, but everyone needs to remember to run the
macro.
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-
That70sTick
2006-03-01 22:47:24 UTC
Permalink
<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.
Cliff
2006-03-02 00:47:26 UTC
Permalink
Post by That70sTick
A macro can do the job, but everyone needs to remember to run the
macro.
Use a timer .....?
--
Cliff
SteveT
2006-03-01 22:32:34 UTC
Permalink
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.
Post by g***@stimulus.freeserve.co.uk
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
Heikki Leivo
2006-03-02 05:11:49 UTC
Permalink
Post by SteveT
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
Oh gosh, now _that_ was clever.
Post by SteveT
What I don't know of is how to mechanically do this -- or if you need to
write a windows script instead.
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-
Kvick
2006-03-02 06:49:20 UTC
Permalink
Post by g***@stimulus.freeserve.co.uk
However, I've never done anything like this before and wondered
if anyone can help.
Thanks,
Kettle
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
-------------------------------------------------------
TOP
2006-03-02 12:53:31 UTC
Permalink
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.
Kvick
2006-03-02 14:11:31 UTC
Permalink
Post by TOP
I think it is possible to get SW to read a macro on startup. Haven't
checked this out though.
Nice... Here's the "commandline" for running macros on startup...

"C:\Program Files\SolidWorks\SLDWORKS.exe" /m "X:\Macros\what.swp"
Loading...