×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Macro or API to use "Invert Selection" to unsuppress components
2

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

RE: Macro or API to use "Invert Selection" to unsuppress components

I found this bit of code as an example on how to invert selection within an assembly.  I haven't tried it yet, but here it is, so give it a go. :)


    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

That code is provided by CadSoutions.ca
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

(OP)
Hi, fcsuper and flower72:

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

If it were available in the API then nobody would go through the trouble of trying to re-create its function by writing a macro.  You may be able to get around this by mapping the "Invert Selection" command to some hotkey combination and then using a SendKeys statement in your macro to send that key combination to SW.  You may have to add a pause in your macro execution to allow SW to process the keystrokes prior to continuing.  See thread766-151134 for the code to pause VBA execution.

RE: Macro or API to use "Invert Selection" to unsuppress components

(OP)
Hi, Handleman:

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

Invert Selection is a standard item in the Tools menu.  The pause I mentioned is to allow SW to process the SendKeys statement before the VB continues execution.  I have found that many times when I use SendKeys the code will continue to execute before the target application has finished processing the sent keystrokes, even when the "Wait" argument of the SendKeys statement is set to True.  

RE: Macro or API to use "Invert Selection" to unsuppress components

(OP)
Hi, Handleman:

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

If you don't see "Invert Selection" in your Tools menu then go to Tools->Customize Menu and put a check-mark by it.

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

Care to share the results of your suggest, rgrayclamps? :)

RE: Macro or API to use "Invert Selection" to unsuppress components

(OP)
Hi, fcsuper:

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources