- 积分
- 228
- 明经币
- 个
- 注册时间
- 2010-12-9
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
我要做一个Excel和AutoCAD连接的问题,用excel打开cad并替换一些cad中的文字和标注文字。Excel和CAD各自的代码已经写好,但是不知道如何用excel运行cad的代码,看了一些帖子没弄清楚。
于是我把cad的代码弄到了excel里面,做了一些修改(在thisdrawing前面加了autocad.application.),但却无法运行。红色的代码提示“对象不支持该属性或方法”,刚接触vba不久,清楚的朋友可否指点一下?
代码如下:
Public Sub DrawingTextReplace()
'尺寸修改
Dim strResult As String
Dim Obj As AcadEntity
Dim oDim As AcadDimension
For Each Obj In AutoCAD.Application.ThisDrawing.ModelSpace
If (Obj.ObjectName = "AcDbAlignedDimension" Or Obj.ObjectName = "AcDbRotatedDimension") Then
Set oDim = Obj
If InStr(oDim.TextOverride, "L=") > 0 Then oDim.TextOverride = "L=1000"
End If
Next Obj
'文字修改
Dim TextSelect As AcadSelectionSet
Dim FilterType(0 To 3) As Integer
Dim FilterData(0 To 3)
Dim adText As Object
On Error Resume Next
FilterType(0) = -4
FilterData(0) = "<or"
FilterType(1) = 0
FilterData(1) = "text"
FilterType(2) = 0
FilterData(2) = "mtext"
FilterType(3) = -4
FilterData(3) = "or>"
If Not IsNull(AutoCAD.Application.ThisDrawing.SelectionSets.Item("TextSelect")) Then
Set TextSelect = AutoCAD.Application.ThisDrawing.SelectionSets.Item("TextSelect")
TextSelect.Delete
End If
Set TextSelect = AutoCAD.Application.ThisDrawing.SelectionSets.Add("TextSelect")
TextSelect.Select acSelectionSetAll, , , FilterType, FilterData
For Each adText In TextSelect
If InStr(adText.TextString, "大庆") Then adText.TextString = "克拉玛依"
Next
End Sub
|
|