Add surface-finish to ExtensionLine by picking interactive from drawing

Add surface-finish to ExtensionLine by picking interactive from drawing

weiser
Advocate Advocate
928 Views
5 Replies
Message 1 of 6

Add surface-finish to ExtensionLine by picking interactive from drawing

weiser
Advocate
Advocate

Hi,

we are using only a few number of different surface-finish-symbols, so I like the user to click a "button" for inserting a specific symbol. After that the user only pick a CurveSegment, DimensionLine or ExtensionLine and the given symbol is added to the selected entity.

 

When using the CommandManager.Pick I can select the CurveSegment-Object, but when picking a dimenson at either the DimensionLine or the ExtensionLine AIP always selects the DimensionObject.

 

Is it possible to attach the surface symbol to the right picked entity?

 

Would be great to get some help!

0 Likes
929 Views
5 Replies
Replies (5)
Message 2 of 6

JelteDeJong
Mentor
Mentor

As far as I know, this is not possible. But if you are willing to use a bit more complicated code you can implement your own sector and get the point where the user clicked. Maybe you can use that point to figure out what kind of dimension line was selected.

I tried this by getting the DimensionLine object. That object has an evaluator and a function GetParamAtPoint.  that function will fail if the point is not on the DimensionLine. but did not get it to work and i really need to get to bed. Maybe someone else can get the GetParamAtPoint function to work. (this section is commented out)

 

Public Class ThisRule
    Sub Main()
        Dim doc As DrawingDocument = ThisDoc.Document

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

        Dim point As Point2d = selector.PointOnSheet
        Dim dimension As LinearGeneralDimension = selector.Dimension

        MsgBox("selected point on sheet: " & point.X & " , " & point.Y)

        doc.SelectSet.Clear()
        doc.SelectSet.Select(dimension)

	' Didn't get this to work....
        'Dim pointData() As Double = {point.X, point.Y}
        'Dim guessParams() As Double = {0, 1}
        'Dim maxDeviations() As Double
        'Dim params() As Double
        'Dim solTypes() As SolutionNatureEnum
		
	'Dim line As LineSegment2d = dimension.DimensionLine
        'line.Evaluator.GetParamAtPoint(pointData, guessParams, maxDeviations, params, solTypes)
    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."

        _selectEvents = _interactEvents.SelectEvents
        _selectEvents.WindowSelectEnabled = False
        _interactEvents.Start()

        Do While _stillSelecting
            _inventor.UserInterfaceManager.DoEvents()
        Loop

        _interactEvents.StatusBarText = String.Empty
        _interactEvents.Stop()
		_inventor.CommandManager.StopActiveCommand
        _selectEvents = Nothing
        _interactEvents = Nothing
    End Sub

    Public Property Dimension As LinearGeneralDimension
    Public Property PointOnSheet As Point2d

    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

        If TypeOf PreSelectEntity Is LinearGeneralDimension Then
            DoHighlight = True
        Else
            DoHighlight = False
        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

        Dimension = JustSelectedEntities.Item(1)
        PointOnSheet = _inventor.TransientGeometry.CreatePoint2d(ViewPosition.X, ViewPosition.Y)
        _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

0 Likes
Message 3 of 6

JelteDeJong
Mentor
Mentor

I found a solution. Try the following rule:

 

Public Class ThisRule
    Sub Main()
        Dim doc As DrawingDocument = ThisDoc.Document

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

        Dim point As Point2d = selector.PointOnSheet
        Dim dimension As LinearGeneralDimension = selector.Dimension


        Dim sheet As Sheet = doc.ActiveSheet
        Dim style1 As SurfaceTextureStyle = doc.StylesManager.SurfaceTextureStyles.Item(1)
        Dim definition As SurfaceTextureSymbolDefinition = sheet.SurfaceTextureSymbols.CreateDefinition(style1)

        Dim intent = sheet.CreateGeometryIntent(dimension, point)
        Dim collection = ThisApplication.TransientObjects.CreateObjectCollection()
        collection.Add(intent)

        Dim qwerty = sheet.SurfaceTextureSymbols.AddByDefinition(collection, definition)

        If (selector.DimensionLineIsSelected) Then
            qwerty.ProductionMethod = "DimensionLine selected"
        Else
            qwerty.ProductionMethod = "ExtensionLine selected"
        End If

    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."

        _selectEvents = _interactEvents.SelectEvents
        _selectEvents.WindowSelectEnabled = False
        _interactEvents.Start()

        Do While _stillSelecting
            _inventor.UserInterfaceManager.DoEvents()
        Loop

        _interactEvents.StatusBarText = String.Empty
        _interactEvents.Stop()
        _selectEvents = Nothing
        _interactEvents = Nothing
        _inventor.CommandManager.StopActiveCommand()
    End Sub

    Public Property Dimension As LinearGeneralDimension
    Public Property PointOnSheet As Point2d

    Public ReadOnly Property DimensionLineIsSelected As Boolean
        Get
            Dim line As LineSegment2d = Dimension.DimensionLine

            Dim x = PointOnSheet.X
            Dim y = PointOnSheet.Y
            Dim x1 = line.StartPoint.X
            Dim y1 = line.StartPoint.Y
            Dim x2 = line.EndPoint.X
            Dim y2 = line.EndPoint.Y

            Dim AB = Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
            Dim AP = Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1))
            Dim PB = Math.Sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y))

            Dim t = Math.Abs(AB - AP - PB)
            If (Math.Abs(AB - AP - PB) < 0.2) Then
                Return True
            Else
                Return False
            End If
        End Get
    End Property

    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

        If TypeOf PreSelectEntity Is LinearGeneralDimension Then
            DoHighlight = True
        Else
            DoHighlight = False
        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

        Dimension = JustSelectedEntities.Item(1)
        PointOnSheet = _inventor.TransientGeometry.CreatePoint2d(ModelPosition.X, ModelPosition.Y)
        _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

Message 4 of 6

weiser
Advocate
Advocate

Hi @JelteDeJong,

thanks for working so hard to solve the problem!

Acutally I have to deal with a problem with our new 3D-printer, so I do not get to try your solution.

When the problems with the hardware are solved I'll get back to your solution.

Thanks a lot for sharing your solution!!

Best wishes

0 Likes
Message 5 of 6

JelteDeJong
Mentor
Mentor

And an improved version that also allows you to select drawing curves:

Public Class ThisRule
    Sub Main()

        Dim doc As DrawingDocument = ThisDoc.Document
        Dim sheet As Sheet = doc.ActiveSheet
        Dim symbols As SurfaceTextureSymbols = sheet.SurfaceTextureSymbols

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

        If (selector.SelectedObjectType = SelectedObjectType.NoSelection) Then Return

        Dim style As SurfaceTextureStyle = doc.StylesManager.SurfaceTextureStyles.Item(1)
        Dim definition As SurfaceTextureSymbolDefinition = symbols.CreateDefinition(style)

        Dim intent As GeometryIntent = sheet.CreateGeometryIntent(selector.SelectedObject, selector.PointOnSheet)
        Dim collection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
        collection.Add(intent)

        Dim symbol As SurfaceTextureSymbol = symbols.AddByDefinition(collection, definition)

        Select Case selector.SelectedObjectType
            Case SelectedObjectType.DimensionLine
                symbol.ProductionMethod = "DimensionLine selected"
            Case SelectedObjectType.ExtensionLine
                symbol.ProductionMethod = "ExtensionLine selected"
            Case SelectedObjectType.DrawingCurve
                symbol.ProductionMethod = "DrawingCurve selected"
        End Select

    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 Object = Nothing
    Public Property PointOnSheet As Point2d = Nothing
    Public Property SelectedObjectType As SelectedObjectType = SelectedObjectType.NoSelection
    Public ReadOnly Property DimensionLineIsSelected As Boolean
        Get
            If (SelectedObject Is Nothing) Then Return False
            If (Not TypeOf SelectedObject Is LinearGeneralDimension) Then Return False

            Dim line As LineSegment2d = SelectedObject.DimensionLine

            Dim x = PointOnSheet.X
            Dim y = PointOnSheet.Y
            Dim x1 = line.StartPoint.X
            Dim y1 = line.StartPoint.Y
            Dim x2 = line.EndPoint.X
            Dim y2 = line.EndPoint.Y

            Dim AB = Math.Sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
            Dim AP = Math.Sqrt((x - x1) ^ 2 + (y - y1) ^ 2)
            Dim PB = Math.Sqrt((x2 - x) ^ 2 + (y2 - y) ^ 2)

            If (Math.Abs(AB - AP - PB) < 0.000001) Then
                Return True
            Else
                Return False
            End If
        End Get
    End Property

    ''' <summary>
    '''     check in this sub if the user hovers over a object that you are looking for
    ''' </summary>
    ''' <param name="PreSelectEntity">Object that the user is hovering over</param>
    ''' <param name="DoHighlight">Set True/False to highlight the selected objet(s)</param>
    ''' <param name="MorePreSelectEntities">Set to highlight more object</param>
    ''' <param name="ModelPosition">
    '''     Point of mouse in space. 
    '''     In 2D-space (drawings) the Z-value is 0.
    ''' </param>
    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 LinearGeneralDimension Then
            DoHighlight = True
        End If

        If TypeOf PreSelectEntity Is DrawingCurveSegment Then
            Dim segment As DrawingCurveSegment = PreSelectEntity
            If (segment.GeometryType = Curve2dTypeEnum.kLineSegmentCurve2d) 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)
        PointOnSheet = _inventor.TransientGeometry.CreatePoint2d(ModelPosition.X, ModelPosition.Y)

        If TypeOf SelectedObject Is DrawingCurveSegment Then
            SelectedObject = SelectedObject.Parent
            SelectedObjectType = SelectedObjectType.DrawingCurve
        Else
            If (DimensionLineIsSelected) Then
                SelectedObjectType = SelectedObjectType.DimensionLine
            Else
                SelectedObjectType = SelectedObjectType.ExtensionLine
            End If
        End If

        _stillSelecting = False
    End Sub

End Class
Public Enum SelectedObjectType
    NoSelection
    DrawingCurve
    DimensionLine
    ExtensionLine
End Enum

 

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

Message 6 of 6

weiser
Advocate
Advocate

Hi @JelteDeJong ,

thanks for offering this solution. I just pasted it into my VB.NET-project.

Everything works fine so far, but the interaction when selecting entities is a bit "strange"...

When calling the sub, a plus appears newr the cursor an I first have to click on the sheet to start the "real selection".

Is there any way to change this?

Is it possible to built a loop wihtin the sub which repeats the insert process until the ESC-key is pressed?

Best regards

Inventor-InsertSurfaceSymbol.gif

 

0 Likes