How to create a cross selection via the API

How to create a cross selection via the API

bradeneuropeArthur
Mentor Mentor
843 Views
9 Replies
Message 1 of 10

How to create a cross selection via the API

bradeneuropeArthur
Mentor
Mentor

Hi,

How to create a cross selection via the API.

bradeneuropeArthur_0-1620036325085.png

Regards,

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Accepted solutions (2)
844 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Hi,

i think this have to be done by emulating the mouse selection. But i'm not sure if there isn't another way.

 

 

 

    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, ByVal y As Integer) As Integer
    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal dwData As Integer, ByVal dwExtraInfo As Integer)
	
	
	Public Sub CrossSelection()
        Call MouseWindowSelect(1800, 1000, -600, -500) 'your coordinates
    End Sub
	

    Private Sub MouseWindowSelect(ByVal XFrom As Long, ByVal YFrom As Long, ByVal dX As Long, ByVal dY As Long)
        SetCursorPos(XFrom, YFrom)
        mouse_event(&H2, 0, 0, 0, 0) 'Mouse Leftdown
        System.Threading.Thread.Sleep(100)
        mouse_event(&H1, dX, dY, 0, 0) 'Mouse Movement
        System.Threading.Thread.Sleep(100)
        SetCursorPos(dX, dY)
        System.Threading.Thread.Sleep(100)
        mouse_event(&H4, 0, 0, 0, 0) 'Mouse Leftup
    End Sub

 

 

 

Regards

0 Likes
Message 3 of 10

WCrihfield
Mentor
Mentor

By "cross selection" do you mean window selection?  You may have seen this one before, but there is a sample program (uses VBA) within the online help, that shows you how to do window selection.  There are also some similar iLogic versions of it too.  Is that what you were looking for?

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 10

bradeneuropeArthur
Mentor
Mentor

@WCrihfield 

Do you get this to work?

For me not!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 10

Anonymous
Not applicable

For the example from WCrihfield make sure you have circular edges in the part or change the selection filter in the class module. Then it works for me.

 

' Set the filter for circular edges (this includes circular arcs).
    oSelectEvents.AddSelectionFilter kPartEdgeCircularFilter
0 Likes
Message 6 of 10

bradeneuropeArthur
Mentor
Mentor

I have no possibilities to select something!

The class is activated but nothing can be selected!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Yes. It worked for me.  It initially was a bit confusing, but after carefully reading through it, and noticing how they set the selection filter, and how the pre-select sub was more specifically singling out circular edges, I then tried it in a few appropriate test files, which contained that type of geometry, it worked.  However, I generally tend to do most of my coding in iLogic/vb.net, instead of VBA, so I created an iLogic rule version of it that I set-up for selecting part bodies (also works on component occurrences in an assembly setting), instead of circular part edges.  It may be a little easier to read/follow and get to work for you this way, depending on your situation.

Here's the code for that rule:

Sub Main
	Dim oSelect As New clsSelect
	oSelect.WindowSelect(ThisApplication)
	MsgBox(oSelect.oSelObjs.Count,,"Selected Objects Count")
End Sub

Class clsSelect
	Private WithEvents oInteractEvents As InteractionEvents
	Private WithEvents oSelectEvents As SelectEvents
	Private oToolTipsOn As Boolean
	Private ThisApplication As Inventor.Application
	Public oSelObjs As ObjectsEnumerator
	Private oStillSelecting As Boolean = True

	Public Sub WindowSelect(oApp As Inventor.Application)
		ThisApplication = oApp
		oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents
		oInteractEvents.InteractionDisabled = False
		oSelectEvents = oInteractEvents.SelectEvents
		oSelectEvents.AddSelectionFilter(SelectionFilterEnum.kPartBodyFilter)
		oSelectEvents.WindowSelectEnabled = True
		oToolTipsOn = ThisApplication.GeneralOptions.ShowCommandPromptTooltips
		ThisApplication.GeneralOptions.ShowCommandPromptTooltips = True
		oInteractEvents.StatusBarText = "Select Part Bodies (or Component Occurrences). Esc to finish."
		oInteractEvents.Start()
		While oStillSelecting
			ThisApplication.UserInterfaceManager.DoEvents()
		End While
	End Sub
	Private Sub oInteractEvents_OnTerminate() Handles oInteractEvents.OnTerminate
		ThisApplication.GeneralOptions.ShowCommandPromptTooltips = oToolTipsOn
		oSelectEvents = Nothing
		oInteractEvents = Nothing
		oStillSelecting = False
	End Sub
	Private Sub oSelectEvents_OnSelect(ByVal JustSelected As ObjectsEnumerator, ByVal SelDevice As SelectionDeviceEnum, ByVal ModelPos As Point, ByVal ViewPos As Point2d, ByVal oView As Inventor.View) Handles oSelectEvents.OnSelect
		oSelObjs = oSelectEvents.SelectedEntities
	End Sub
	Private Sub oSelectEvents_OnUnSelect(UnSelectedEntities As ObjectsEnumerator, SelDevice As SelectionDeviceEnum, ModelPos As Point, ViewPos As Point2d, oView As Inventor.View) Handles oSelectEvents.OnUnSelect
		oSelObjs = oSelectEvents.SelectedEntities
	End Sub
End Class

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 10

bradeneuropeArthur
Mentor
Mentor

what is the reason it did not work in VBA?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 9 of 10

WCrihfield
Mentor
Mentor
Accepted solution

The VBA version was working for me.  You may not have set it up correctly, if its not working for you.  Setting it up within the VBA Editor can be a bit odd/unexpected if your not used to using the 'Class Modules'.  So, I put pretty much all my VBA Macros within a custom application project that all users have access to on a shared drive.  Under the application project, in the tree view, you have three folders ("Forms", "Modules", & "Class Modules").  The first part of the code in that sample should be put into a regular Module by itself, and called "TestWindowSelection".  That regular module will only contain the first Private oSelect As clsSelect line, and the first Sub TestWindowSelection() block of code.

Private oSelect As clsSelect

Public Sub TestWindowSelection()
    ' Create a new clsSelect object.
    Set oSelect = New clsSelect

    ' Call the WindowSelect method of the clsSelect object
    oSelect.WindowSelect
End Sub

 

  All the rest of the code below that point (blue comment block, Private WithEvents, and so on) should be put into a new 'Class Module' by itself, under the folder called "Class Modules", and that Class Module should be named "clsSelect" (important).

'*************************************************************
' The declarations and functions below need to be copied into
' a class module whose name is "clsSelect". The name can be
' changed but you'll need to change the declaration in the
' calling function "TestWindowSelection" to use the new name.

' Declare the event objects
Private WithEvents oInteractEvents As InteractionEvents
Private WithEvents oSelectEvents As SelectEvents

' Declare a flag that's used to determine if command prompts are shown as tooltips.
Private bTooltipEnabled As Boolean

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

    ' Ensure interaction is enabled.
    oInteractEvents.InteractionDisabled = False

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

    ' Set the filter for circular edges (this includes circular arcs).
    oSelectEvents.AddSelectionFilter 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.
    Set oSelectEvents = Nothing
    Set oInteractEvents = Nothing
End Sub

Private Sub oSelectEvents_OnPreSelect(PreSelectEntity As Object, DoHighlight As Boolean, MorePreSelectEntities As ObjectCollection, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
    ' Set a reference to the selected edge.
    ' Only circular edges can come through since the circular edge filter was set.
    Dim oEdge As Edge
    Set oEdge = PreSelectEntity

    ' Allow only fully circular edges to be picked.
    If Not oEdge.GeometryType = 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)
    MsgBox "Picked " & JustSelectedEntities.Count & " circular edges."
End Sub

 

Then within the regular Module, when it creates a new instance of that class for the variable oSelect, it accesses the class module that corresponds to that class' name to for all the information about it.  Very different and awkward setting it up this way, when you're used to working with iLogic and vb.net for a long time.

If you already had it all set-up correctly, and it still isn't working, maybe there's something within the code that doesn't work with your specific version of Inventor, I'm not sure.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 10

bradeneuropeArthur
Mentor
Mentor

Thanks @Anonymous @WCrihfield

This modification did the trick:

bradeneuropeArthur_0-1620155149677.png

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes