Macro or API to use "Invert Selection" to unsuppress components
Macro or API to use "Invert Selection" to unsuppress components
(OP)
I am trying to write a SW API or Macro to unsuppress all but selected components in an assembly. It seems that "Invert Selection" command is not available in SW API. I tried to record a macro, but it did not capture "Invert Selection" command. Does anyone know how to access SW "Invert Selection" command in api?
I tried a couple of "Unsuppress all but selected components" macro and api programs downloaded from the internet. But their performances are nowhere near that of native "Unsuppress" plus "Invert selection" commands in SolidWorks.
Thanks,
Alex
SW 2006 sp 3.4
VB 6.0
I tried a couple of "Unsuppress all but selected components" macro and api programs downloaded from the internet. But their performances are nowhere near that of native "Unsuppress" plus "Invert selection" commands in SolidWorks.
Thanks,
Alex
SW 2006 sp 3.4
VB 6.0






RE: Macro or API to use "Invert Selection" to unsuppress components
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swswSelMgr As SldWorks.SelectionMgr
Dim vComponents As Variant
Dim swSelComp As SldWorks.Component2
Dim selCount As Integer
Dim i As Long
Dim bretval As Boolean
Dim swSelObj
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
If swModel.GetType = 2 Then
Set swconf = swModel.GetActiveConfiguration
Set swSelComp = swconf.GetRootComponent
vComponents = swSelComp.GetChildren
If UBound(vComponents) > 0 Then
Set swSelMgr = swModel.SelectionManager
selCount = swSelMgr.GetSelectedObjectCount
If selCount > 0 Then
ReDim swSelObj(selCount)
For i = 1 To selCount
If swSelMgr.GetSelectedObjectType2(i) = 20 Then
Set swSelObj(i) = swSelMgr.GetSelectedObject5(i)
Else
MsgBox "Please, select a component."
Exit Sub
End If
Next i
For i = 0 To UBound(vComponents)
bretval = vComponents(i).Select2(True, 0)
Next i
For i = 1 To selCount
swSelObj(i).DeSelect
Next i
End If
End If
Else
MsgBox "Please, open an Assembly."
End If
Set swModel = Nothing
Set swApp = Nothing
End Sub
RE: Macro or API to use "Invert Selection" to unsuppress components
You can find more examples on their page.
http://www.cadsolutions.ca/magazine/api.asp
That one works fine for me.
FF
RE: Macro or API to use "Invert Selection" to unsuppress components
Thanks for your quick replies. It seems that the code does not work on an assembly with sub-assemblies.
I would prefer using "Invert Selection" if it is available thru. api.
Thanks,
Alex
RE: Macro or API to use "Invert Selection" to unsuppress components
RE: Macro or API to use "Invert Selection" to unsuppress components
That is a good advice. But how do I map the "Invert Selection" command as it is not in SW standard menu. The "Invert Selection" is accessed through a menu right clicked on screen area after selecting components from screen.
If I can create a hotkey combination for this command, I can send it to SW from VB. I do not need to pause for this as I preselect components which I want unsuppressed.
Thanks,
Alex
RE: Macro or API to use "Invert Selection" to unsuppress components
RE: Macro or API to use "Invert Selection" to unsuppress components
Thanks! This works beautifully. I was unable to locate "Invert Selection" from SW menu.
By the way, you should not have to add any pause in VB when you send "SendKeys" statement. When you run "SendKeys" in VB, you just throw a series of commands into Windows's keyboard event queue to be executed. The "Wait" argument of the SendKeys state should take care of the problem.
There are times however that you may want to monitor execution of your statements to "slow down" your VB program to prevent overflow keyboard cache memory.
Alex
RE: Macro or API to use "Invert Selection" to unsuppress components
I agree that the Wait argument should take care of the problem. However, there have been times when I've used it that it didn't.
RE: Macro or API to use "Invert Selection" to unsuppress components
RE: Macro or API to use "Invert Selection" to unsuppress components
Would love to share everything I know.
What was my suggestion?
I just learnt from handleman that I can map my keyboard to "Invert Selection" command. So, here is what I do to suppress everything except the selected components/sub-assembies.
1. Preselect the components;
2. Send "Sendkeys" to SW using VB to execute "Invert Selection" (I assign "I" key to "Invert Selection" command.)
3. Send "Sendkeys" to SW using VB to execute "Suppress" command.
This method should also work in hide/show components. It is better than the couple of api programs I used before.
Alex