设置两种过滤条件

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

答案是肯定的。除了两个特别的过滤条件(kSketchProfileFilterkSketch3DProfileFilter),别的类型的过滤条件累加是没有问题的(通过重复调用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

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值