Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

@Michael.Navara Instead of trying to assign the selected item to a predefined object type and see if an error occurs (try-catch), why don't you simply check the .type of the selected item?


@Darkforce_the_ilogic_guy Please find below the first section of code used in my macros which support selecting an object before running. As in your case, the selected object should be an occurrence. In my case, the user is only allowed to select one item.

Specific checks on the occurrence (is it visible, suppressed or else) are placed after this section. It's VBA, but it should be easily converted into iLogic.

'Declarations
Dim oSourceOcc As ComponentOccurrence

'Get the selected occurrence
If ThisApplication.ActiveDocument.SelectSet.Count = 0 Then

  'Let user select a component
  Set oSourceOcc = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select a component (or press ESC to quit)")

  'Quit if user pressed ESC
  If oSourceOcc Is Nothing Then
    End
  Else
    Call ThisApplication.ActiveDocument.SelectSet.Select(oSourceOcc)
  End If

ElseIf ThisApplication.ActiveDocument.SelectSet.Count > 1 Then

  'Inform user about too much selection
  MsgBox "Please select only one component at a time.", vbCritical + vbOKOnly, "<Macro Name>"
  End

Else

  'Check if selected item is an occurrence
  If Not ThisApplication.ActiveDocument.SelectSet(1).Type = kComponentOccurrenceObject And Not ThisApplication.ActiveDocument.SelectSet(1).Type = kComponentOccurrenceProxyObject Then

    'Inform user about incompatible selection
    MsgBox "Can't use this type of object." & vbCrLf & vbCrLf & "Please select a part or sub assembly and try again", vbCritical + vbOKOnly, "<Function Name>"
    End
  Else

    'Set source occurrence
    Set oSourceOcc = ThisApplication.ActiveDocument.SelectSet(1)
  End If
End If