日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2024/3/24 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 03-03 创建和编辑AutoCAD实体(三) 使用选择集(2) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

4、DefineRules for Selection Filters定義選擇集過濾器規(guī)則

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.

我們可以通過使用選擇過濾器來限制哪些對象被選中并添加到選擇集。選擇過濾器列表用來通過屬性或類型過濾所選對象,例如,我們可能想只選擇藍(lán)色的對象或某一圖層上的對象。我們還可以使用選擇條件組合,例如,我們可以創(chuàng)建一個選擇過濾器將選擇對象限定于Pattern圖層上的藍(lán)色的圓??梢詾椤霸趫D形區(qū)域選擇對象”一節(jié)中的各種不同選擇方法指定選擇過濾器作為參數(shù)。

?

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.

注意:使用過濾只能識別顯式賦給對象的值,而不能識別繼承自圖層的那些值。比如,如果對象的線型屬性設(shè)置為隨圖層(ByLayer)而該圖層線型為Hidden,那么要過濾線型為Hidden的對象將不會選擇那些線型屬性為隨圖層(ByLayer)的對象。

?

Topics in this section本小節(jié)內(nèi)容

·??????Use Selection Filters to Define Selection Set Rules?使用選擇過濾器定義選擇集規(guī)則

·??????Specify Multiple Criteria in a Selection Filter?多個過濾條件

·??????Add Complexity to Your Filter List Conditions?復(fù)雜的過濾條件

·??????Use Wild-Card Patterns in Selection Set Filter Criteria?在過濾條件里使用通配符

·??????Filter for Extended Data?過濾擴展數(shù)據(jù)

?

4.1、UseSelection Filters to Define Selection Set Rules使用選擇過濾器定義選擇集規(guī)則

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形式的一對參數(shù)構(gòu)成。TypedValue的第一個參數(shù)表明過濾器的類型(例如對象),第二個參數(shù)為要過濾的值(例如圓)。過濾器類型是一個DXF組碼,用來指定使用哪種過濾器。一些常用過濾器類型列表如下。

?

?

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

DXF組碼的完整列表,見DXF參考手冊中組碼值類型一節(jié)

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.

下面程序提示用戶選擇對象放到選擇集內(nèi),然后過濾掉圓以外的其他所有對象。

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獲取當(dāng)前文檔編輯器

? Editor acDocEd =Application.DocumentManager.MdiActiveDocument.Editor;

?

? // Create a TypedValue array to define thefilter criteria

? // 創(chuàng)建一個TypedValue數(shù)組來定義過濾器條件

? TypedValue[] acTypValAr = new TypedValue[1];

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

?

? // Assign the filter criteria to aSelectionFilter object

? // 將過濾器條件賦值給SelectionFilter對象

? SelectionFilter acSelFtr = newSelectionFilter(acTypValAr);

?

? // Request for objects to be selected in thedrawing area

? // 請求用戶在圖形區(qū)域選擇對象

??PromptSelectionResult acSSPrompt;

? acSSPrompt = acDocEd.GetSelection(acSelFtr);

?

? // If the prompt status is OK, objects wereselected

? // 提示狀態(tài)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.

選擇過濾器可以包含過濾多個屬性或?qū)ο蟮臈l件。可以通過聲明一個包含足夠數(shù)量元素的數(shù)組來定義總的過濾條件,數(shù)組的每個元素代表一個過濾條件。

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

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

ImportsAutodesk.AutoCAD.EditorInput

?

<CommandMethod("FilterBlueCircleOnLayer0")>_

Public SubFilterBlueCircleOnLayer0()

? '' Get the current document editor

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

?

? '' Create a TypedValue array to define thefilter criteria

? Dim acTypValAr(2) As TypedValue

? acTypValAr.SetValue(NewTypedValue(DxfCode.Color, 5), 0)

? acTypValAr.SetValue(NewTypedValue(DxfCode.Start, "CIRCLE"), 1)

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

?

? '' Assign the filter criteria to a SelectionFilterobject

? 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("Numberof objects 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("FilterBlueCircleOnLayer0")]

public static voidFilterBlueCircleOnLayer0()

{

? // Get the current document editor獲取當(dāng)前文檔編輯器

? Editor acDocEd =Application.DocumentManager.MdiActiveDocument.Editor;

?

? // Create a TypedValue array to define thefilter criteria

? // 創(chuàng)建TypedValue數(shù)組定義過濾條件

? TypedValue[] acTypValAr = new TypedValue[3];

? acTypValAr.SetValue(new TypedValue((int)DxfCode.Color,5), 0);

? acTypValAr.SetValue(newTypedValue((int)DxfCode.Start, "CIRCLE"), 1);

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

?

? // Assign the filter criteria to aSelectionFilter object

? // 將過濾條件賦值給SelectionFilter對象

? SelectionFilter acSelFtr = newSelectionFilter(acTypValAr);

?

? // Request for objects to be selected in thedrawing area

? // 請求在圖形區(qū)域選擇對象

? PromptSelectionResult acSSPrompt;

? acSSPrompt = acDocEd.GetSelection(acSelFtr);

?

? // If the prompt status is OK, objects wereselected

? // 如果提示狀態(tài)OK,表示對象已選

? if (acSSPrompt.Status == PromptStatus.OK)

? {

????? SelectionSet acSSet = acSSPrompt.Value;

?

????? Application.ShowAlertDialog("Numberof objects selected: " +

????????????????????????????????? acSSet.Count.ToString());

? }

? else

? {

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

? }

}

VBA/ActiveX CodeReference

SubFilterBlueCircleOnLayer0()

??? Dim sset As AcadSelectionSet

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

?

??? ' Define the filter list, only blue Circleobjects

??? ' 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"

?

??? ' 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.3、AddComplexity to Your Filter List Conditions復(fù)雜的過濾條件

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

當(dāng)指定多個選擇條件時,AutoCAD假設(shè)所選對象必須滿足每個條件。我們還可以以別的方式搞定過濾條件。對于數(shù)值項,可以使用關(guān)系運算(比如,遠(yuǎn)的半徑必須大于等于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表示選擇過濾器中的關(guān)系預(yù)算符類型。運算符本身用字符串表示??捎玫年P(guān)系運算符列表如下:

?

Relational operators for selection set filter lists關(guān)系運算符列表

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)位與(僅限整數(shù)組)

"&="

Bitwise masked equals (integer groups only)位屏蔽等于(僅限整數(shù)組)

?

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表示,邏輯操作符為字符串,且必須成對出現(xiàn)。操作符開始于小于號(<),結(jié)束于大于號(>)。下表;列出了用于選擇集過濾器的邏輯操作符。

?

Logical grouping operators for selection set filter lists

Starting operator起始操作符

Encloses包括:

Ending operator結(jié)束操作符

"<AND"

One or more operands一個以上操作數(shù)

"AND>"

"<OR"

One or more operands一個以上操作數(shù)

"OR>"

"<XOR"

Two operands兩個操作數(shù)

"XOR>"

"<NOT"

One operand一個操作數(shù)

"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

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

ImportsAutodesk.AutoCAD.EditorInput

?

<CommandMethod("FilterRelational")>_

Public SubFilterRelational()

? '' Get the current document editor

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

?

? '' Create a TypedValue array to define thefilter criteria

? Dim acTypValAr(2) As TypedValue

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

? acTypValAr.SetValue(NewTypedValue(DxfCode.Operator, ">="), 1)

? acTypValAr.SetValue(New TypedValue(40, 5), 2)

?

? '' Assign the filter criteria to a SelectionFilterobject

? 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("Numberof objects 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("FilterRelational")]

public static voidFilterRelational()

{

? // Get the current document editor獲取當(dāng)前文檔編輯器

? Editor acDocEd =Application.DocumentManager.MdiActiveDocument.Editor;

?

? // Create a TypedValue array to define thefilter criteria

? // 創(chuàng)建TypedValue來定義過濾條件

? TypedValue[] acTypValAr = new TypedValue[3];

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

? acTypValAr.SetValue(newTypedValue((int)DxfCode.Operator, ">="), 1);

? acTypValAr.SetValue(new TypedValue(40, 5),2);

?

? // Assign the filter criteria to aSelectionFilter object

? // 將過濾條件復(fù)制給SelectionFilter對象

? SelectionFilter acSelFtr = newSelectionFilter(acTypValAr);

?

? // Request for objects to be selected in thedrawing area

? // 請求在圖形區(qū)域選擇對象

? PromptSelectionResult acSSPrompt;

? acSSPrompt = acDocEd.GetSelection(acSelFtr);

?

? // If the prompt status is OK, objects wereselected

? // 提示欄OK,表示對象已選

? if (acSSPrompt.Status == PromptStatus.OK)

? {

????? SelectionSet acSSet = acSSPrompt.Value;

?

????? Application.ShowAlertDialog("Numberof objects selected: " +

?????????????????????????????????acSSet.Count.ToString());

? }

? else

? {

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

? }

}

VBA/ActiveX Code Reference

SubFilterRelational()

??? Dim sset As AcadSelectionSet

??? Dim FilterType(2) As Integer

??? Dim FilterData(2) As Variant

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

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

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

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

?

??? sset.SelectOnScreen FilterType, FilterData

?

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

?

??? ' Remove the selection set at the end

??? sset.Delete

End Sub


Select either Text or MText 選擇單行文字或多行文字

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

下面例子演示可以選擇Text(單行文字)或者MText(多行文字)。

VB.NET

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

ImportsAutodesk.AutoCAD.EditorInput

?

<CommandMethod("FilterForText")>_

Public SubFilterForText()

? '' Get the current document editor

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

?

? '' Create a TypedValue array to define thefilter criteria

? Dim acTypValAr(3) As TypedValue

? acTypValAr.SetValue(NewTypedValue(DxfCode.Operator, "<or"), 0)

? acTypValAr.SetValue(New TypedValue(DxfCode.Start,"TEXT"), 1)

? acTypValAr.SetValue(NewTypedValue(DxfCode.Start, "MTEXT"), 2)

? acTypValAr.SetValue(NewTypedValue(DxfCode.Operator, "or>"), 3)

?

? '' 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("Numberof objects 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("FilterForText")]

public static voidFilterForText()

{

? // Get the current document editor

? Editor acDocEd =Application.DocumentManager.MdiActiveDocument.Editor;

?

? // Create a TypedValue array to define thefilter criteria

? TypedValue[] acTypValAr = new TypedValue[4];

? acTypValAr.SetValue(newTypedValue((int)DxfCode.Operator, "<or"), 0);

? acTypValAr.SetValue(newTypedValue((int)DxfCode.Start, "TEXT"), 1);

? acTypValAr.SetValue(newTypedValue((int)DxfCode.Start, "MTEXT"), 2);

? acTypValAr.SetValue(newTypedValue((int)DxfCode.Operator, "or>"), 3);

?

? // Assign the filter criteria to aSelectionFilter object

? 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, objects wereselected

? if (acSSPrompt.Status == PromptStatus.OK)

? {

????? SelectionSet acSSet = acSSPrompt.Value;

?

????? Application.ShowAlertDialog("Numberof objects selected: " +

??????? ??????????????????????????acSSet.Count.ToString());

? }

? else

? {

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

? }

}

VBA/ActiveX CodeReference

Sub FilterForText()

??? Dim sset As AcadSelectionSet

??? Dim FilterType(3) As Integer

??? Dim FilterData(3) As Variant

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

?

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

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

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

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

?

??? sset.SelectOnScreen FilterType, FilterData

?

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

?

??? ' Remove the selection set at the end

??? sset.Delete

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”.

使用轉(zhuǎn)義引號(’)表示一個字符不是通配符,應(yīng)逐個字符使用。例如,要指定只將名為“*U2”的匿名塊包含在選擇集中,應(yīng)使用值“’*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

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

ImportsAutodesk.AutoCAD.EditorInput

?

<CommandMethod("FilterMtextWildcard")>_

Public SubFilterMtextWildcard()

? '' Get the current document editor

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

?

? '' Create a TypedValue array to define thefilter criteria

? Dim acTypValAr(1) As TypedValue

? acTypValAr.SetValue(NewTypedValue(DxfCode.Start, "MTEXT"), 0)

? acTypValAr.SetValue(New TypedValue(DxfCode.Text,"*The*"), 1)

?

? '' 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("Numberof objects selected: " & _

?????????????????????????????????acSSet.Count.ToString())

? Else

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

? End If

End Sub

C#

usingAutodesk.AutoCAD.Runtime;

usingAutodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

usingAutodesk.AutoCAD.EditorInput;

?

[CommandMethod("FilterMtextWildcard")]

public static voidFilterMtextWildcard()

{

? // Get the current document editor

? Editor acDocEd =Application.DocumentManager.MdiActiveDocument.Editor;

?

? // Create a TypedValue array to define thefilter criteria

? TypedValue[] acTypValAr = new TypedValue[2];

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

? acTypValAr.SetValue(newTypedValue((int)DxfCode.Text, "*The*"), 1);

?

? // Assign the filter criteria to aSelectionFilter object

? 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, objects wereselected

? if (acSSPrompt.Status == PromptStatus.OK)

? {

????? SelectionSet acSSet = acSSPrompt.Value;

?

????? Application.ShowAlertDialog("Numberof objects selected: " +

??????????????????? ??????????????acSSet.Count.ToString());

? }

? else

? {

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

? }

}

VBA/ActiveX Code Reference

SubFilterMtextWildcard()

??? Dim sset As AcadSelectionSet

??? Dim FilterType(1) As Integer

??? Dim FilterData(1) As Variant

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

?

??? FilterType(0) = 0

??? FilterData(0) = "MTEXT"

??? FilterType(1) = 1

??? FilterData(1) = "*The*"

?

??? sset.SelectOnScreen FilterType, FilterData

?

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

?

??? ' Remove the selection set at the end

??? sset.Delete

End Sub

?

4.5、Filterfor Extended Data過濾擴展數(shù)據(jù)

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.

外部應(yīng)用程序可以向AutoCAD對象提供諸如文本串、數(shù)值、3D點、距離、圖層名等數(shù)據(jù)。這些數(shù)據(jù)我們稱之為擴展數(shù)據(jù),或叫xdata。我們可以過濾含有指定外部程序擴展數(shù)據(jù)的實體。

Select circles that contain xdata 選擇含有擴展數(shù)據(jù)的圓

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

下例多慮含有由程序“MY_APP”添加了擴展數(shù)據(jù)的圓。

VB.NET

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

ImportsAutodesk.AutoCAD.EditorInput

?

<CommandMethod("FilterXdata")>_

Public SubFilterXdata()

? '' Get the current document editor

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

?

? '' Create a TypedValue array to define thefilter criteria

? Dim acTypValAr(1) As TypedValue

? acTypValAr.SetValue(NewTypedValue(DxfCode.Start, "Circle"), 0)

? acTypValAr.SetValue(NewTypedValue(DxfCode.ExtendedDataRegAppName, _

????????????????????????????????????"MY_APP"), 1)

?

? '' 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("Numberof objects 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("FilterXdata")]

public static voidFilterXdata()

{

? // Get the current document editor

? Editor acDocEd =Application.DocumentManager.MdiActiveDocument.Editor;

?

? // Create a TypedValue array to define thefilter criteria

? TypedValue[] acTypValAr = new TypedValue[2];

? acTypValAr.SetValue(new TypedValue((int)DxfCode.Start,"Circle"), 0);

? acTypValAr.SetValue(newTypedValue((int)DxfCode.ExtendedDataRegAppName,

????????????????????????????????????"MY_APP"), 1);

?

? // Assign the filter criteria to aSelectionFilter object

? SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);

?

? // Request for objects to be selected in thedrawing area

? PromptSelectionResult acSSPrompt;

? acSSPrompt = acDocEd.GetSelection(acSelFtr);

?

? // If the prompt status is OK, objects wereselected

? if (acSSPrompt.Status == PromptStatus.OK)

? {

????? SelectionSet acSSet = acSSPrompt.Value;

?

????? Application.ShowAlertDialog("Numberof objects selected: " +

?????????????????????????????????acSSet.Count.ToString());

? }

? else

? {

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

? }

}

VBA/ActiveX Code Reference

Sub FilterXdata()

??? Dim sset As AcadSelectionSet

??? Dim FilterType(1) As Integer

??? Dim FilterData(1) As Variant

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

?

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

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

?

??? sset.SelectOnScreen FilterType, FilterData

?

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

?

??? ' Remove the selection set at the end

??? sset.Delete

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.

創(chuàng)建選擇集后,接下來就可以使用所選對象的id。選擇集不允許從中添加或刪除對象id,不過我們可以用ObjectIdCollection對象將多個選擇集合并為單個選擇集使用。我們可以從ObjectIdCollection對象中添加或刪除對象id。從ObjectIdCollection對象中刪除一個對象id,使用Remove方法或RemoveAt方法。

關(guān)于合并多個選擇集和使用ObjectIdCollection對象的更多內(nèi)容,見“添加或合并多個選擇集”。

?

總結(jié)

以上是生活随笔為你收集整理的03-03 创建和编辑AutoCAD实体(三) 使用选择集(2)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。