VB外部参照搜索
(使用AutoCAD 2000)你好
我有一个快速的外部参照问题。有人能帮我用一些VB代码在附着的外部参照中“搜索”吗?我需要浏览数百个图形,如果它们包含某个外部参照,我想删除它。
要从图形中删除的外部参照有一个静态名称,因此应该会更容易-但我不知道如何将外部参照“搜索”功能合并到程序中。
基本上我想:
-打开文件夹中的每个图形(我已经有了这样做的代码)
-搜索名为“基础图形”的外部参照
-如果它存在,我想删除它。如果它不存在,我想移到下一个图形
是否可以以这种方式搜索外部参照?有人能帮我吗?
非常感谢。
迈克 使用Objectdbx可以做到这一点-它可以更快地悄悄打开图形,然后在autocad中实际打开图形
我没有vb在我面前,我不记得代码分离,但你应该能够解决它
告诉我进展如何
干杯
Option Explicit
Sub CHANGEXREFS ()
Dim AcadDbx As AxdbDocument
Dim Direc As String
Dim Elem as object
Dim Filenom as string
Dim Wholefile as string
Set AcadDbx = GetInterfaceObject("OjectDBX.AxDbDocument.17")
On Error Resume Next
Direc = "c:\program files\AutoCAD Civil 3D 2008\Sample" 'Change to your directory or link directory to a form
Filenom = Dir$(Direc & "\*.dwg")
Do While filenom <> ""
Wholefile = Direc & "\" & filenom
msgbox wholefile ' i just put this here to show you that it is opening the files
AcadDbx.open Wholefile
For Each Elem In AcadDbx.Blocks
If elem.IsXRef = True and elem.name = "Base-Drawing" then
Msgbox "PUT YOUR CODE HERE WHAT YOU WNAT TO DO WITH THE XREF"
'it should be something like 'elem.Detach = true (cant remember)
End if
Next 'Next Elem
Set Elem = Nothing
Filenom = Dir$
Loop
set AcadDbx = Nothing
end sub
这对我很有效。谢谢你的帮助! 啊,嗯。有人能告诉我为什么在向代码中添加第二个外部参照时出现“循环未初始化”错误吗?
For Each Elem In AcadDbx.Blocks
If Elem.IsXRef = True And Elem.Name = "Base-Drawing" Or Elem.IsXRef = True And Elem.Name = "Temp-Base" Then
Elem.Detach
End If
Next
我没有办法对此进行测试,但请尝试:
For Each Elem In AcadDbx.Blocks
If Elem.IsXRef = True And (Elem.Name = "Base-Drawing" Or Elem.Name = "Temp-Base") Then
Elem.Detach
End If
Next 这奏效了。我不知道为什么会有不同,但它有效,而且更干净,所以我不会想太久!英雄联盟
谢谢你的帮助! 是否有方法修改此脚本以生成外部参照链接到的图形列表,而不是删除外部参照?例如,我有一个名为“site plan”的外部参照图形,它链接到20个其他图形。我想打印这些图纸的列表,参考“现场平面图”。
页:
[1]