- 积分
- 203
- 明经币
- 个
- 注册时间
- 2011-10-27
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
ub Command1_Click()
Dim objDbx As AXDBLib.AxDbDocument
Dim fileName As String
Dim ent() As AcadEntity
Dim lngCount As Long, i As Long
Do
Set objDbx = CreateObject("ObjectDBX.AxDbDocument.18")
ThisDrawing.SendCommand "(setvar " & """users1""" & "(getfiled " & """Select a DWG File""" & """E:/工作/全图/142-KB/""" & """dwg""" & "8)) "
fileName = ThisDrawing.GetVariable("users1")
objDbx.Open fileName
lngCount = objDbx.ModelSpace.Count
ReDim ent(lngCount - 1) As AcadEntity
For i = 0 To lngCount - 1
Set ent(i) = objDbx.ModelSpace.Item(i)
Next i
objDbx.CopyObjects ent, ThisDrawing.ModelSpace
Set objDbx = Nothing
If MsgBox("是否继续?", vbYesNo, "Microsoft Excel") = vbNo Then
Dim s
Dim t As String
Dim lay0 As AcadLayer
t = "图例"
Do
s = MsgBox("是否删除" & t & "层吗?", vbOKCancel, "提示")
If s = vbOK Then
findlay = 0
For Each lay0 In ThisDrawing.Layers '在所有的图层中进行循环
If lay0.Name = t Then '如果找到图层名
findlay = 1
Dim L As AcadLayer
Set L = ThisDrawing.Layers(t)
ThisDrawing.ActiveLayer = ThisDrawing.Layers("0")
Dim E As AcadEntity
For Each E In ThisDrawing.ModelSpace
If E.Layer = t Then
E.Delete
End If
Next
'L.Delete '当图层中有参照时删不掉
ThisDrawing.Regen acActiveViewport
Exit For
End If
Next lay0
If findlay = 0 Then '没有找到图层
MsgBox "没有找到" & t & " 图层"
End If
If t = "图例" Then
t = "内图廓线"
Else
Exit Sub
End If
Else
If t = "图例" Then
t = "内图廓线"
Else
Exit Sub
End If
End If
Loop
Exit Sub
End If
Loop
End Sub
[img]file:///D:/我的文档/Tencent%20Files/974135976/Image/D(H{B)4GYI1PWP][%H1C%OY.jpg[/img]
这段程序在VBA中运行正常,但在VB中运行就出现以上错误,不知哪位高手知道这是哪里的问题?
Set objDbx = CreateObject("ObjectDBX.AxDbDocument.18")在VB中运行时出错是什么原因?
也引用了
file:///D:/我的文档/Tencent%20Files/974135976/Image/DW6WX39Y_5447CE7VYC4)KJ.jpg
|
|