How to get data after using Window selection - Inventor VBA

How to get data after using Window selection - Inventor VBA

Anonymous
Not applicable
1,489 Views
11 Replies
Message 1 of 12

How to get data after using Window selection - Inventor VBA

Anonymous
Not applicable

Hi everyone, 

I searched some threads related to window selection but it did not answer my question. So I make a new question here, hope that someone can give me any suggestions.

In the Inventor help, I got window selection example1.JPG

my question is how to use the selection after using window selection.

For example,

1. if I pick an edge, so how to use this edge to create a drawing curve segment 

2. if I select a number of views (in Inventor drawing) , so how to use this selection to set an Object Collection, then I can use in other tasks

Many thanks

 

 

 

 

0 Likes
Accepted solutions (1)
1,490 Views
11 Replies
Replies (11)
Message 2 of 12

WCrihfield
Mentor
Mentor

Just in case you didn't notice, you have to have either a hole, or other circular part edges within your sample part file, and window select around that portion of the part, for that example macro to show you anything.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 12

WCrihfield
Mentor
Mentor

Near the bottom of the code, you'll notice a couple lines as follows:

Dim oEdge As Edge

Set oEdge = PreSelectEntity

You could add your own code before the end of that sub.

Or you could replace the MsgBox portion within the last Sub, to do whatever you want with the 'JustSelectedEntities' collection.

 

Earlier in the code you can find where they set the selection filter to "kPartEdgeCircularFilter".

You can change this to any other option within the SslectionFilterEnum list.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 12

Anonymous
Not applicable

@WCrihfield 

Thanks for your explanation, 

Actually, I use Visual Studio to run this code, but nothing happen.

There is a warning that Function "window select" doesn't return a value, I try to use return statement but it still remain.

1.JPG

I also attach this code in Visual studio, so could you please take a look and give me any suggestion.

Thanks in advance.

 

 

 

0 Likes
Message 5 of 12

WCrihfield
Mentor
Mentor

Which versions of Windows, Inventor, and Visual Studio are you using?

As far as debugging a series of VBA Subs & Functions using Visual Studio, I honestly haven't been using Visual Studio long enough to be very much help yet.  And I'm just using the free version of Visual Studio Code 2019.

But I did follow the instruction on the sample's page using Inventor's VBA Editor, and everything worked fine for me.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 12

Anonymous
Not applicable

@WCrihfield 

I use win 7, Inventor 2018 and Visual studio community 2019. 

The problem is this code in Inventor VBA is run successfully, but I want to use in VS to create an add in, however, there is an warning as I mentioned above.

I can see the window tooltip "Window select. Esc to exit.", but cannot choose any circular edges (please see picture below)

3.JPG

Hope that anyone can help me explain a bit. Thanks in advance.

 

 

 

 

0 Likes
Message 7 of 12

Anonymous
Not applicable

Hi All, 

Can anyone let me know how to use window selection in vb.net (in visual studio)?

Thanks in advance.

0 Likes
Message 8 of 12

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

I just tried to use this code in visual studio and it works. I created a simple winforms app with one button to start selecting and did some minor adjustments to the code. Added handles for the functions and also rewrote the arguments for the OnPreSelect function because they didn't match as they were written in the example.

 

See code below.

 

Imports Inventor


Public Class Form1
    Private WithEvents oInteractEvents As InteractionEvents
    Private WithEvents oSelectEvents As SelectEvents
    Private bTooltipEnabled As Boolean
    Private ThisApplication = GetObject(, "Inventor.Application")
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        WindowSelect()
    End Sub


    Public Function WindowSelect()
        ' Create an InteractionEvents object.
        oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents

        ' Ensure interaction is enabled.
        oInteractEvents.InteractionDisabled = False

        ' Set a reference to the select events.
        oSelectEvents = oInteractEvents.SelectEvents

        ' Set the filter for circular edges (this includes circular arcs).
        oSelectEvents.AddSelectionFilter(SelectionFilterEnum.kPartEdgeCircularFilter)

        oSelectEvents.WindowSelectEnabled = True

        bTooltipEnabled = ThisApplication.GeneralOptions.ShowCommandPromptTooltips
        ThisApplication.GeneralOptions.ShowCommandPromptTooltips = True

        oInteractEvents.StatusBarText = "Window select. Esc to exit."

        ' Start the InteractionEvents object.
        oInteractEvents.Start()
    End Function

    Private Sub oInteractEvents_OnTerminate()
        ' Reset to original value
        ThisApplication.GeneralOptions.ShowCommandPromptTooltips = bTooltipEnabled

        ' Clean up.
        oSelectEvents = Nothing
        oInteractEvents = Nothing
    End Sub

    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 View) Handles oSelectEvents.OnPreSelect
        ' Set a reference to the selected edge.
        ' Only circular edges can come through since the circular edge filter was set.
        Dim oEdge As Edge
        oEdge = PreSelectEntity

        ' Allow only fully circular edges to be picked.
        If Not oEdge.GeometryType = CurveTypeEnum.kCircleCurve Then
            DoHighlight = False
        End If
    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) Handles oSelectEvents.OnSelect
        MsgBox("Picked " & JustSelectedEntities.Count & " circular edges.")
    End Sub

End Class

 

0 Likes
Message 9 of 12

JhoelForshav
Mentor
Mentor

I assume though that you want the oSelectEvents_OnSelect sub to look like this insted:

 

 Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles oSelectEvents.OnSelect
        MsgBox("Picked " & oSelectEvents.SelectedEntities.Count & " circular edges.")
    End Sub

Since JustSelectedEntities.Count seems to always return 1.

0 Likes
Message 10 of 12

Anonymous
Not applicable

Hi @JhoelForshav ,

I try this code above, however, I don't know why it cannot work.

I record my screen (attached file), so could you take a look and see what happen here.

Many thanks.

 

 

 

 

0 Likes
Message 11 of 12

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

You must change the selection filter to kDrawingCurveSegmentFilter in WindowSelect if you want to be able to select curves in a drawing. Edge type is for edges on surfacebodies.

 

Also in preselct the variable should be changed to drawingcurvesegment.

See below code. I've also changed it to create a class "clsSelect" as suggested in the help. But if you just do the changes mentioned above it should work.

 

Imports Inventor


Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim oSelect As New clsSelect
        oSelect.WindowSelect()
    End Sub



End Class

Class clsSelect
    Private WithEvents oInteractEvents As InteractionEvents
    Private WithEvents oSelectEvents As SelectEvents
    Private bTooltipEnabled As Boolean
    Private ThisApplication = GetObject(, "Inventor.Application")

    Public Sub WindowSelect() 'Might as well be a sub
        ' Create an InteractionEvents object.
        oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents

        ' Ensure interaction is enabled.
        oInteractEvents.InteractionDisabled = False

        ' Set a reference to the select events.
        oSelectEvents = oInteractEvents.SelectEvents

        ' Set the filter for circular edges (this includes circular arcs).
        oSelectEvents.AddSelectionFilter(SelectionFilterEnum.kDrawingCurveSegmentFilter) 'Changed filter

        oSelectEvents.WindowSelectEnabled = True



        bTooltipEnabled = ThisApplication.GeneralOptions.ShowCommandPromptTooltips
        ThisApplication.GeneralOptions.ShowCommandPromptTooltips = True

        oInteractEvents.StatusBarText = "Window select. Esc to exit."

        ' Start the InteractionEvents object.
        oInteractEvents.Start()
    End Sub

    Private Sub oInteractEvents_OnTerminate()
        ' Reset to original value
        ThisApplication.GeneralOptions.ShowCommandPromptTooltips = bTooltipEnabled
        ' Clean up.
        oSelectEvents = Nothing
        oInteractEvents = Nothing

    End Sub

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

        Dim oCurve As DrawingCurveSegment 'Changed 
        oCurve = PreSelectEntity
        If Not oCurve.GeometryType = Curve2dTypeEnum.kCircleCurve2d Then
            DoHighlight = False
        End If
    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) Handles oSelectEvents.OnSelect
        MsgBox("Picked " & oSelectEvents.SelectedEntities.Count & " circular curves.")
    End Sub


End Class

 

 

Message 12 of 12

Anonymous
Not applicable

Hi @JhoelForshav 

I work fine now, I see that we don't use function anymore.

Thanks for your kind help,

 

0 Likes