Jump to content

Recommended Posts

Posted

(using AutoCAD 2000)

Hello

 

I have a quick XRef question. Can someone help me with some VB code that “searches” among attached XRefs? I need to go through hundreds of drawings and if they contain a certain XRef – I want to remove it.

 

The XRef to be removed from the drawings has a static name, so that should make it easier – but I’m not sure how to incorporate an XRef “search” function into a program.

 

Basically I want to:

- open every drawing in a folder (I already have the code to do that)

- search for an XRef named “Base-Drawing”

- if it exists I want to remove it. If it does not exist I want to move to the next drawing

 

Is it possible to search XRefs in that manner? Can someone help me?

 

Thank you

Mike

Posted

use Objectdbx to do this - its heaps quicker opening drawings quietly then actually opening the drawing in autocad

 

I dont have vb infront of me and i cant remeber the code to detach but you should be able to work it out

 

Let me know how you go

 

Cheers

 

 


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

Posted

Aargh, hmmmmm. Can someone tell me why I get a “loop not initialized” error when I add a second XRef to the code?

 

 
For Each Elem In [color=black]AcadDbx.Blocks[/color]
   If Elem.IsXRef = True And Elem.Name = "[color=black]Base-Drawing"[/color] Or Elem.IsXRef = True And Elem.Name = "Temp-Base" Then
   Elem.Detach
   End If
Next

Posted

No way for me to test this but try:

 

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

Posted

That worked. I don't know why it made a difference but it worked and it's cleaner so I'm not going to wonder about it for too long! lol

 

Thanks for all your help!

  • 2 weeks later...
Posted

Is there a way to modify this script to make a list of drawings the xref is linked to instead of deleting the xref? For example, I have an xref drawing named "site plan" and it is linked to 20 other drawings. I want to print a list of those drawings "site plan" is referenced.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...