03-03 创建和编辑AutoCAD实体(三) 使用选择集(2)

前端之家收集整理的这篇文章主要介绍了03-03 创建和编辑AutoCAD实体(三) 使用选择集(2)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

4、DefineRules for Selection Filters定义选择集过滤器规则

You can limit which objects are selectedand added to a selection set by using a selection filter. A selection filterlist can be used to filter selected objects by properties or type. For example,you might want to select only blue objects or objects on a certain layer. Youcan also combine selection criteria. For example,you can create a selectionfilter that limits selection to blue circles on the layer named Pattern.Selection filters can be specified as a parameter for the different selectionmethods in SelectObjects in the Drawing Area.

我们可以通过使用选择过滤器来限制哪些对象被选中并添加到选择集。选择过滤器列表用来通过属性或类型过滤所选对象,例如,我们可能想只选择蓝色的对象或某一图层上的对象。我们还可以使用选择条件组合,例如,我们可以创建一个选择过滤器将选择对象限定于Pattern图层上的蓝色的圆。可以为“在图形区域选择对象”一节中的各种不同选择方法指定选择过滤器作为参数。

Note Filtering recognizes values explicitly assigned toobjects,not those inherited by the layer. For example,if an object’s linetypeproperty is set to ByLayer and the layer it is assigned is set to the Hiddenlinetype; filtering for objects assigned the Hidden linetype will not selectthese objects since their linetype property is set to ByLayer.

注意:使用过滤只能识别显式赋给对象的值,而不能识别继承自图层的那些值。比如,如果对象的线型属性设置为随图层(ByLayer)而该图层线型为Hidden,那么要过滤线型为Hidden的对象将不会选择那些线型属性为随图层(ByLayer)的对象。

Topics in this section本小节内容

·Use Selection Filters to Define Selection Set Rules 使用选择过滤器定义选择集规则

·Specify Multiple Criteria in a Selection Filter 多个过滤条件

·Add Complexity to Your Filter List Conditions 复杂的过滤条件

·Use Wild-Card Patterns in Selection Set Filter Criteria 在过滤条件里使用通配

·Filter for Extended Data 过滤扩展数据

4.1、UseSelection Filters to Define Selection Set Rules使用选择过滤器定义选择集规则

Selection filters are composed of pairs ofarguments in the form of TypedValues. The first argument of a TypedValueidentifies the type of filter (for example,an object),and the second argumentspecifies the value you are filtering on (for example,circles). The filtertype is a DXF group code that specifies which filter to use. A few of the mostcommon filter types are listed here.

选择过滤器由TypedValue形式的一对参数构成。TypedValue的第一个参数表明过滤器的类型(例如对象),第二个参数为要过滤的值(例如圆)。过滤器类型是一个DXF组码,用来指定使用哪种过滤器。一些常用过滤器类型列表如下。

For a complete list of DXF group codes,see Group Code Value Types in the DXF Reference.

DXF组码的完整列表,见DXF参考手册中组码值类型一节

Specify a single selection criterion fora selection set 指定单个选择条件

The following code prompts users to selectobjects to be included in a selection set,and filters out all objects exceptfor circles.

下面程序提示用户选择对象放到选择集内,然后过滤掉圆以外的其他所有对象。

VB.NET

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

ImportsAutodesk.AutoCAD.EditorInput

<CommandMethod("FilterSelectionSet")>_

Public SubFilterSelectionSet()

'' Get the current document editor

Dim acDocEd As Editor =Application.DocumentManager.MdiActiveDocument.Editor

'' Create a TypedValue array to define thefilter criteria

Dim acTypValAr(0) As TypedValue

acTypValAr.SetValue(NewTypedValue(DxfCode.Start,"CIRCLE"),0)

'' Assign the filter criteria to aSelectionFilter object

Dim acSelFtr As SelectionFilter = NewSelectionFilter(acTypValAr)

'' Request for objects to be selected in thedrawing area

Dim acSSPrompt As PromptSelectionResult

acSSPrompt = acDocEd.GetSelection(acSelFtr)

'' If the prompt status is OK,objects wereselected

If acSSPrompt.Status = PromptStatus.OK Then

Dim acSSet As SelectionSet =acSSPrompt.Value

Application.ShowAlertDialog("Number ofobjects selected: " & _

acSSet.Count.ToString())

Else

Application.ShowAlertDialog("Numberof objects selected: 0")

End If

End Sub

C#

usingAutodesk.AutoCAD.Runtime;

usingAutodesk.AutoCAD.ApplicationServices;

usingAutodesk.AutoCAD.DatabaseServices;

usingAutodesk.AutoCAD.EditorInput;

[CommandMethod("FilterSelectionSet")]

public static voidFilterSelectionSet()

{

// Get the current document editor获取当前文档编辑器

Editor acDocEd =Application.DocumentManager.MdiActiveDocument.Editor;

// Create a TypedValue array to define thefilter criteria

// 创建一个TypedValue数组来定义过滤器条件

TypedValue[] acTypValAr = new TypedValue[1];

acTypValAr.SetValue(newTypedValue((int)DxfCode.Start,0);

// Assign the filter criteria to aSelectionFilter object

// 将过滤器条件赋值给SelectionFilter对象

SelectionFilter acSelFtr = newSelectionFilter(acTypValAr);

// Request for objects to be selected in thedrawing area

// 请求用户在图形区域选择对象

PromptSelectionResult acSSPrompt;

acSSPrompt = acDocEd.GetSelection(acSelFtr);

// If the prompt status is OK,255)"> // 提示状态OK,表示用户已选完

if (acSSPrompt.Status == PromptStatus.OK)

{

SelectionSet acSSet = acSSPrompt.Value;

Application.ShowAlertDialog("Number of objects selected: " +

acSSet.Count.ToString());

}

else

Application.ShowAlertDialog("Numberof objects selected: 0");

}

VBA/ActiveX CodeReference

Sub FilterSelectionSet()

' Create a new selection set

Dim sset As AcadSelectionSet

Set sset =ThisDrawing.SelectionSets.Add("SS1")

' Define the filter list,only Circleobjects

' will be selectable

Dim FilterType(0) As Integer

Dim FilterData(0) As Variant

FilterType(0) = 0

FilterData(0) = "Circle"

' Prompt the user to select objects

' and add them to the selection set

sset.SelectOnScreen FilterType,FilterData

MsgBox "Number of objects selected:" & sset.Count

' Remove the selection set at the end

sset.Delete

End Sub

4.2、SpecifyMultiple Criteria in a Selection Filter多个过滤条件

A selection filter can contain filteringcriteria for more than just one property or object. You define the total numberof conditions to filter on by declaring an array containing enough elements torepresent each of the filter criterion.

选择过滤器可以包含过滤多个属性或对象的条件。可以通过声明一个包含足够数量元素的数组来定义总的过滤条件,数组的每个元素代表一个过滤条件。

Select objects that meet two criterion 选择满足两个条件的对象

The following example specifies twocriterion to filter selected objects by: the object must be a circle and itmust reside on layer 0.

下面示例指定两个条件过滤所选对象:对象为圆且在0层上。

VB.NET

<CommandMethod("FilterBlueCircleOnLayer0")>_

Public SubFilterBlueCircleOnLayer0()

Dim acTypValAr(2) As TypedValue

acTypValAr.SetValue(NewTypedValue(DxfCode.Color,5),1)

acTypValAr.SetValue(NewTypedValue(DxfCode.LayerName,"0"),2)

'' Assign the filter criteria to a SelectionFilterobject

Application.ShowAlertDialog("Numberof objects selected: " & _

[CommandMethod("FilterBlueCircleOnLayer0")]

public static voidFilterBlueCircleOnLayer0()

// 创建TypedValue数组定义过滤条件

TypedValue[] acTypValAr = new TypedValue[3];

acTypValAr.SetValue(new TypedValue((int)DxfCode.Color,1);

acTypValAr.SetValue(newTypedValue((int)DxfCode.LayerName,2);

// 将过滤条件赋值给SelectionFilter对象

// 请求在图形区域选择对象

PromptSelectionResult acSSPrompt;

// 如果提示状态OK,表示对象已选

Application.ShowAlertDialog("Numberof objects selected: " +

acSSet.Count.ToString());

SubFilterBlueCircleOnLayer0()

' on layer 0

Dim FilterType(2) As Integer

Dim FilterData(2) As Variant

FilterType(0) = 62: FilterData(0) = 3

FilterType(1) = 0: FilterData(1) ="Circle"

FilterType(2) = 8: FilterData(2) ="0"

End Sub

4.3、AddComplexity to Your Filter List Conditions复杂的过滤条件

When you specify multiple selectioncriteria,AutoCAD assumes the selected object must meet each criterion. You canqualify your criteria in other ways. For numeric items,you can specifyrelational operations (for example,the radius of a circle must be greaterthan or equal to 5.0). And for all items,you can specify logicaloperations (for example,Text or MText).

当指定多个选择条件时,AutoCAD假设所选对象必须满足每个条件。我们还可以以别的方式搞定过滤条件。对于数值项,可以使用关系运算(比如,远的半径必须大于等于5.0)。对于所有项,可以使用逻辑运算(比如单行文字或多行文字)。

Use a -4 DXF code or the constantDxfCode.Operator to indicate a relational operator in a selection filter. Theoperator is expressed as a string. The allowable relational operators are shownin the following table.

使用DXF组码-4或常量DxfCode.Operator表示选择过滤器中的关系预算符类型。运算符本身用字符串表示。可用的关系运算符列表如下:

@H_502_681@

Relational operators for selection set filter lists关系运算符列表

Operator运算符

Description描述

"*"

Anything goes (always true)任何情况(总为True)

"="

Equals等于

"!="

Not equal to不等于

"/="

Not equal to不等于

"<>"

Not equal to不等于

"<"

Less than小于

"<="

Less than or equal to小于等于

">"

Greater than大于

">="

Greater than or equal to大于等于

"&"

Bitwise AND (integer groups only)位与(仅限整数组)

"&="

Bitwise masked equals (integer groups only)位屏蔽等于(仅限整数组)

Logical operators in a selection filterare also indicated by a -4 group code or the constant DxfCode.Operator,and theoperator is a string,but the operators must be paired. The opening operator ispreceded by a less-than symbol (<),and the closing operator is followed bya greater-than symbol (>). The following table lists the logical operatorsallowed in selection set filtering.

选择过滤器中的逻辑操作符同样用-4组码或常量DxfCode.Operator表示,逻辑操作符为字符串,且必须成对出现。操作符开始于小于号(<),结束于大于号(>)。下表;列出了用于选择集过滤器的逻辑操作符。

@H_502_681@

Logical grouping operators for selection set filter lists

Starting operator起始操作符

Encloses包括

Ending operator结束操作符

"<AND"

One or more operands一个以上操作数

"AND>"

"<OR"

One or more operands一个以上操作数

"OR>"

"<XOR"

Two operands两个操作数

"XOR>"

"<NOT"

One operand一个操作数

"NOT>"

Select a circle whose radius is greaterthan or equal to 5.0 选择半径大于等于5.0的圆

The following example selects circleswhose radius is greater than or equal to 5.0.

下面例子选择半径大于等于5.0的圆。

VB.NET

<CommandMethod("FilterRelational")>_

Public SubFilterRelational()

acTypValAr.SetValue(NewTypedValue(DxfCode.Operator,">="),255)"> acTypValAr.SetValue(New TypedValue(40,255)">[CommandMethod("FilterRelational")]

public static voidFilterRelational()

// 创建TypedValue来定义过滤条件

acTypValAr.SetValue(newTypedValue((int)DxfCode.Operator,255)"> acTypValAr.SetValue(new TypedValue(40,255)"> // 将过滤条件复制给SelectionFilter对象

// 提示栏OK,表示对象已选

}

VBA/ActiveX Code Reference

SubFilterRelational()

FilterType(0) = 0: FilterData(0) ="Circle"

FilterType(1) = -4: FilterData(1) =">="

FilterType(2) = 40: FilterData(2) = 5#

End Sub


Select either Text or MText 选择单行文字或多行文字

The following example specifies thateither Text or MText objects can be selected.

下面例子演示可以选择Text(单行文字)或者MText(多行文字)。

VB.NET

<CommandMethod("FilterForText")>_

Public SubFilterForText()

Dim acTypValAr(3) As TypedValue

acTypValAr.SetValue(New TypedValue(DxfCode.Start,"TEXT"),"MTEXT"),"or>"),3)

[CommandMethod("FilterForText")]

public static voidFilterForText()

// Get the current document editor

TypedValue[] acTypValAr = new TypedValue[4];

Sub FilterForText()

Dim FilterType(3) As Integer

Dim FilterData(3) As Variant

FilterType(0) = -4: FilterData(0) ="<or"

FilterType(1) = 0: FilterData(1) ="TEXT"

FilterType(2) = 0: FilterData(2) ="MTEXT"

FilterType(3) = -4: FilterData(3) ="or>"

End Sub

4.4、UseWild-Card Patterns in Selection Set Filter Criteria在过滤条件里使用通配

Symbol names and strings in selectionfilters can include wild-card patterns.

选择过滤器中的符号名字和字符串可以包含通配符。

The following table identifies thewild-card characters recognized by AutoCAD,and what each means in the contextof a string:

下表为AutoCAD能够识别的通配字符,及其在字符串上下文所代表的意义:

Use a reverse quote (`) to indicate that acharacter is not a wildcard,but is to be taken literally. For example,tospecify that only an anonymous block named “*U2” be included in the selectionset,use the value“`*U2”.

使用转义引号(’)表示一个字符不是通配符,应逐个字符使用。例如,要指定只将名为“*U2”的匿名块包含在选择集中,应使用值“’*U2”。


Select MText where a specific wordappears in the text 选择包含指定文字的MText

The following example defines a selectionfilter that selects MText objects that contain the text string of “The”.

下例定义一个选择过滤器,选择包含文字串“The”的MText对象。

VB.NET

<CommandMethod("FilterMtextWildcard")>_

Public SubFilterMtextWildcard()

Dim acTypValAr(1) As TypedValue

acTypValAr.SetValue(New TypedValue(DxfCode.Text,"*The*"),255)">using Autodesk.AutoCAD.DatabaseServices;

[CommandMethod("FilterMtextWildcard")]

public static voidFilterMtextWildcard()

TypedValue[] acTypValAr = new TypedValue[2];

acTypValAr.SetValue(newTypedValue((int)DxfCode.Text,255)">SubFilterMtextWildcard()

Dim FilterType(1) As Integer

Dim FilterData(1) As Variant

FilterData(0) = "MTEXT"

FilterType(1) = 1

FilterData(1) = "*The*"

End Sub

4.5、Filterfor Extended Data过滤扩展数据

External applications can attach data suchas text strings,numeric values,3D points,distances,and layer names to AutoCADobjects. This data is referred to as extended data,or xdata. You can filterentities containing extended data for a specified application.

外部应用程序可以向AutoCAD对象提供诸如文本串、数值、3D点、距离、图层名等数据。这些数据我们称之为扩展数据,或叫xdata。我们可以过滤含有指定外部程序扩展数据的实体。

Select circles that contain xdata 选择含有扩展数据的圆

The following example filters for circlescontaining xdata added by the “MY_APP” application:

下例多虑含有由程序“MY_APP”添加了扩展数据的圆。

VB.NET

<CommandMethod("FilterXdata")>_

Public SubFilterXdata()

acTypValAr.SetValue(NewTypedValue(DxfCode.ExtendedDataRegAppName,_

"MY_APP"),255)">[CommandMethod("FilterXdata")]

public static voidFilterXdata()

acTypValAr.SetValue(new TypedValue((int)DxfCode.Start,255)"> acTypValAr.SetValue(newTypedValue((int)DxfCode.ExtendedDataRegAppName,

SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);

Sub FilterXdata()

FilterType(1) = 1001: FilterData(1) ="MY_APP"

End Sub

5、Remove Objects From a Selection Set从选择集删除对象

After you create a selection set,you canwork with the object ids of the objects selected. Selection sets do not allowyou to add or remove object ids from it,but you can use an ObjectIdCollectionobject to merge multiple selection sets into a single object to work with. Youcan add and remove object ids from an ObjectIdCollection object. Use the Remove or RemoveAt methods to remove an object id from anObjectIdCollection object. For information on merging multiple selection setsand working with an ObjectIdCollection object,see AddTo or Merge Multiple Selection Sets.

创建选择集后,接下来就可以使用所选对象的id。选择集不允许从中添加删除对象id,不过我们可以用ObjectIdCollection对象将多个选择集合并为单个选择集使用。我们可以从ObjectIdCollection对象中添加删除对象id。从ObjectIdCollection对象中删除一个对象id,使用Remove方法或RemoveAt方法

关于合并多个选择集和使用ObjectIdCollection对象的更多内容,见“添加或合并多个选择集”。

猜你在找的VB相关文章