路边 发表于 2005-8-17 08:24:00

用VBA怎样选择一个图层的所有内容??

用VBA怎样选择一个图层的所有内容??请高手给个具体例子!!

wubohan84 发表于 2009-2-7 12:10:00

我也正想解决这个问题呢。。。<div><br/></div>

rjh2001r 发表于 2009-2-7 23:44:00

<p>'****************创建带过滤器的选择集Start******************"</p><p>'创建过滤集<br/>Public Sub BuildFilter(ByRef TypeArray, ByRef DataArray, ByRef gCodes() As Variant)<br/>&nbsp;&nbsp;&nbsp; Dim fType() As Integer, fData()<br/>&nbsp;&nbsp;&nbsp; Dim index As Long, i As Long<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; index = LBound(gCodes) - 1<br/>&nbsp;&nbsp;&nbsp; For i = LBound(gCodes) To UBound(gCodes) Step 2<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; index = index + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim Preserve fType(0 To index)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim Preserve fData(0 To index)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fType(index) = CInt(gCodes(i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fData(index) = gCodes(i + 1)<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; TypeArray = fType: DataArray = fData<br/>&nbsp;&nbsp; <br/>End Sub</p><p>'功能:创建选择集<br/>Public Function CreateSelectionSet(Optional ByVal ssName As String = "ss") As AcadSelectionSet</p><p>&nbsp;&nbsp;&nbsp; Dim ss As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; Set ss = ThisDrawing.SelectionSets(ssName)<br/>&nbsp;&nbsp;&nbsp; If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)<br/>&nbsp;&nbsp;&nbsp; ss.Clear<br/>&nbsp;&nbsp;&nbsp; Set CreateSelectionSet = ss</p><p>End Function<br/>&nbsp;<br/>&nbsp; 'ParamArray定义的的数组在SUB内不能再做为实参传递<br/>Public Sub BuildFilterAndCteSset(sset, ssName, ParamArray gCodes())<br/>&nbsp; '定义过滤器<br/>&nbsp; Dim pType, pData<br/>&nbsp; Dim codes() As Variant<br/>&nbsp; <br/>&nbsp; codes = gCodes<br/>&nbsp; BuildFilter pType, pData, codes<br/>&nbsp;<br/>&nbsp; '定义选择集<br/>&nbsp; Set sset = CreateSelectionSet(ssName)<br/>&nbsp;<br/>&nbsp; '根据以上指定的过滤器建立选择集<br/>&nbsp; sset.Clear<br/>&nbsp; sset.Select acSelectionSetAll, , , pType, pData<br/>&nbsp; '这里可以通过Select、SelectAtPoint、SelectByPolygon、SelectOnScreen等方法<br/>&nbsp; '配合Mode和Point1、Point2建立更加用户化的选择集<br/>&nbsp;<br/>End Sub<br/>'********************创建带过滤集的选择集end********************"</p><p>'应用实例</p><p>'通过在CAD命令行输入:(entget(car(entsel)))获取的对象基本特性</p><p>Public Sub LayerSS()<br/>&nbsp;&nbsp;&nbsp; Dim sset As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; BuildFilterAndCteSset sset, "ss", 8, "层名"&nbsp;&nbsp; <br/>End Sub</p>
页: [1]
查看完整版本: 用VBA怎样选择一个图层的所有内容??