- 积分
- 610
- 明经币
- 个
- 注册时间
- 2017-8-9
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 2017forverd 于 2018-1-10 14:33 编辑
Sub Main()
Dim acadapp As Object
Dim objsel As AcadSelectionSet
Dim xref As AcadExternalReference
Dim ptmin(2) As Double
Dim ptmax(2) As Double
Dim objtext As AcadText
Dim objref As AcadExternalReference
'On Error Resume Next
Set acadapp = GetObject(, "AutoCAD.Application")
If Err Then
Err.Clear
Set acadapp = CreateObject("AutoCAD.Application")
End If
'遍历该程序所在文件夹内的所有dwg文件
Dim i As Integer
i = 0
h = 4.5
mydir = Dir(App.Path & "\*.dwg", vbNormal)
Do While mydir <> ""
Set wb = GetObject(App.Path & "\" & mydir)
If mydir = "标准图框.dwg" Then
GoTo nextdo
End If
Set activedoc = acadapp.ActiveDocument
myname = Left(mydir, InStr(mydir, Chr(32)) - 1) '获取文件名中的图号
Set objsel = activedoc.SelectionSets.Add("myselection") '选择所有的插入图形为选择集
Dim ft(0) As Integer
Dim fd(0)
ft(0) = 0: fd(0) = "insert"
objsel.Select acSelectionSetAll, , , ft, fd
For Each objref In objsel
If objref.Name = "标准图框" Then
ownid = objref.OwnerID
Set obj = activedoc.ObjectIdToObject(ownid)
layout_name = obj.layout.Name
activedoc.activelayout = activedoc.layouts.Item(layout_name) '激活图框的布局
a = objref.XScaleFactor '获取图框的缩放因子
ptmin(0) = objref.InsertionPoint(0) + a * 388.3 '获取图框的插入点
ptmin(1) = objref.InsertionPoint(1) + a * 12.86
If objref.Hyperlinks.Application.ActiveDocument.ActiveSpace = acModelSpace Then
Set objtext = activedoc.ModelSpace.AddText(myname, ptmin, h * a)
Else
Set objtext = activedoc.PaperSpace.AddText(myname, ptmin, h * a)
End If
'objtext.StyleName = "zdmhz1"
'objtext.ScaleFactor = 0.7
'objtext.Update
End If
Next
wb.Save
activedoc.Close
i = i + 1
nextdo:
mydir = Dir
Loop
Set wb = Nothing
Set pathname = Nothing
Set activedoc = Nothing
acadapp.Visible = True
MsgBox "本次共编辑图号" & i & "张"
End Sub
这是我编写的一段代码,但是运行在第一个else的时候出现
第一次遇到这个错误,请问怎么解决?谢谢
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|