在EXCEL中向CAD命令行发送命令
本帖最后由 清风明月名字 于 2014-4-14 18:55 编辑Public Function 向CAD命令行发送命令(命令 As String)
'STRING为变长字符串,可以储存2的32次方字符即2亿多个
Dim CAD As AcadApplication, CADDOC As AcadDocument
Dim MYSpacE, j, plineObj, layerobj
Set CAD = GetObject(, "AutoCAD.Application") '取得CAD现有进程
If Err Then
Err.Clear
Set CAD = CreateObject("AutoCAD.Application") '若 AutoCad未启动,则运行它
If Err Then
Dim msg As String
msg = Err.Description + "! 检查CAD安装是否正确"
MsgBox msg
Exit Function
End If
End If
CAD.Visible = True
Set CADDOC = CAD.ActiveDocument
Set MYSpacE = CADDOC.ModelSpace
'创建新图层000宏或命令行所画图元放于此
Set layerobj = CADDOC.Layers.Add("000宏或命令行所画图元放于此")
CADDOC.SendCommand 命令
向CAD命令行发送命令 = "检查一下"
End Function
ThisDrawing.SendCommand"命令及参数"
例:自动清理图层
ThisDrawing.SendCommand "-purge" & vbCr & "A" & vbCr & vbCr & "N" & vbCr
Sub Ch3_SendACommandToAutoCAD()
ThisDrawing.SendCommand "_Circle 2,2,0 4 "
ThisDrawing.SendCommand "_zoom a "
End Sub
你疯了吗? 学习了,多谢讲解 是将VBA代码放在EXCEL中,来运行的 怎么最近都收币啊 哎 懒得理你 运行不了,楼主能否上传一个excel文档?
页:
[1]