- UID
- 91561
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-11-3
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
扩展数据是AutoCAD最有特色的功能,程序员可以为实体附加必要的扩展数据,使实体带有具体的含义,而不是单纯的一个AutoCAD图元。扩展数据有许多用处,除可以存放数据外,还可以利用扩展数据获取选择集。下面是两个关于扩展数据的示例:
Private Sub Command4_Click()
Dim ent As Object
Dim startPoint(0 To 2) As Double
Dim endPoint(0 To 2) As Double
Dim dataType(0 To 3) As Integer
Dim data(0 To 3) As Variant
Set objAcad = GetObject(, "AutoCAD.Application") ' 获得AutoCAD R14对象
Set objDoc = objAcad.ActiveDocument
startPoint(0) = 10#
startPoint(1) = 10#
startPoint(2) = 0#
endPoint(0) = 20#
endPoint(1) = 10#
endPoint(2) = 0#
dataType(0) = 1001 '扩展数据组的应用名
data(0) = "管道专业扩展数据"
dataType(1) = 1000
data(1) = "供水管"
dataType(2) = 1040 '长度
data(2) = 15.5
dataType(3) = 1070 '公称直径
data(3) = 32
' 画 LINE
Set ent = objDoc.ModelSpace.AddLine(startPoint, endPoint)
With ent
.Color = 1 ' 改用红色
Call .SetXData(dataType, data) '写入扩展数据
End With
Set objAcad = Nothing
End Sub
Private Sub Command5_Click()
Dim UtilObj As Object
Dim sset As Object
Dim ent As Object
Dim Point1(0 To 2) As Double
Dim Point2(0 To 2) As Double
Dim gpCode(0 To 1) As Integer
Dim dataValue(0 To 1) As Variant
Dim varData As Variant
Dim groupCode As Variant, dataCode As Variant
Dim xdataType As Variant
Dim xdataValue As Variant
Set objAcad = GetObject(, "AutoCAD.Application") ' 获得AutoCAD R14对象
Set objDoc = objAcad.ActiveDocument
On Error GoTo Error_GetEntity
Set UtilObj = objAcad.ActiveDocument.Utility
' 初始化名为 ss1 的一个选择集
Set sset = objAcad.ActiveDocument.SelectionSets.Add("ss1")
' 获得系统变量 LIMMIN 用于设置第一个虚拟点
varData = objAcad.ActiveDocument.GetVariable("LIMMIN")
Point1(0) = varData(0)
Point1(1) = varData(1)
Point1(2) = 0#
' 获得系统变量 LIMMAX 用于设置第二个虚拟点
varData = objAcad.ActiveDocument.GetVariable("LIMMAX")
Point2(0) = varData(0)
Point2(1) = varData(1)
Point2(2) = 0#
gpCode(0) = 0 ' 设置第一个过滤条件的组代码
dataValue(0) = "Line" ' 过滤出 Line 实体
gpCode(1) = 1001 ' 设置第二个过滤条件的组代码
dataValue(1) = "管道专业扩展数据" ' 过滤出含扩展数据组的应用名的实体
groupCode = gpCode ' 设置全部过滤条件的组代码
dataCode = dataValue ' 设置全部过滤条件 ' 用条件过滤获得选择集
sset.Select 0, Point1, Point2, groupCode, dataCode
If sset.Count > 0 Then
Set ent = sset(0) ' 从选择集中取出第一个实体
Call ent.GetXData("管道专业扩展数据", xdataType, xdataValue)
MsgBox xdataValue(1) + ": 长度=" + Str(xdataValue(2)) + " 公称直径=" + Str(xdataValue(3))
End If
Set objAcad = Nothing
Exit Sub
Error_GetEntity:
MsgBox Err.Description, 16, "Error: AutoCAD is not running"
Set objAcad = Nothing
Exit Sub
End Sub |
|