- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2005-1-6 19:19:00
|
显示全部楼层
<BR>Imports Autodesk.AutoCAD.ApplicationServices<BR>Imports Autodesk.AutoCAD.DatabaseServices<BR>Imports Autodesk.AutoCAD.Runtime<BR>Imports Autodesk.AutoCAD.Interop<BR>Imports Autodesk.AutoCAD.Interop.Common<BR>Imports Autodesk.AutoCAD.Geometry
Public Class TlsSelectionSet<BR> Private m_oSel As AcadSelectionSet<BR> Private m_vFilterType() As Short, m_vFilterData() As Object<BR> Private m_sName As String<BR> Private m_oApp As AcadApplication = Application.AcadApplication<BR> Private m_oDoc As AcadDocument
Public Sub NullFilter()<BR> '清空过滤器
m_vFilterType = Nothing<BR> m_vFilterData = Nothing
End Sub
Private Function IsNull() As Boolean
If m_oSel Is Nothing Then<BR> IsNull = True<BR> ElseIf m_oSel.Count = 0 Then<BR> IsNull = True<BR> Else<BR> IsNull = False<BR> End If
End Function<BR> Public Sub New()<BR> Me.New("TlsSel")<BR> End Sub
Public Sub New(ByVal Name As String)<BR> m_oDoc = m_oApp.ActiveDocument<BR> Init(Name)<BR> End Sub<BR> Public Sub Init(ByVal Name As String)<BR> '创建选择集
NullFilter()<BR> If Not m_oSel Is Nothing Then m_oSel.Delete()<BR> m_sName = Name<BR> Try<BR> m_oDoc.SelectionSets.Item(m_sName).Delete()<BR> Catch ex As Exception
End Try<BR> m_oSel = m_oDoc.SelectionSets.Add(m_sName)
End Sub
Protected Overrides Sub Finalize()<BR> MyBase.Finalize()<BR> If Not m_oSel Is Nothing Then m_oSel.Delete()<BR> End Sub
Public ReadOnly Property Count() As Integer<BR> '获取选择集实体个数<BR> Get<BR> Count = m_oSel.Count<BR> End Get<BR> End Property
Public ReadOnly Property Name() As String<BR> '获取选择集名称<BR> Get<BR> Name = m_sName<BR> End Get<BR> End Property
Public ReadOnly Property Item(ByVal Index) As AcadEntity<BR> '获取选择集实体<BR> Get<BR> Item = m_oSel.Item(Index)<BR> End Get<BR> End Property
Public Sub AddItem(ByVal obj As AcadEntity)<BR> '向选择集加入单个实体
Dim objs(0) As AcadEntity
objs(0) = obj<BR> m_oSel.AddItems(objs)
End Sub
Public Sub AddItem(ByVal objs As AcadEntity())<BR> '向选择集加入实体数组
m_oSel.AddItems(objs)
End Sub
Public Sub RemoveItem(ByVal obj As AcadEntity)<BR> '在选择集中移除单个实体
Dim objs(0) As AcadEntity<BR> objs(0) = obj<BR> m_oSel.RemoveItems(objs)
End Sub
<BR> Public Sub RemoveItem(ByVal objs As AcadEntity())<BR> '在选择集中移除实体数组
m_oSel.RemoveItems(objs)
End Sub
Public Sub Clear()<BR> '清空选择集
Select Case m_sName<BR> Case "ICKFIRST"<BR> GetPickfirstSelectionSet()<BR> Case "CURRENT"<BR> GetActiveSelectionSet()<BR> Case Else<BR> Init(m_sName)<BR> End Select
m_oSel.Clear()
End Sub
Public Sub Update()
m_oSel.Update()
End Sub
Public Sub GetPickfirstSelectionSet()<BR> '获取Pickfirst选择集
NullFilter()<BR> If Not m_oSel Is Nothing Then m_oSel.Delete()<BR> m_sName = "ICKFIRST"<BR> m_oDoc.SelectionSets.Item(m_sName).Delete()<BR> m_oSel = m_oDoc.PickfirstSelectionSet
End Sub
Public Sub GetActiveSelectionSet()<BR> '获取Active选择集<BR> On Error Resume Next
NullFilter()<BR> If Not m_oSel Is Nothing Then m_oSel.Delete()<BR> m_sName = "CURRENT"<BR> m_oDoc.SelectionSets.Item(m_sName).Delete()<BR> m_oSel = m_oDoc.ActiveSelectionSet
End Sub
Public Sub SetFilterType(ByVal ParamArray FilterType())<BR> '设置过滤器类型
Dim i<BR> Dim nCount As Short<BR> nCount = UBound(FilterType)<BR> ReDim m_vFilterType(nCount)
For i = 0 To nCount<BR> m_vFilterType(i) = FilterType(i)<BR> Next i
End Sub
Public Sub SetFilterData(ByVal ParamArray FilterData())<BR> '设置过滤器数据
Dim i<BR> Dim nCount As Integer<BR> nCount = UBound(FilterData)<BR> ReDim m_vFilterData(nCount)
For i = 0 To nCount<BR> m_vFilterData(i) = FilterData(i)<BR> Next i
End Sub
Public Sub SetFilter(ByVal ParamArray Filter())<BR> '设置过滤器
Dim i<BR> Dim n As Integer<BR> Dim nCount As Integer<BR> nCount = (UBound(Filter) + 1) / 2 - 1<BR> ReDim m_vFilterType(nCount), m_vFilterData(nCount)
For i = 0 To nCount<BR> n = i * 2<BR> m_vFilterType(i) = Filter(n)<BR> m_vFilterData(i) = Filter(n + 1)<BR> Next i
End Sub
<BR> Public Sub SelectObjectOnScreen()
If IsArray(m_vFilterType) Then<BR> m_oSel.SelectOnScreen(m_vFilterType, m_vFilterData)<BR> Else<BR> m_oSel.SelectOnScreen()<BR> End If
End Sub
Public Sub SelectObject(ByVal Mode As AcSelect, ByVal Point1 As Object, ByVal Point2 As Object)
If IsArray(m_vFilterType) Then<BR> m_oSel.Select(Mode, Point1, Point2, m_vFilterType, m_vFilterData)<BR> Else<BR> m_oSel.Select(Mode, Point1, Point2)<BR> End If
End Sub<BR> Public Sub SelectObject(ByVal Mode As AcSelect)
If IsArray(m_vFilterType) Then<BR> m_oSel.Select(Mode, , , m_vFilterType, m_vFilterData)<BR> Else<BR> m_oSel.Select(Mode)<BR> End If
End Sub
Public Sub SelectObjectAtPoint(ByVal Point)<BR> On Error Resume Next
If IsArray(m_vFilterType) Then<BR> m_oSel.SelectAtPoint(Point, m_vFilterType, m_vFilterData)<BR> Else<BR> m_oSel.SelectAtPoint(Point)<BR> End If
End Sub
Public Sub SelectObjectByPolygon(ByVal Mode As AcSelect, ByVal Points As Object)
If IsArray(m_vFilterType) Then<BR> m_oSel.SelectByPolygon(Mode, Points, m_vFilterType, m_vFilterData)<BR> Else<BR> m_oSel.SelectByPolygon(Mode, Points)<BR> End If
End Sub
Public WriteOnly Property Visible() As Boolean<BR> Set(ByVal Value As Boolean)<BR> If IsNull() Then Exit Property
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.Visible = Value<BR> Next i<BR> End Set<BR> End Property
<BR> Public WriteOnly Property Layer() As String<BR> Set(ByVal Value As String)
If IsNull() Then Exit Property
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.Layer = Value<BR> Next i<BR> End Set<BR> End Property
Public WriteOnly Property LineType() As String<BR> Set(ByVal Value As String)
If IsNull() Then Exit Property
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.Linetype = Value<BR> Next i<BR> End Set<BR> End Property
Public WriteOnly Property Color() As ACAD_COLOR<BR> Set(ByVal Value As ACAD_COLOR)
If IsNull() Then Exit Property
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.color = Value<BR> Next i<BR> End Set<BR> End Property
Public Sub Move(ByVal Point1 As Object, ByVal Point2 As Object)
If IsNull() Then Exit Sub
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.Move(Point1, Point2)<BR> Next i
End Sub
Public Function Copy(ByVal Point1 As Object, ByVal Point2 As Object) As AcadEntity()
If IsNull() Then Exit Function
Dim objs() As AcadEntity<BR> Dim i<BR> ReDim objs(Count - 1)
For i = 0 To Count<BR> objs(i) = m_oSel.Item(i).Copy<BR> objs(i).Move(Point1, Point2)<BR> Next i
Return objs
End Function
Public Sub Rotate(ByVal BasePoint As Object, Optional ByVal RotationAngle As Double = 1.0#)
If IsNull() Then Exit Sub
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.Rotate(BasePoint, RotationAngle)<BR> Next i
End Sub
Public Sub Rotate3D(ByVal Point1 As Object, ByVal Point2 As Object, Optional ByVal RotationAngle As Double = 1.0#)
If IsNull() Then Exit Sub
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.Rotate3D(Point1, Point2, RotationAngle)<BR> Next i
End Sub
Public Sub ScaleAll(ByVal BasePoint As Object, Optional ByVal ScaleFactor As Double = 1)
If IsNull() Then Exit Sub
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.ScaleEntity(BasePoint, ScaleFactor)<BR> Next i
End Sub
Public Sub Mirror(ByVal Point1 As Object, ByVal Point2 As Object)
If IsNull() Then Exit Sub
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.Mirror(Point1, Point2)<BR> Next i
End Sub
Public Sub Mirror3D(ByVal Point1 As Object, ByVal Point2 As Object, ByVal Point3 As Object)
If IsNull() Then Exit Sub
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.Mirror3D(Point1, Point2, Point3)<BR> Next i
End Sub
Public Sub Highlight(Optional ByVal HighlightFlag As Boolean = True)
Dim i As AcadEntity<BR> For Each i In m_oSel<BR> i.Highlight(HighlightFlag)<BR> Next i
End Sub
Public Sub Delete()
m_oSel.Erase()
End Sub
<BR> Public Sub CopyObjects(ByVal Owner As Object, ByVal IdPairs As Object)
If IsNull() Then Exit Sub
m_oDoc.CopyObjects(ToArray, Owner, IdPairs)
End Sub
Public Sub CopyObjects(ByVal Owner As Object)
If IsNull() Then Exit Sub
m_oDoc.CopyObjects(ToArray, Owner)
End Sub
Public Sub CopyObjects()
If IsNull() Then Exit Sub
m_oDoc.CopyObjects(ToArray)
End Sub
<BR> Public Function GetBoundingBox(ByRef MinPoint As Object, ByRef MaxPoint As Object) As Boolean
Dim i<BR> Dim d1, d2, p1, p2
If IsNull() Then Exit Function
m_oSel.Item(0).GetBoundingBox(d1, d2)
For i = 1 To Count - 1
m_oSel.Item(i).GetBoundingBox(p1, p2)
If p1(0) < d1(0) Then d1(0) = p1(0)<BR> If p1(1) < d1(1) Then d1(1) = p1(1)<BR> If p2(0) > d2(0) Then d2(0) = p2(0)<BR> If p2(1) > d2(1) Then d2(1) = p2(1)
Next i
MinPoint = d1<BR> MaxPoint = d2
End Function
Public Function ToBlock(ByVal InsertionPoint As Object, Optional ByVal Name As String = "*U") As String
If IsNull() Then Exit Function
Dim oBlock As AcadBlock<BR> oBlock = m_oDoc.Blocks.Add(InsertionPoint, Name)<BR> CopyObjects(oBlock)
Return oBlock.Name
End Function
Public Function ToSelectionSet() As AcadSelectionSet<BR> '获取选择集
Return m_oSel
End Function
Public Function ToArray()<BR> '转化选择集为对象数组输出
Dim i<BR> Dim objs() As AcadEntity<BR> Dim nCount As Integer
nCount = m_oSel.Count - 1<BR> ReDim objs(nCount)
For i = 0 To nCount<BR> objs(i) = m_oSel.Item(i)<BR> Next i
Return objs
End Function
Public Function ToObjectIdCollection() As ObjectIdCollection<BR> '转化选择集为对象数组输出<BR> Dim i<BR> Dim objId As ObjectId<BR> Dim objs As New ObjectIdCollection<BR> For i = 0 To m_oSel.Count - 1<BR> objId.OldId = m_oSel.Item(i).ObjectID<BR> objs.Add(objId)<BR> Next i
Return objs
End Function
<BR>End Class<BR> |
|