明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1565|回复: 2

ARX的COM函数库之实体篇(acdbEntGet)

[复制链接]
发表于 2013-11-18 15:35:25 | 显示全部楼层 |阅读模式
本帖最后由 efan2000 于 2014-6-19 20:45 编辑

通过acdbEntMake可以创建对象,创建之后可以通过acdbEntLast获取最后创建的对象,再通过acdbEntGet可以查询对象的信息。
  1. ' 创建直线
  2. Sub testAcdbEntMakeLine()
  3.     Dim ct(0 To 2) As Integer
  4.     Dim cv(0 To 2) As Variant
  5.     ct(0) = 0
  6.     cv(0) = "LINE"
  7.     Dim pt1(0 To 2) As Double
  8.     ct(1) = 10 ' 起点
  9.     cv(1) = pt1
  10.     Dim pt2(0 To 2) As Double
  11.     pt2(0) = 10
  12.     ct(2) = 11 ' 端点
  13.     cv(2) = pt2
  14.     Debug.Print AcdbEntMake(ct, cv)
  15.     testAcdbEntLast
  16. End Sub

  17. ' 创建直线-新版
  18. Sub testAcdbEntMakeLine()
  19.     Dim ent As ResultBuffer
  20.     Set ent = New ResultBuffer
  21.     ent.AddTypedValue 0, "LINE"
  22.     Dim pt1(0 To 2) As Double
  23.     ent.AddTypedValue 10, pt1 ' 起点
  24.     Dim pt2(0 To 2) As Double
  25.     pt2(0) = 10
  26.     ent.AddTypedValue 11, pt2 ' 端点
  27.     Debug.Print AcdbEntMake(ent)
  28. End Sub

  29. ' 获取最后创建对象
  30. Sub testAcdbEntLast()
  31.     Dim v As Variant
  32.     Debug.Print AcdbEntLast(v)
  33.     testAcdbEntGet v
  34. End Sub

  35. ' 获取对象组码
  36. Sub testAcdbEntGet(ByVal ent As Variant)
  37.     Dim t As Variant
  38.     Dim v As Variant
  39.     AcdbEntGet ent, t, v
  40.     Dim s As String
  41.     s = "("
  42.     Dim i As Integer
  43.     For i = 0 To UBound(t)
  44.         If i <> 0 Then
  45.             s = s & " "
  46.         End If
  47.         If (t(i) = -1) Or (t(i) >= 330 And t(i) <= 369) Then
  48.             s = s & "(" & t(i) & " . " & "<图元名: " & LCase(Hex(v(i)(0))) & ">" & ")"
  49.         ElseIf (t(i) >= 0 And t(i) <= 9) Or (t(i) >= 100 And t(i) <= 109) Or (t(i) >= 410 And t(i) <= 419) Then
  50.             s = s & "(" & t(i) & " . " & """" & v(i) & """" & ")"
  51.         ElseIf (t(i) >= 10 And t(i) <= 17) Or (t(i) >= 210 And t(i) <= 219) Then
  52.             s = s & "(" & t(i) & " " & Format(v(i)(0), "0.0" & String(5 - IIf(Abs(Fix(v(i)(0))) = 0, 0, Len(Abs(Fix(v(i)(0))))), "#")) & " " & Format(v(i)(1), "0.0" & String(5 - IIf(Abs(Fix(v(i)(1))) = 0, 0, Len(Abs(Fix(v(i)(1))))), "#")) & " " & Format(v(i)(2), "0.0" & String(5 - IIf(Abs(Fix(v(i)(2))) = 0, 0, Len(Abs(Fix(v(i)(2))))), "#")) & ")"
  53.         ElseIf (t(i) >= 38 And t(i) <= 59) Or (t(i) >= 140 And t(i) <= 149) Then
  54.             s = s & "(" & t(i) & " . " & Format(v(i), "0.0" & String(5 - IIf(Abs(Fix(v(i))) = 0, 0, Len(Abs(Fix(v(i))))), "#")) & ")"
  55.         Else
  56.             s = s & "(" & t(i) & " . " & v(i) & ")"
  57.         End If
  58.     Next
  59.     s = s & ")"
  60.     Debug.Print s
  61. End Sub


  62. ' 获取对象组码-新版
  63. Sub testAcdbEntGet(ByVal ent As Variant)
  64.     Dim rb As ResultBuffer
  65.     Set rb = AcdbEntGet(ent)
  66.     Dim v As Variant
  67.     v = rb.AsArray()
  68.     Dim s As String
  69.     s = "("
  70.     Dim i As Integer
  71.     For i = 0 To UBound(v)
  72.         Dim tv As TypedValue
  73.         Set tv = v(i)
  74.         If i <> 0 Then
  75.             s = s & " "
  76.         End If
  77.         If (tv.TypeCode = -1) Or (tv.TypeCode >= 330 And tv.TypeCode <= 369) Then
  78.             s = s & "(" & tv.TypeCode & " . " & "<图元名: " & LCase(Hex(tv.Value(0))) & ">" & ")"
  79.         ElseIf (tv.TypeCode >= 0 And tv.TypeCode <= 9) Or (tv.TypeCode >= 100 And tv.TypeCode <= 109) Or (tv.TypeCode >= 410 And tv.TypeCode <= 419) Then
  80.             s = s & "(" & tv.TypeCode & " . " & """" & tv.Value & """" & ")"
  81.         ElseIf (tv.TypeCode >= 10 And tv.TypeCode <= 17) Or (tv.TypeCode >= 210 And tv.TypeCode <= 219) Then
  82.             s = s & "(" & tv.TypeCode & " " & Format(tv.Value(0), "0.0" & String(5 - IIf(Abs(Fix(tv.Value(0))) = 0, 0, Len(Abs(Fix(tv.Value(0))))), "#")) & " " & Format(tv.Value(1), "0.0" & String(5 - IIf(Abs(Fix(tv.Value(1))) = 0, 0, Len(Abs(Fix(tv.Value(1))))), "#")) & " " & Format(tv.Value(2), "0.0" & String(5 - IIf(Abs(Fix(tv.Value(2))) = 0, 0, Len(Abs(Fix(tv.Value(2))))), "#")) & ")"
  83.         ElseIf (tv.TypeCode >= 38 And tv.TypeCode <= 59) Or (tv.TypeCode >= 140 And tv.TypeCode <= 149) Then
  84.             s = s & "(" & tv.TypeCode & " . " & Format(tv.Value, "0.0" & String(5 - IIf(Abs(Fix(tv.Value)) = 0, 0, Len(Abs(Fix(tv.Value)))), "#")) & ")"
  85.         Else
  86.             s = s & "(" & tv.TypeCode & " . " & tv.Value & ")"
  87.         End If
  88.     Next
  89.     s = s & ")"
  90.     Debug.Print s
  91. End Sub

在立即窗口输出:
5100
5100
((-1 . <图元名: fe95e118>) (0 . "LINE") (330 . <图元名: ffe8acf8>) (5 . "EB8B") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine") (10 0.0 0.0 0.0) (11 10.0 0.0 0.0) (210 0.0 0.0 1.0))

ARX的COM接口下载地址


 楼主| 发表于 2013-11-18 16:02:01 | 显示全部楼层
本帖最后由 efan2000 于 2014-4-21 13:55 编辑

如果是先创建多个对象,那么可以通过acdbEntNext依次获取最后创建的对象。
  1. ' 获取多个最后创建对象
  2. Sub testAcdbEntNext()
  3.     Dim r As Integer
  4.     Dim v As Variant
  5.     r = AcdbEntLast(v)
  6.     Debug.Print r
  7.     testAcdbEntMakeLine
  8.     testAcdbEntMakeArc
  9.     Dim tv As Variant
  10.     If r = 5100 Then
  11.         r = AcdbEntNext(v, tv)
  12.     Else
  13.         r = AcdbEntNext(Null, tv)
  14.     End If
  15.     Debug.Print r
  16.     While r = 5100
  17.         testAcdbEntGet tv
  18.         v = tv
  19.         r = AcdbEntNext(v, tv)
  20.         Debug.Print r
  21.     Wend
  22. End Sub

  23. ' 创建直线
  24. Sub testAcdbEntMakeLine()
  25.     Dim ct(0 To 2) As Integer
  26.     Dim cv(0 To 2) As Variant
  27.     ct(0) = 0
  28.     cv(0) = "LINE"
  29.     Dim pt1(0 To 2) As Double
  30.     ct(1) = 10 ' 起点
  31.     cv(1) = pt1
  32.     Dim pt2(0 To 2) As Double
  33.     pt2(0) = 10
  34.     ct(2) = 11 ' 端点
  35.     cv(2) = pt2
  36.     Debug.Print AcdbEntMake(ct, cv)
  37. End Sub

  38. ' 创建圆弧
  39. Sub testAcdbEntMakeArc()
  40.     Dim ct(0 To 4) As Integer
  41.     Dim cv(0 To 4) As Variant
  42.     ct(0) = 0
  43.     cv(0) = "ARC"
  44.     Dim pt1(0 To 2) As Double
  45.     ct(1) = 10 ' 圆心
  46.     cv(1) = pt1
  47.     ct(2) = 40 ' 半径
  48.     cv(2) = 1
  49.     ct(3) = 50 ' 起点角度
  50.     cv(3) = 0
  51.     ct(4) = 51 ' 端点角度
  52.     cv(4) = 45
  53.     Debug.Print AcdbEntMake(ct, cv)
  54. End Sub

  55. ' 获取对象组码
  56. Sub testAcdbEntGet(ByVal ent As Variant)
  57.     Dim t As Variant
  58.     Dim v As Variant
  59.     AcdbEntGet ent, t, v
  60.     Dim s As String
  61.     s = "("
  62.     Dim i As Integer
  63.     For i = 0 To UBound(t)
  64.         If i <> 0 Then
  65.             s = s & " "
  66.         End If
  67.         If (t(i) = -1) Or (t(i) >= 330 And t(i) <= 369) Then
  68.             s = s & "(" & t(i) & " . " & "<图元名: " & LCase(Hex(v(i)(0))) & ">" & ")"
  69.         ElseIf (t(i) >= 0 And t(i) <= 9) Or (t(i) >= 100 And t(i) <= 109) Or (t(i) >= 410 And t(i) <= 419) Then
  70.             s = s & "(" & t(i) & " . " & """" & v(i) & """" & ")"
  71.         ElseIf (t(i) >= 10 And t(i) <= 17) Or (t(i) >= 210 And t(i) <= 219) Then
  72.             s = s & "(" & t(i) & " " & Format(v(i)(0), "0.0" & String(5 - IIf(Abs(Fix(v(i)(0))) = 0, 0, Len(Abs(Fix(v(i)(0))))), "#")) & " " & Format(v(i)(1), "0.0" & String(5 - IIf(Abs(Fix(v(i)(1))) = 0, 0, Len(Abs(Fix(v(i)(1))))), "#")) & " " & Format(v(i)(2), "0.0" & String(5 - IIf(Abs(Fix(v(i)(2))) = 0, 0, Len(Abs(Fix(v(i)(2))))), "#")) & ")"
  73.         ElseIf (t(i) >= 38 And t(i) <= 59) Or (t(i) >= 140 And t(i) <= 149) Then
  74.             s = s & "(" & t(i) & " . " & Format(v(i), "0.0" & String(5 - IIf(Abs(Fix(v(i))) = 0, 0, Len(Abs(Fix(v(i))))), "#")) & ")"
  75.         Else
  76.             s = s & "(" & t(i) & " . " & v(i) & ")"
  77.         End If
  78.     Next
  79.     s = s & ")"
  80.     Debug.Print s
  81. End Sub

在立即窗口输出:
-5001
5100
5100
5100
((-1 . <图元名: ffe8c128>) (0 . "LINE") (330 . <图元名: ffe8acf8>) (5 . "12D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine") (10 0.0 0.0 0.0) (11 10.0 0.0 0.0) (210 0.0 0.0 1.0))
5100
((-1 . <图元名: ffe8c130>) (0 . "ARC") (330 . <图元名: ffe8acf8>) (5 . "12E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbCircle") (10 0.0 0.0 0.0) (40 . 1.0) (210 0.0 0.0 1.0) (100 . "AcDbArc") (50 . 0.0) (51 . 1.0177))
-5001
发表于 2014-1-21 10:12:39 | 显示全部楼层
高级,看不懂。想学习下@
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-2-22 05:41 , Processed in 0.152565 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表