设置两种过滤条件

在Inventor中做交互操作时,是否能同时设置kDrawingNoteFilter和kDrawingDimensionFilter两个过滤条件呢?也就是说是否可以让用户选择这两种标注样式呢?

答案是肯定的。除了两个特别的过滤条件(kSketchProfileFilter和kSketch3DProfileFilter),别的类型的过滤条件累加是没有问题的(通过重复调用AddSelectionFilter)。Inventor的开发帮组文档对AddSelectionFilter的参数的解释中暗示了可以增加多个过滤条件:

Parameters

Description

Filter

Input value to be added to the list that specifies the filter or the indication of the type of object(s) being looked for. The valid filters for sketch profile selection are kSketchProfileFilter, kSketch3DProfileFilter or both. If either of these filters is added, no other filters can be added (method returns an error). If any filter other than these two are already added, adding these filters return an error.

下面是我写的VBA测试代码,可以返回用户选取的标注文字和标注尺寸:

Module1:

Sub twoFilters()

‘ Create a new clsSelect object.

Dim oSelect As New clsSelect

Dim objs As ObjectCollection

Set objs = ThisApplication.TransientObjects.CreateObjectCollection

oSelect.Pick objs

Set oSelect = Nothing

If objs.Count > 0 Then

‘Do something here…

End If

objs.Clear

Set objs = Nothing

End Sub

Class clsSelect:

‘*************************************************************

‘ 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 “testSelection” to use the new name.

‘ Declare the event objects

Private WithEvents oInteractEvents As InteractionEvents

Private WithEvents oSelectEvents As SelectEvents

Private oSelectedEnts As ObjectCollection

‘ Declare a flag that’s used to determine when selection stops.

Private bStillSelecting As Boolean

Public Sub Pick(ByRef objCol As ObjectCollection)

‘ Initialize flag.

bStillSelecting = True

‘ 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 using the value passed in.

oSelectEvents.SingleSelectEnabled = False

oSelectEvents.AddSelectionFilter kDrawingNoteFilter

oSelectEvents.AddSelectionFilter kDrawingDimensionFilter

oInteractEvents.StatusBarText = “Select note and dimention, ESC to quit.”

Set oSelectedEnts = ThisApplication.TransientObjects.CreateObjectCollection

‘ Start the InteractionEvents object.

oInteractEvents.Start

‘ Loop until a selection is made.

Do While bStillSelecting

DoEvents

Loop

‘ Get the selected items.

objCol.Clear

If oSelectedEnts.Count > 0 Then

Dim obj As Object

For Each obj In oSelectedEnts

objCol.Add obj

Next

End If

‘ Stop the InteractionEvents object.

oInteractEvents.Stop

‘ Clean up.

Set oSelectEvents = Nothing

Set oInteractEvents = Nothing

End Sub

Private Sub oInteractEvents_OnTerminate()

‘ Set the flag to indicate we’re done.

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 View)

Dim obj As Object

For Each obj In JustSelectedEntities

oSelectedEnts.Add obj

Next

End Sub

Private Sub oSelectEvents_OnUnSelect(ByVal UnSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)

Dim obj As Object

For Each obj In UnSelectedEntities

oSelectedEnts.RemoveByObject obj

Next

End Sub

经历一种身体下了地狱,眼睛进入天堂,灵魂归入故里。

设置两种过滤条件

相关文章:

你感兴趣的文章:

标签云: