二、选择操作先在图中画些图形,运行下方代码
- Sub 画两个圆做例子()
- Dim doct As Object
- Set doct = doc '引用之前函数,自己去找
- If doct Is Nothing Then Exit Sub
- Dim pt(0 To 2) As Double
- pt(0) = 0
- pt(1) = 0
- pt(2) = 0
- Rad = 30
- Set Circl = doct.ModelSpace.AddCircle(pt, Rad)
- pt(0) = 50
- pt(1) = 50
- pt(2) = 0
- Rad = 30
- Set Circl = doct.ModelSpace.AddCircle(pt, Rad)
- pt(0) = 200
- pt(1) = 200
- pt(2) = 0
- Rad = 30
- Set Circl = doct.ModelSpace.AddCircle(pt, Rad)
- End Sub
复制代码 画完再看后边
- Sub 选择集选择操作1() 'Select方法选择
- Dim doct As AcadDocument
- Set doct = doc
- If doct Is Nothing Then Exit Sub
- Dim S As AcadSelectionSet
- Set S = AddSelect(doct, "SL") '创建选择集
-
- S.Select acSelectionSetAll '选择全部
- Dim pt1(2) As Double, pt2(2) As Double
- pt1(0) = 0: pt1(1) = 0: pt1(2) = 0
- pt2(0) = 100: pt2(1) = 100: pt2(2) = 0
- S.Clear
- S.Select acSelectionSetCrossing, pt1, pt2 '矩形窗交选择(矩形包含和相交的图形)
- S.Clear
- S.Select acSelectionSetWindow, pt1, pt2 '矩形窗口选择(只有矩形包含的图形)
- S.Clear
- S.Select acSelectionSetLast '最后一个生成的图形选择
- S.Clear
- S.Select acSelectionSetPrevious '上一次选择
-
- S.Delete '删除选择集
- End Sub
复制代码 Select方法:Select Mode [, Point1] [, Point2] [, FilterType] [, FilterData]
Mode:选择模式常量
acSelectionSetWindow'矩形窗口选择 acSelectionSetCrossing'矩形窗交选择 acSelectionSetPrevious'上一次选择 acSelectionSetLast '最后一个生成的图形选择 acSelectionSetAll '选择全部 窗交与窗口的区别是,窗交会把窗口相交的图形也选择进去。 当窗交或窗口选择时需要提供矩形两个角点参数[, Point1][, Point2],参数是双精度一维三元素数组 [, FilterType][, FilterData]:选择集过滤参数,此参数以后单独讲 - Sub 选择集选择操作2() 'SelectByPolygon多边形方法选择
- Dim doct As AcadDocument
- Set doct = doc
- If doct Is Nothing Then Exit Sub
-
- Dim S As AcadSelectionSet
- Set S = AddSelect(doct, "SL") '创建选择集
- Dim pt3(8) As Double
- pt3(0) = 0: pt3(1) = 0: pt3(2) = 0
- pt3(3) = 100: pt3(4) = 0: pt3(5) = 0
- pt3(6) = 0: pt3(7) = 100: pt3(8) = 0
- S.SelectByPolygon acSelectionSetCrossingPolygon, pt3 '多边形窗交选择(多边形包含和相交的图形)
- S.Clear
- S.SelectByPolygon acSelectionSetWindowPolygon, pt3 '多边形窗口选择(只有多边形包含的图形)
- S.Clear
- S.SelectByPolygon acSelectionSetFence, pt3 '栅选(点组成多段线相交的图形)
-
- S.Delete '删除选择集
- End Sub
复制代码SelectByPolygon方法:Mode, PointsList [, FilterType] [, FilterData] Mode:选择模式常量
acSelectionSetFence'栅选 acSelectionSetWindowPolygon'多边形窗口选择 acSelectionSetCrossingPolygon '多边形窗交选择 PointsList:组成多边形的点数组,参照不优化多段线数组 [, FilterType] [, FilterData]:忽略 注意:当窗交或窗口选择时多段线点自动封闭处理,定义的多边形不能自身相交。 当栅选是多段线不自动封闭,只选择与多段线相交的图形。 - Sub 选择集选择操作3() 'SelectAtPoint指定点方法选择
- Dim doct As AcadDocument
- Set doct = doc
- If doct Is Nothing Then Exit Sub
-
- Dim S As AcadSelectionSet
- Set S = AddSelect(doct, "SL") '创建选择集
-
- Dim pt1(2) As Double
- pt1(0) = 30: pt1(1) = 0: pt1(2) = 0
- S.SelectAtPoint pt1 '经过点的图形
-
- S.Delete '删除选择集
- End Sub
复制代码SelectAtPoint方法:选择经过点的图形(不是所有经过的都被选择,只选择最上层的一个图形) 参数Point [, FilterType] [, FilterData] Point:三维坐标点(一维三元素双精度数组) [, FilterType] [, FilterData]忽略 - Sub 选择集选择操作4() '通过用户选择
- Dim doct As AcadDocument
- Set doct = doc
- If doct Is Nothing Then Exit Sub
-
- Dim S As AcadSelectionSet
- Set S = AddSelect(doct, "SL") '创建选择集
- S.SelectOnScreen '切换到CAD进行手动选择
-
- S.Delete '删除选择集
- End Sub
复制代码SelectOnScreen方法:[, FilterType] [, FilterData] 只有两个可选参数[, FilterType] [, FilterData]先忽略 SelectOnScreen方法会暂时挂起,等待用户去CAD界面手动选择后把选择的图形添加到选择集。
|