- UID
 - 76071
 
- 积分
 - 1505
 
- 精华
 
- 贡献
 -  
 
- 威望
 -  
 
- 活跃度
 -  
 
- D豆
 -  
 
- 在线时间
 -  小时
 
- 注册时间
 - 2003-8-30
 
- 最后登录
 - 1970-1-1
 
 
 
 
 
 
 | 
 
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册 
 
 
 
 
×
 
  
- 'TlsSel类
 
 - 'By 雪山飞狐
 
 - '模块名---TlsSel
 
 - ' You may use the code included in this module in any way,
 
 - ' provided that both the above copyright notice and the
 
 - ' release of liability (stated below) appear in all copies.
 
 - Private oSel As AcadSelectionSet
 
 - Private TlsFt, TlsFd
 
 - Private sName As String
 
  
- Public Sub NullFilter()
 
 - '清空过滤器
 
 -     TlsFt = Null
 
 -     TlsFd = Null
 
  
- End Sub
 
  
- Private Function IsNull() As Boolean
 
  
-     If oSel Is Nothing Then
 
 -         IsNull = True
 
 -     ElseIf oSel.Count = 0 Then
 
 -         IsNull = True
 
 -     Else
 
 -         IsNull = False
 
 -     End If
 
 -     
 
 - End Function
 
  
- Public Sub Init(Optional ByVal Name As String = "TlsSel")
 
 - '创建选择集
 
 - On Error Resume Next
 
 -     
 
 -     NullFilter
 
 -     If Not oSel Is Nothing Then oSel.Delete
 
 -     sName = Name
 
 -     ThisDrawing.SelectionSets(sName).Delete
 
 -     Set oSel = ThisDrawing.SelectionSets.Add(sName)
 
 -     
 
 - End Sub
 
  
- Private Sub Class_Terminate()
 
 - '类析构时清除选择集
 
 - On Error Resume Next
 
 -     
 
 -     If Not oSel Is Nothing Then oSel.Delete
 
 -     
 
 - End Sub
 
  
- Public Function ToArray()
 
 - '转化选择集为对象数组输出
 
 - On Error Resume Next
 
 -   
 
 -     Dim i
 
 -     Dim objs() As AcadEntity
 
 -     Dim nCount As Integer
 
 -     
 
 -     nCount = oSel.Count - 1
 
 -     ReDim objs(nCount)
 
 -     
 
 -     For i = 0 To nCount
 
 -         Set objs(i) = oSel(i)
 
 -     Next i
 
 -     
 
 -     ToArray = objs
 
 -     
 
 - End Function
 
  
- Public Property Get Count() As Integer
 
 - '获取选择集实体个数
 
 - On Error Resume Next
 
  
-     Count = oSel.Count
 
 -     
 
 - End Property
 
  
- Public Property Get Name() As String
 
 - '获取选择集名称
 
 - On Error Resume Next
 
  
-     Name = sName
 
 -     
 
 - End Property
 
  
 
- Public Property Get Item(ByVal Index) As AcadEntity
 
 - '获取选择集实体
 
 - On Error Resume Next
 
  
-     Set Item = oSel(Index)
 
 -     
 
 - End Property
 
  
- Public Sub Add(ByVal obj)
 
 - '向选择集加入单个实体
 
 - On Error Resume Next
 
 -     
 
 -     Dim objs(0) As AcadEntity
 
 -     
 
 -     Set objs(0) = obj
 
 -     oSel.AddItems pbjs
 
 -     
 
 - End Sub
 
  
- Public Sub AddItems(ByVal objs)
 
 - '向选择集加入实体数组
 
 - On Error Resume Next
 
 -     
 
 -     oSel.AddItems objs
 
 -     
 
 - End Sub
 
  
- Public Sub Remove(ByVal obj)
 
 - '在选择集中移除单个实体
 
 - On Error Resume Next
 
 -     
 
 -     Dim objs(0) As AcadEntity
 
 -     Set objs(0) = obj
 
 -     oSel.RemoveItems objs
 
 -     
 
 - End Sub
 
  
 
- Public Sub RemoveItems(ByVal objs)
 
 - '在选择集中移除实体数组
 
 - On Error Resume Next
 
 -     
 
 -     oSel.RemoveItems objs
 
 -     
 
 - End Sub
 
  
- Public Sub Clear()
 
 - '清空选择集
 
 - On Error Resume Next
 
 -     
 
 -     Select Case sName
 
 -     Case "PICKFIRST"
 
 -         GetPickfirstSel
 
 -     Case "CURRENT"
 
 -         GetActiveSel
 
 -     Case Else
 
 -         Init sName
 
 -     End Select
 
 -     
 
 -     oSel.Clear
 
 -     
 
 - End Sub
 
  
- Public Sub Update()
 
 - On Error Resume Next
 
 -     
 
 -     oSel.Update
 
  
- End Sub
 
  
- Public Function GetSel() As AcadSelectionSet
 
 - '获取选择集
 
 - On Error Resume Next
 
 -     
 
 -     Set GetSel = oSel
 
 -     
 
 - End Function
 
  
- Public Sub GetPickfirstSel()
 
 - '获取Pickfirst选择集
 
 - On Error Resume Next
 
 -         
 
 -     NullFilter
 
 -     If Not oSel Is Nothing Then oSel.Delete
 
 -     sName = "PICKFIRST"
 
 -     ThisDrawing.SelectionSets(sName).Delete
 
 -     Set oSel = ThisDrawing.PickfirstSelectionSet
 
 -     
 
 - End Sub
 
  
- Public Sub GetActiveSel()
 
 - '获取Active选择集
 
 - On Error Resume Next
 
 -         
 
 -     NullFilter
 
 -     If Not oSel Is Nothing Then oSel.Delete
 
 -     sName = "CURRENT"
 
 -     ThisDrawing.SelectionSets(sName).Delete
 
 -     Set oSel = ThisDrawing.ActiveSelectionSet
 
 -     
 
 - End Sub
 
  
- Public Sub SetFilterType(ParamArray FilterType())
 
 - '设置过滤器类型
 
 - On Error Resume Next
 
 -     
 
 -     Dim i
 
 -     Dim nCount As Integer
 
 -     nCount = UBound(FilterType)
 
 -     
 
 -     Dim ft() As Integer
 
 -     ReDim ft(nCount)
 
 -     
 
 -     For i = 0 To nCount
 
 -         ft(i) = FilterType(i)
 
 -     Next i
 
 -     
 
 -     TlsFt = ft
 
 -     
 
 - End Sub
 
  
- Public Sub SetFilterData(ParamArray FilterData())
 
 - '设置过滤器数据
 
 - On Error Resume Next
 
  
-     Dim i
 
 -     Dim nCount As Integer
 
 -     nCount = UBound(FilterData)
 
 -     
 
 -     Dim fd()
 
 -     ReDim fd(nCount)
 
 -     
 
 -     For i = 0 To nCount
 
 -         fd(i) = FilterData(i)
 
 -     Next i
 
 -     
 
 -     TlsFd = fd
 
 -     
 
 - End Sub
 
  
- Public Sub SetFilter(ParamArray Filter())
 
 - '设置过滤器
 
 - On Error Resume Next
 
 -     
 
 -     Dim i
 
 -     Dim n As Integer
 
 -     Dim nCount As Integer
 
 -     nCount = (UBound(Filter) + 1) / 2 - 1
 
 -     
 
 -     Dim ft() As Integer, fd()
 
 -     ReDim ft(nCount), fd(nCount)
 
 -     
 
 -     For i = 0 To nCount
 
 -         n = i * 2
 
 -         ft(i) = Filter(n)
 
 -         fd(i) = Filter(n + 1)
 
 -     Next i
 
 -     
 
 -     TlsFt = ft
 
 -     TlsFd = fd
 
  
- End Sub
 
  
 
- Public Sub SelectObjectOnScreen()
 
 - On Error Resume Next
 
 -         
 
 -     If IsArray(TlsFt) Then
 
 -         oSel.SelectOnScreen TlsFt, TlsFd
 
 -     Else
 
 -         oSel.SelectOnScreen
 
 -     End If
 
 -     
 
 - End Sub
 
  
- Public Sub Selectobject(ByVal Mode As AcSelect, Optional ByVal Point1, Optional ByVal Point2)
 
 - On Error Resume Next
 
 -         
 
 -     If IsArray(TlsFt) Then
 
 -         If IsMissing(Point1) Then
 
 -             oSel.Select Mode, , , TlsFt, TlsFd
 
 -         Else
 
 -             oSel.Select Mode, Point1, Point2, TlsFt, TlsFd
 
 -         End If
 
 -     Else
 
 -         If IsMissing(Point1) Then
 
 -             oSel.Select Mode
 
 -         Else
 
 -             oSel.Select Mode, Point1, Point2
 
 -         End If
 
 -     End If
 
 -     
 
 - End Sub
 
  
- Public Sub SelectObjectAtPoint(ByVal Point)
 
 - On Error Resume Next
 
 -         
 
 -     If IsArray(TlsFt) Then
 
 -         oSel.SelectAtPoint Point, TlsFt, TlsFd
 
 -     Else
 
 -         oSel.SelectAtPoint Point
 
 -     End If
 
 -     
 
 - End Sub
 
  
- Public Sub SelectObjectByPolygon(ByVal Mode As AcSelect, Optional ByVal Points, Optional ByVal Point2)
 
 - On Error Resume Next
 
 -         
 
 -     If IsArray(TlsFt) Then
 
 -         oSel.SelectByPolygon Mode, Points, TlsFt, TlsFd
 
 -     Else
 
 -         oSel.SelectByPolygon Mode, Points
 
 -     End If
 
 -     
 
 - End Sub
 
  
- Public Property Let Visible(ByVal Value As Boolean)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Property
 
 -     
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.Visible = Value
 
 -     Next i
 
 -     
 
 - End Property
 
  
 
- Public Property Let Layer(ByVal Value As String)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Property
 
 -     
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.Layer = Value
 
 -     Next i
 
 -     
 
 - End Property
 
  
- Public Property Let LineType(ByVal Value As String)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Property
 
 -     
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.LineType = Value
 
 -     Next i
 
 -     
 
 - End Property
 
  
- Public Property Let Color(ByVal Value As ACAD_COLOR)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Property
 
 -     
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.Color = Value
 
 -     Next i
 
 -     
 
 - End Property
 
  
- Public Sub Move(Optional ByVal Point1, Optional ByVal Point2)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Sub
 
 -     If IsMissing(Point1) Then Point1 = CreatePoint()
 
 -     If IsMissing(Point2) Then Point2 = CreatePoint()
 
 -     
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.Move Point1, Point2
 
 -     Next i
 
 -     
 
 - End Sub
 
  
- Public Function Copy(Optional ByVal Point1, Optional ByVal Point2)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Sub
 
 -     If IsMissing(Point1) Then Point1 = CreatePoint()
 
 -     If IsMissing(Point2) Then Point2 = CreatePoint()
 
 -     
 
 -     Dim objs() As AcadEntity
 
 -     Dim i
 
 -     ReDim objs(Count - 1)
 
 -     
 
 -     For i = 0 To Count
 
 -         Set objs(i) = oSel(i).Copy
 
 -         objs(i).Move Point1, Point2
 
 -     Next i
 
 -     
 
 -     Copy = objs
 
 -     
 
 - End Function
 
  
- Public Sub Rotate(Optional ByVal BasePoint, Optional ByVal RotationAngle As Double = 1#)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Sub
 
 -     If IsMissing(BasePoint) Then BasePoint = CreatePoint()
 
 -         
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.Rotate BasePoint, RotationAngle
 
 -     Next i
 
  
- End Sub
 
  
- Public Sub Rotate3D(Optional ByVal Point1, Optional ByVal Point2, Optional ByVal RotationAngle As Double = 1#)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Sub
 
 -     If IsMissing(Point1) Then Point1 = CreatePoint()
 
 -     If IsMissing(Point2) Then Point2 = CreatePoint()
 
 -     
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.Rotate3D Point1, Point2, RotationAngle
 
 -     Next i
 
  
- End Sub
 
  
- Public Sub ScaleAll(Optional ByVal BasePoint, Optional ByVal scalefactor As Double = 1)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Sub
 
 -     If IsMissing(BasePoint) Then BasePoint = CreatePoint()
 
 -     
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.ScaleEntity BasePoint, scalefactor
 
 -     Next i
 
  
- End Sub
 
  
- Public Sub Mirror(Optional ByVal Point1, Optional ByVal Point2)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Sub
 
 -     If IsMissing(Point1) Then Point1 = CreatePoint()
 
 -     If IsMissing(Point2) Then Point2 = CreatePoint()
 
 -     
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.Mirror Point1, Point2
 
 -     Next i
 
  
- End Sub
 
  
- Public Sub Mirror3D(Optional ByVal Point1, Optional ByVal Point2, Optional ByVal Point3)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Sub
 
 -     If IsMissing(Point1) Then Point1 = CreatePoint()
 
 -     If IsMissing(Point2) Then Point2 = CreatePoint()
 
 -     If IsMissing(Point3) Then Point3 = CreatePoint()
 
 -     
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.Mirror3D Point1, Point2, Point3
 
 -     Next i
 
  
- End Sub
 
  
- Public Sub Highlight(Optional ByVal HighlightFlag As Boolean = True)
 
 - On Error Resume Next
 
 -     
 
 -     Dim i As AcadEntity
 
 -     For Each i In oSel
 
 -         i.Highlight HighlightFlag
 
 -     Next i
 
  
- End Sub
 
  
- Public Sub Delete()
 
 - On Error Resume Next
 
 -     
 
 -     oSel.Erase
 
  
- End Sub
 
  
 
- Public Sub CopyObjects(Optional ByVal Owner, Optional ByVal IdPairs)
 
 - On Error Resume Next
 
  
-     If IsNull() Then Exit Sub
 
  
-     If IsMissing(Owner) Then
 
 -         If IsMissing(IdPairs) Then
 
 -             ThisDrawing.CopyObjects ToArray
 
 -         Else
 
 -             ThisDrawing.CopyObjects ToArray, , IdPairs
 
 -         End If
 
 -     Else
 
 -         If IsMissing(IdPairs) Then
 
 -             ThisDrawing.CopyObjects ToArray, Owner
 
 -         Else
 
 -             ThisDrawing.CopyObjects ToArray, Owner, IdPairs
 
 -         End If
 
 -     End If
 
  
- End Sub
 
  
- Public Sub GetBoundingBox(ByRef MinPoint, ByRef MaxPoint)
 
 - On Error Resume Next
 
  
-     Dim i
 
 -     Dim d1, d2, p1, p2
 
 -     
 
 -     If IsNull() Then Exit Sub
 
 -     
 
 -     oSel(0).GetBoundingBox d1, d2
 
 -     
 
 -     For i = 1 To Count - 1
 
 -     
 
 -         oSel(i).GetBoundingBox p1, p2
 
 -         
 
 -         If p1(0) < d1(0) Then d1(0) = p1(0)
 
 -         If p1(1) < d1(1) Then d1(1) = p1(1)
 
 -         If p2(0) > d2(0) Then d2(0) = p2(0)
 
 -         If p2(1) > d2(1) Then d2(1) = p2(1)
 
 -         
 
 -     Next i
 
 -     
 
 -     MinPoint = d1
 
 -     MaxPoint = d2
 
 -     
 
 - End Sub
 
  
- Public Function ToBlock(Optional ByVal InsertionPoint, Optional ByVal Name As String = "*U") As String
 
 - On Error GoTo ErrHandle
 
  
-     If IsNull() Then Exit Function
 
 -     If IsMissing(InsertionPoint) Then InsertionPoint = CreatePoint()
 
 -     
 
 -     Dim oBlock As AcadBlock
 
 -     Set oBlock = ThisDrawing.Blocks.Add(InsertionPoint, Name)
 
 -     CopyObjects oBlock
 
 -     
 
 -     ToBlock = oBlock.Name
 
 -     
 
 - ErrHandle:
 
  
- End Function
 
  
- Function CreateArray(ByVal TypeName As VbVarType, ParamArray ValArray())
 
 -     Dim nCount As Integer
 
 -     Dim i
 
 -     Dim mArray
 
 -     
 
 -     nCount = UBound(ValArray)
 
 -     
 
 -     Select Case TypeName
 
 -     Case vbDouble
 
 -         Dim dArray() As Double
 
 -         ReDim dArray(nCount)
 
 -         mArray = dArray
 
 -     Case vbInteger
 
 -         Dim nArray() As Integer
 
 -         ReDim nArray(nCount)
 
 -         mArray = nArray
 
 -     Case vbString
 
 -         Dim sArray() As String
 
 -         ReDim sArray(nCount)
 
 -         mArray = sArray
 
 -     Case vbVariant
 
 -         Dim vArray()
 
 -         ReDim vArray(nCount)
 
 -         mArray = vArray
 
 -     End Select
 
 -     
 
 -     For i = 0 To nCount
 
 -         mArray(i) = ValArray(i)
 
 -     Next i
 
 -     
 
 -     CreateArray = mArray
 
 - End Function
 
  
- Public Function CreatePoint(Optional ByVal X As Double = 0#, Optional ByVal Y As Double = 0#, Optional ByVal Z As Double = 0#)
 
 -     
 
 -     Dim pnt(2) As Double
 
 -     pnt(0) = X: pnt(1) = Y: pnt(2) = Z
 
 -     
 
 -     CreatePoint = pnt
 
 -     
 
 - End Function
 
  
  |   
 
 
 
 |