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

this rule will let you select ordinate dimension

Public Class ThisRule
    Sub Main()
        Dim oSelect As New Selector
        Dim selectedItems As ObjectsEnumerator = oSelect.Pick(ThisApplication)
        If selectedItems Is Nothing Then Return

		' selectedItems holds all of your Ordinate Dimension

        Dim oSelSet As SelectSet = ThisApplication.ActiveDocument.SelectSet
        oSelSet.Clear()
        For Each oFace In selectedItems
            oSelSet.Select(oFace)
        Next
    End Sub
End Class


Public Class Selector
    ' taken from:
    ' https://adndevblog.typepad.com/manufacturing/2016/07/filter-out-faces-not-facing-the-user.html

    Private WithEvents oInteractEvents As InteractionEvents
    Private WithEvents oSelectEvents As SelectEvents
    Private bStillSelecting As Boolean
	Private Sub oSelectEvents_OnPreSelect(
                ByRef PreSelectEntity As Object,
                ByRef DoHighlight As Boolean,
                ByRef MorePreSelectEntities As ObjectCollection,
                SelectionDevice As SelectionDeviceEnum,
                ModelPosition As Point,
                ViewPosition As Point2d, View As Inventor.View)
		
		'here we check if a selected item is of the type OrdinateDimension
        If Not TypeOf PreSelectEntity Is OrdinateDimension Then
            DoHighlight = False
            Exit Sub
        Else
            DoHighlight = True
        End If
    End Sub
	
    Public Function Pick(ThisApplication As Inventor.Application) As ObjectsEnumerator
        bStillSelecting = True
        oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents
        oInteractEvents.InteractionDisabled = False
        oSelectEvents = oInteractEvents.SelectEvents
        oSelectEvents.WindowSelectEnabled = True

        AddHandler oSelectEvents.OnPreSelect, AddressOf oSelectEvents_OnPreSelect
        AddHandler oSelectEvents.OnSelect, AddressOf oSelectEvents_OnSelect
        AddHandler oInteractEvents.OnTerminate, AddressOf oInteractEvents_OnTerminate

        oInteractEvents.Start()

        Do While bStillSelecting
            ThisApplication.UserInterfaceManager.DoEvents()
        Loop

        Dim oSelectedEnts As ObjectsEnumerator
        oSelectedEnts = oSelectEvents.SelectedEntities
        If oSelectedEnts.Count > 0 Then
            Pick = oSelectedEnts
        Else
            Pick = Nothing
        End If

        oInteractEvents.Stop()
        oSelectEvents = Nothing
        oInteractEvents = Nothing
    End Function

    Private Sub oInteractEvents_OnTerminate()
        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 Inventor.View)
        bStillSelecting = False
    End Sub
End Class

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com