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: Rich-T

Maybe you want to have a look at this rule. It is a bit complex when it comes to selecting the plane/point. (Line 31 to line 109).  But the important part (and easiest part) is in the first part of the rule.

Public Class ThisRule
	Sub Main()
		Dim doc As PartDocument = ThisDoc.Document
        Dim def As PartComponentDefinition = doc.ComponentDefinition

        Dim selector As New Selector(ThisApplication)
        selector.Pick()

        Dim sketch = def.Sketches.Add(selector.SelectedObject)
        Dim modelPoint As Point2d = sketch.ModelToSketchSpace(selector.ModelPosition)


        Dim partNumber = iProperties.Value("Project", "Part Number")
        Dim sketchText = sketch.TextBoxes.AddFitted(modelPoint, partNumber)

        Dim textSketchEntities As SketchEntitiesEnumerator = sketchText.ConvertToGeometry("txt")

        Dim markGeometry As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
        For Each oSE As SketchEntity In textSketchEntities
            markGeometry.Add(oSE)
        Next

        Dim markFeatures As MarkFeatures = def.Features.MarkFeatures
        Dim markStyle As MarkStyle = doc.MarkStyles.Item("Mark Surface")
        Dim markDef As MarkDefinition = markFeatures.CreateMarkDefinition(markGeometry, markStyle)
        markDef.Direction = PartFeatureExtentDirectionEnum.kNegativeExtentDirection
        markFeatures.Add(markDef)

    End Sub
End Class
Public Class Selector

    Private WithEvents _interactEvents As InteractionEvents
    Private WithEvents _selectEvents As SelectEvents
    Private _stillSelecting As Boolean
    Private _inventor As Inventor.Application

    Public Sub New(ThisApplication As Inventor.Application)
        _inventor = ThisApplication
    End Sub

    Public Sub Pick()
        _stillSelecting = True

        _interactEvents = _inventor.CommandManager.CreateInteractionEvents
        _interactEvents.InteractionDisabled = False
        _interactEvents.StatusBarText = "Select a LinearGeneralDimension."
        _interactEvents.SetCursor(CursorTypeEnum.kCursorBuiltInLineCursor)

        _selectEvents = _interactEvents.SelectEvents
        _selectEvents.WindowSelectEnabled = False

        _interactEvents.Start()
        Do While _stillSelecting
            _inventor.UserInterfaceManager.DoEvents()
        Loop
        _interactEvents.Stop()

        _inventor.CommandManager.StopActiveCommand()

    End Sub

    Public Property SelectedObject As Face = Nothing
    Public Property ModelPosition As Point = Nothing

    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) Handles _selectEvents.OnPreSelect

        DoHighlight = False

        If TypeOf PreSelectEntity Is Face Then
            If TypeOf PreSelectEntity.Geometry Is Plane Then
                DoHighlight = True
            End If
        End If


    End Sub

    Private Sub oInteractEvents_OnTerminate() Handles _interactEvents.OnTerminate
        _stillSelecting = 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) Handles _selectEvents.OnSelect

        SelectedObject = JustSelectedEntities.Item(1)

        If TypeOf SelectedObject Is Face Then
            If TypeOf SelectedObject.Geometry Is Plane Then
                Me.SelectedObject = SelectedObject
                Me.ModelPosition = ModelPosition
            End If
        End If

        _stillSelecting = 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