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

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

概述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 ob 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表示选择过滤器中的关系预算符类型。运算符本身用字符串表示。可用的关系运算符列表如下:

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表示,逻辑 *** 作符为字符串,且必须成对出现。 *** 作符开始于小于号(<),结束于大于号(>)。下表;列出了用于选择集过滤器的逻辑 *** 作符。

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对象的更多内容,见“添加或合并多个选择集”。

总结

以上是内存溢出为你收集整理的03-03 创建和编辑AutoCAD实体(三) 使用选择集(2)全部内容,希望文章能够帮你解决03-03 创建和编辑AutoCAD实体(三) 使用选择集(2)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1292065.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存