关于使⽤VBA调⽤AutoCAD的学习
如果有很多个坐标点,想简单的看⼀下彼此之间的相对位置关系,⼀个很简单的办法,就是展到AutoCAD中。在AutoCAD中逐点输⼊坐标数据肯定是不现实的,最简答的⽅法是在Excel中调⽤AutoCAD:
Global Sheet As Object, acadmtext As acadmtext, fontHight As Double
Global xlBook As Excel.Workbook
Global p0(2) As Double, p1(2) As Double, p2(2) As Double
Global acadApp As Object
Global acadDoc As Object
Global number As Integer, pt(2) As Double
Public Function GetAcad(dwt As String) As Boolean
Dim Face As String
Dim Bold As Boolean
Dim Italic As Boolean
Dim charSet As Long
Dim PitchandFamily As Longvba自学好学吗
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If Err Then
Err.Clear
Set acadApp = CreateObject("AutoCAD.Application")
If Err Then
MsgBox "请安装AutoCAD 2000以上版本", vbCritical, "autocad"
Exit Function
On Error GoTo 0
GetAcad = False
Exit Function
End If
End If
Set acadDoc = acadApp.ActiveDocument
acadApp.Visible = True
GetAcad = True
acadDoc.ActiveTextStyle.GetFont Face, Bold, Italic, charSet, PitchandFamily
acadDoc.ActiveTextStyle.SetFont "宋体", Bold, Italic, charSet, PitchandFamily
0:
End Function
Public Function Draw_Point(Point() As Double) As AcadPoint
Set Draw_Point = acadDoc.ModelSpace.AddPoint(Point)
Draw_Point.Update
End Function
但如果计算机中装了多个版本的CAD,在调⽤过程中存在混淆,经查阅资料原来还有ProgID 这个东西:
AutoCAD产品名版本号ProgID
AutoCAD 2004R16AutoCAD.Application.16
AutoCAD 2005R16.1AutoCAD.Application.16.1
AutoCAD 2006R16.2AutoCAD.Application.16.2
AutoCAD 2007R17AutoCAD.Application.17
AutoCAD 2008R17.1AutoCAD.Application.17.1
AutoCAD 2009R17.2AutoCAD.Application.17.2
AutoCAD 2010R18AutoCAD.Application.18
AutoCAD 2011R18.1AutoCAD.Application.18.1
⽤法指导:
CreateObject ("AutoCAD.Application.17.1") '启动AutoCAD 2008.
如果不指定版本号,如CreateObject("AutoCAD.Application"),程序就会启动⽤户最后⼀次使⽤的AutoCAD的版本。
如果机器上装了很多AutoCAD的版本,往往需要指定启动哪个版本(⽐如R18.1,⽽不是R18)。
⼜:查到下⾯这个资料。基本意思就是说AutoCAD2012应该使⽤VS2010调⽤,那么VBA调⽤可能要出问题。事实上,我机⼦上同时装了AutoCAD2006和2012两个版本,AutoCAD2012调⽤就是不⾏。
懒得管那么多了,我的本意就是想看看点之间的相对位置关系,不想再去穷究了。
Note Projects compiled with Microsoft Visual Studio 2008 with a target of Microsoft .NET Framework 3.5 should load into AutoCAD 2012 without a problem. Microsoft Visual Studio 2008 cannot be used to debug projects loaded in AutoCAD 2012; you must use Microsoft Visual Studio 2010 when debugging a project.
注意:由Microsoft Visual Studio 2008编译的⽬标为Microsoft .NET Framework 3.5的项⽬可以加载到AutoCAD2012运⾏没有问题。但Microsoft Visual Studio 注意
2008不能⽤来调试AutoCAD 2012加载的项⽬,调试项⽬时必须使⽤Microsoft Visual Studio 2010。
If you are using AutoCAD 2010 or AutoCAD 2011, you should use:
如果使⽤的是AutoCAD 2010或AutoCAD 2011,则应选择:
· Microsoft Visual Studio 2008 with Service Pack 1
· Microsoft .NET Framework 3.5 with Service Pack 1
If you are using AutoCAD 2007 through AutoCAD 2009, you should use:
如果使⽤的是AutoCAD 2007到AutoCAD 2009,则应选择:
· Microsoft Visual Studio 2005
· Microsoft .NET Framework 2.0 or later (或2.0以上)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论