加载中…
个人资料
简单
简单
  • 博客等级:
  • 博客积分:0
  • 博客访问:10,688
  • 关注人气:71
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

CASS中,高程点Z值与高程注记匹配检查

(2008-06-17 16:31:11)
标签:

it

分类: 工作/开发方面

思路:

    高程点是一个块参照(Insert,BlockReference),先建立高程点的选择集,然后通过高程点的选择集内实体去建立高程注记选择集,然后判断高程注记是否与高程点的Z值相等,如果不相等,则假设高程注记是正确的,根据高程注记修改高程点的Z值,修改完毕后,并以高程点的X、Y,Z=0为圆心,5为半径,绘制圆,颜色为绿色,方便后期人工复查。

 

具体代码如下:

Option Explicit

'判断高程点的Z值和高程注记是否匹配
'如果不匹配,则把高程注记的颜色变为绿色
Public Sub CheckGCD_Z()

  Zoom_Extent  '先执行全屏显示视图

  '定义绿色
  Dim CorGreen As AcadAcCmColor
  Set CorGreen = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.16")
  Call CorGreen.SetRGB(0, 255, 0)   '绿色

  '建立高程点的选择集
  Dim pGCDSelSet As AcadSelectionSet
  Set pGCDSelSet = CreateSelectionSet
 
  Dim pType As Variant
  Dim pData As Variant
  BuildFilter pType, pData, 0, "INSERT", 8, "GCD"
 
  pGCDSelSet.Select acSelectionSetAll, , , pType, pData
   
  Dim pInsertObj As AcadBlockReference
  '进行选择集循环
  For Each pInsertObj In pGCDSelSet
    Dim pInsertPt As Variant
    pInsertPt = pInsertObj.InsertionPoint
   
    Dim pGCDSelSet_Txt As AcadSelectionSet
    Set pGCDSelSet_Txt = CreateSelectionSet2
   
    Dim pType_Txt As Variant
    Dim pData_Txt As Variant
    BuildFilter pType_Txt, pData_Txt, 0, "Text", 8, "GCD"
   
    '定义选择范围的左下角、右上角
    Dim minExt(0 To 2) As Double
    Dim maxExt(0 To 2) As Double
    '范围为块参照插入点上下、左右各变化0.5米
    minExt(0) = pInsertPt(0) - 2.5: minExt(1) = pInsertPt(1) - 2.5: minExt(2) = 0
    maxExt(0) = pInsertPt(0) + 2.5: maxExt(1) = pInsertPt(1) + 2.5: maxExt(2) = 0
   
    pGCDSelSet_Txt.Select acSelectionSetCrossing, minExt, maxExt, pType_Txt, pData_Txt

    Dim pGCD_TxtObj As AcadText
    For Each pGCD_TxtObj In pGCDSelSet_Txt
      Dim pGCD_Z As String
      pGCD_Z = pGCD_TxtObj.TextString
     
      '如果高程注记与高程点的Z值不相等,
      '则把高程Z值修改为高程注记的值,且以高程点为圆心,
      '绘制半径为5的圆
      If Val(pGCD_Z) <> Format(pInsertPt(2), "0.00") Then
         pInsertPt(2) = Val(pGCD_Z)   '将注记赋给Z值
                  
         pInsertObj.InsertionPoint = pInsertPt  '重新修改插入点的值
        
         '绘制圆
         Dim pCircle As AcadCircle
         Dim pCentPt As Variant
         Dim pRadius As Integer
         pCentPt = pInsertPt
         pCentPt(2) = 0
         pRadius = 5
        
         Set pCircle = ThisDrawing.ModelSpace.AddCircle(pCentPt, pRadius)
         pCircle.TrueColor = CorGreen '颜色为绿色
      End If
     
    Next pGCD_TxtObj

  Next pInsertObj
 
  MsgBox "高程点Z值与高程注记匹配检查完毕!", vbInformation, "高程点Z值与高程注记匹配检查"
  ThisDrawing.Application.Update  '刷新
 
End Sub

'创建过滤器的函数
Public Sub BuildFilter(TypeArray, DataArray, ParamArray gCodes())
    Dim fType() As Integer, fData()
    Dim index As Long, i As Long
   
    index = LBound(gCodes) - 1
    For i = LBound(gCodes) To UBound(gCodes) Step 2
        index = index + 1
        ReDim Preserve fType(0 To index)
        ReDim Preserve fData(0 To index)
        fType(index) = CInt(gCodes(i))
        fData(index) = gCodes(i + 1)
    Next
    TypeArray = fType: DataArray = fData
   
End Sub
'创建空间选择集的函数
Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet

    Dim ss As AcadSelectionSet
    On Error Resume Next
    Set ss = ThisDrawing.SelectionSets(ssName)
    If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
    ss.Clear
    Set CreateSelectionSet = ss

End Function


'创建空间选择集的函数2
Public Function CreateSelectionSet2(Optional ssName As String = "ss2") As AcadSelectionSet

    Dim ss2 As AcadSelectionSet
    On Error Resume Next
    Set ss2 = ThisDrawing.SelectionSets(ssName)
    If Err Then Set ss2 = ThisDrawing.SelectionSets.Add(ssName)
    ss2.Clear
    Set CreateSelectionSet2 = ss2

End Function

'全图显示
Public Sub Zoom_Extent()
  ThisDrawing.Application.ZoomExtents
End Sub

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有