当前版块:问答社区 > CASS

[CASS二次开发源代码]VB6+AutoCAD---图元扩展数据

Windows10
其他
CASS9
'检查实体是否存在扩展数据
Public Function HasXData(objEnt As AcadEntity, strAppName As String) As Boolean
  Dim DataType As Variant, DataValue As Variant
  objEnt.GetXData strAppName, DataType, DataValue
  If IsEmpty(DataType) Then
     HasXData = False
  Else
     HasXData = True
  End If
End Function
'读取扩展数据
Public Function GetCode(objEnt As AcadEntity, strAppName As String) As Variant
  Dim DataType As Variant, DataVaue As Variant, i As Integer
  If HasXData(objEnt, strAppName) = False Then
     GetCode = ""
  Else
     objEnt.GetXData strAppName, DataType, DataValue
     For i = LBound(DataType) To UBound(DataType)
         If DataType(i) = 1000 Then GetCode = DataValue(i): Exit For
     Next i
  End If
End Function
'设置扩展数据
Public Function SetCode(objEnt As AcadEntity, strAppName As String, strDataValue As String)
    Dim DataType(0 To 1) As Integer
    Dim DataValue(0 To 1) As Variant
    DataType(0) = 1001: DataValue(0) = strAppName
    DataType(1) = 1000: DataValue(1) = strDataValue
    objEnt.SetXData DataType, DataValue
End Function
'删除绑定图元的扩展数据
Public Sub ClearXData(Obj As AcadObject, Optional RegApp As String = "")
    Const regAppKey As Integer = 1001
    Const acadApp As String = "ACAD"
    Dim XDType As Variant
    Dim XDData As Variant
    Dim NewType(0) As Integer
    Dim NewData(0) As Variant
    Dim i As Integer
    Obj.GetXData AppName:=RegApp, XDataType:=XDType, XDataValue:=XDData
    If Not IsEmpty(XDType) Then
        For i = LBound(XDType) To UBound(XDType)
            If XDType(i) = regAppKey Then
                If Not XDData(i) Like acadApp Then
                    NewType(0) = regAppKey
                    NewData(0) = XDData(i)
                    Obj.setXdata XDataType:=NewType, XDataValue:=NewData
                End If
            End If
        Next i
    End If
End Sub
'显示选定图元的扩展属性
Public Sub ListXData(ByVal AcadApp As Object)
  Dim ent As Object
  Dim XDType As Variant, XDData As Variant
  Dim i As Integer, pnt(2) As Double, strPrint As String, strInfo As String, strEnd As String
  On Error Resume Next
  AcadApp.Application.ActiveDocument.Utility.GetEntity ent, pnt, vbCr & vbCr & "选择实体:"
  If Err Then Err.Clear: Exit Sub
  ent.GetXData "", XDType, XDData
  If Not IsEmpty(XDType) Then
        For i = LBound(XDType) To UBound(XDType)
            DoEvents
            If XDType(i) = 1001 Then
                If Not XDData(i) Like "ACAD" Then
                   If strPrint = "" Then
                      strPrint = "[" & XDData(i) & "]=" & GetCode(ent, CStr(XDData(i)))
                   Else
                      strPrint = strPrint & Space(2) & "[" & XDData(i) & "]=" & GetCode(ent, CStr(XDData(i)))
                   End If
                End If
            End If
        Next i
  End If
  strInfo = "----------实体 " & ent.Handle & " 扩展属性----------"
  If strPrint = "" Then
     strPrint = strInfo & vbCrLf & "NULL"
  Else
     strPrint = strInfo & vbCrLf & strPrint
  End If
  For i = 1 To Len(strInfo) + 6
      strEnd = strEnd & "-"
  Next i
  strPrint = strPrint & vbCrLf & strEnd
  AcadApp.Application.ActiveDocument.Utility.Prompt vbCr & vbCr & strPrint
End Sub

全部评论

等级:LV30
积分:72050
奔跑蜗牛 2019-11-01 12:11
学习了
回复 0
1
提交
悬赏回复规则
1、悬赏期为24小时,从发布时间起算;
2、悬赏期内提问者如设置评论为“精选评论”,视为悬赏结束,该精选评论人将获得本题全部悬赏积分;
3、悬赏期内如提问者未设置“精选评论”,则前5位评论者平分悬赏积分(如仅有一位评论,该评论者获得50%悬赏积分);
4、悬赏积分会自动发放到生态圈账户中,请留意站内信通知。
知道了

距离打开宝箱还剩7

是否花费200积分补签?
确认
取消