本帖最后由 efan2000 于 2014-7-27 19:35 编辑
通过封装ARX的函数,使之能够在VB、VBA或者.NET等中以COM方式访问。
acdbEntMake对应的COM函数为:Function AcdbEntMake(codetype, codevalue) As Long,其中codetype为整型的数组,codevalue为变体的数组,根据组码来确定类型。
- ' 创建圆弧
- Sub testAcdbEntMakeArc()
- Dim ct(0 To 4) As Integer
- Dim cv(0 To 4) As Variant
- ct(0) = 0
- cv(0) = "ARC"
- Dim pt1(0 To 2) As Double
- ct(1) = 10 ' 圆心
- cv(1) = pt1
- ct(2) = 40 ' 半径
- cv(2) = 1
- ct(3) = 50 ' 起点角度
- cv(3) = 0
- ct(4) = 51 ' 端点角度
- cv(4) = 45
- Debug.Print AcdbEntMake(ct, cv)
- End Sub
- ' 创建圆弧-新版
- Sub testAcdbEntMakeArc()
- Dim ent As ResultBuffer
- Set ent = New ResultBuffer
- ent.AddTypedValue 0, "ARC"
- Dim pt(0 To 2) As Double
- ent.AddTypedValue 10, pt ' 圆心
- ent.AddTypedValue 40, 1 ' 半径
- ent.AddTypedValue 50, 0 ' 起点角度
- ent.AddTypedValue 51, 45 ' 端点角度
- Debug.Print AcdbEntMake(ent)
- End Sub
- ' 创建圆
- Sub testAcdbEntMakeCircle()
- Dim ct(0 To 2) As Integer
- Dim cv(0 To 2) As Variant
- ct(0) = 0
- cv(0) = "CIRCLE"
- Dim pt1(0 To 2) As Double
- ct(1) = 10 ' 圆心
- cv(1) = pt1
- ct(2) = 40 ' 半径
- cv(2) = 3.5
- Debug.Print AcdbEntMake(ct, cv)
- End Sub
- ' 创建圆-新版
- Sub testAcdbEntMakeCircle()
- Dim ent As ResultBuffer
- Set ent = New ResultBuffer
- ent.AddTypedValue 0, "CIRCLE"
- Dim pt1(0 To 2) As Double
- ent.AddTypedValue 10, pt1 ' 圆心
- ent.AddTypedValue 40, 3.5 ' 半径
- Debug.Print AcdbEntMake(ent)
- End Sub
- '插入块
- Sub testAcdbEntMakeInsert()
- Dim ct(0 To 2) As Integer
- Dim cv(0 To 2) As Variant
- ct(0) = 0
- cv(0) = "INSERT"
- ct(1) = 2 ' 名称
- cv(1) = "Block"
- Dim pt(0 To 2) As Double
- ct(2) = 10 ' 位置
- cv(2) = pt
- Debug.Print AcdbEntMake(ct, cv)
- End Sub
- ' 创建直线
- Sub testAcdbEntMakeLine()
- Dim ct(0 To 2) As Integer
- Dim cv(0 To 2) As Variant
- ct(0) = 0
- cv(0) = "LINE"
- Dim pt1(0 To 2) As Double
- ct(1) = 10 ' 起点
- cv(1) = pt1
- Dim pt2(0 To 2) As Double
- pt2(0) = 10
- ct(2) = 11 ' 端点
- cv(2) = pt2
- Debug.Print AcdbEntMake(ct, cv)
- End Sub
- ' 创建多行文字
- Sub testAcdbEntMakeMText()
- Dim ct(0 To 4) As Integer
- Dim cv(0 To 4) As Variant
- ct(0) = 0
- cv(0) = "MTEXT"
- ct(1) = 100
- cv(1) = "AcDbEntity"
- ct(2) = 100
- cv(2) = "AcDbMText"
- Dim pt(0 To 2) As Double
- ct(3) = 10 ' 位置
- cv(3) = pt
- ct(4) = 1 ' 内容
- cv(4) = "MText"
- Debug.Print AcdbEntMake(ct, cv)
- End Sub
- ' 创建点
- Sub testAcdbEntMakePoint()
- Dim ct(0 To 1) As Integer
- Dim cv(0 To 1) As Variant
- ct(0) = 0
- cv(0) = "POINT"
- Dim pt1(0 To 2) As Double
- ct(1) = 10 ' 位置
- cv(1) = pt1
- Debug.Print AcdbEntMake(ct, cv)
- End Sub
- ' 创建多段线
- Sub testAcdbEntMakePolyline()
- Dim ct(0 To 5) As Integer
- Dim cv(0 To 5) As Variant
- ct(0) = 0
- cv(0) = "LWPOLYLINE"
- ct(1) = 100
- cv(1) = "AcDbEntity"
- ct(2) = 100
- cv(2) = "AcDbPolyline"
- ct(3) = 90 ' 顶点数
- cv(3) = 2
- Dim pt1(0 To 1) As Double
- ct(4) = 10 ' 顶点
- cv(4) = pt1
- Dim pt2(0 To 1) As Double
- pt2(0) = 10
- ct(5) = 10 ' 顶点
- cv(5) = pt2
- Debug.Print AcdbEntMake(ct, cv)
- End Sub
- ' 创建文字
- Sub testAcdbEntMakeText()
- Dim ct(0 To 3) As Integer
- Dim cv(0 To 3) As Variant
- ct(0) = 0
- cv(0) = "TEXT"
- Dim pt1(0 To 2) As Double
- ct(1) = 10 ' 位置
- cv(1) = pt1
- ct(2) = 40 ' 高度
- cv(2) = 2
- ct(3) = 1 ' 内容
- cv(3) = "Text"
- Debug.Print AcdbEntMake(ct, cv)
- End Sub
2014.07.25
修正AcedGrRead的BUG。
2014.06.19
原来版本部分函数已更改,新增ResultBuffer和TypedValue类处理ARX的resbuf结构。
支持R2004-R2014版本的AutoCAD32位版本。
注:函数库在R2007测试通过,理论上在R2008、R2009的32版本可以通用,其它版本的将于后续发布。
增加了R2010的32位版本mccomarx18,R2011、R2012的可以通用,但没测试。
增加了R2004的32位版本mccomarx16,R2005、R2006的可以通用,但没测试。
|