Try this,
using Vba.net:
Public Sub AddParticipant()
Dim oApp As Application
Dim oAD As AssemblyDocument
Dim oACD As AssemblyComponentDefinition
Dim oFeats As Features
Dim oObjFeat As Object
Dim oObjCompCol As ObjectCollection
Dim oCoCC As ComponentOccurrence
Dim oFirstStep As Boolean
Dim oSecondStep As Boolean
oFirstStep = False
oSecondStep = False
Dim oIE As InteractionEvents
Dim oSE As SelectEvents
Dim oSelect As clsSelect
Set oApp = ThisApplication
If oApp.ActiveDocumentType = kAssemblyDocumentObject Then
Set oAD = oApp.ActiveDocument
Set oACD = oAD.ComponentDefinition
Set oFeats = oACD.Features
Set oObjCompCol = oApp.TransientObjects.CreateObjectCollection
Do Until oFirstStep = True
Set oObjFeat = oApp.CommandManager.Pick(kAssemblyFeatureFilter, "Pick feature. Esc to exit.")
If oObjFeat Is Nothing Then
WantContinueSelecting = MsgBox("No feature are selected, want continue selecting?", vbYesNo + vbCritical, "Selection Feature Result")
If WantContinueSelecting = vbYes Then
oFirstStep = False
Else
Set oObjCompCol = Nothing
Set oFeats = Nothing
Set oACD = Nothing
Set oAD = Nothing
Set oApp = Nothing
Exit Sub
End If
Else
oFirstStep = True
End If
Loop
Do Until oSecondStep = True
Set oSelect = New clsSelect
oSelect.Pick SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, oObjCompCol
If oObjCompCol.Count = 0 Then
WantContinueSelecting = MsgBox("No component are selected, want continue selecting?", vbYesNo + vbCritical, "Selection Component Result")
If WantContinueSelecting = vbYes Then
oSecondStep = False
Else
Exit Sub
End If
Else
oSecondStep = True
End If
Loop
For Each Item In oObjCompCol
oObjFeat.AddParticipant Item
Next
End If
End Sub
create class module, name it "clsSelect" :
Private WithEvents oInteractEvents As InteractionEvents
Private WithEvents oSelectEvents As SelectEvents
' Declare a flag that's used to determine when selection stops.
Private bStillSelecting As Boolean
Public Function Pick(ByVal filter As SelectionFilterEnum, ByRef oBjcol As ObjectCollection) As Object
' Initialize flag.
bStillSelecting = True
' Create an InteractionEvents object.
Set oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents
' Ensure interaction is enabled.
oInteractEvents.InteractionDisabled = False
' Set a reference to the select events.
Set oSelectEvents = oInteractEvents.SelectEvents
' Set the filter using the value passed in.
oSelectEvents.AddSelectionFilter filter
oSelectEvents.WindowSelectEnabled = True
' Start the InteractionEvents object.
' bTooltipEnabled = ThisApplication.GeneralOptions.ShowCommandPromptTooltips
ThisApplication.GeneralOptions.ShowCommandPromptTooltips = True
oInteractEvents.StatusBarText = "Please select component. Esc to exit."
oInteractEvents.Start
' Loop until a selection is made.
Do While bStillSelecting
ThisApplication.UserInterfaceManager.DoEvents
Loop
' Get the selected item. If more than one thing was selected,
' just get the first item and ignore the rest.
Dim oSelectedEnts As ObjectsEnumerator
Set oSelectedEnts = oSelectEvents.SelectedEntities
If oSelectedEnts.Count > 0 Then
For Each Item In oSelectedEnts
oBjcol.Add Item
Next
Else
Set Pick = Nothing
End If
' Stop the InteractionEvents object.
oInteractEvents.Stop
' Clean up.
Set oSelectEvents = Nothing
Set oInteractEvents = Nothing
End Function
Private Sub oInteractEvents_OnTerminate()
' Set the flag to indicate we're done.
bStillSelecting = False
End Sub
Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
' Set the flag to indicate we're done.
bStillSelecting = False
End Sub
Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.
Autodesk Inventor Professional Certified 2014