View Full Version : Detach xrefs with VBA

2004-07-21, 09:26 PM
I'm using AutoCAD 2000. How do I correctly detach a known xref using VBA. I can get to the external reference by iterating through a selection set to get the correct name and path information to verify that I have the correct xref to detach, but I cannot seem to figure out the correct syntax for detaching it.

I'm getting "object doesn't support this property or method" errors.

2004-07-21, 11:00 PM
The ExternalReference object does not have a Detach method. You need to get the Block object, which does have a Detach method.

2004-07-22, 09:42 PM
OK Got that. Thanks Robert.

Is there a way to detach an xref that is nested with multiple references? For example I have an assembly drawing that has a titleblock xrefed. There are also numerous other part drawings xrefed into this assembly drawing that also have the same titleblock xrefed within them.

What I am trying to do is detach the current titleblock in the assembly drawing and xref in a new one. When I try doing this on this I'm getting the error "run-time error '-2145386475 (80200015)': Duplicate Key.

Is there a way around this to get to the titleblock xref in the assembly drawing only and detach it?

2004-07-22, 11:00 PM
It is probably far too late for you, but I would advise Overlaying titleblocks for exactly this reason.

:confused: However, I don't get the issue. After all, an XRef's purpose in life is to always be up-to-date. How can it be an XRef and not be up-to-date?

2004-07-23, 01:24 PM
Good question.

I agree with the overlay comment. However I was not in this position when that decision was made.

Our company recently acquired another. The powers that be here want to have 1 common titleblock between the two companies. The geometry of the block and location of the attributes changed. So it's not so easy as to just change the block file because the attributes need changing also. The attribute block is inserted into the drawing and the titleblock is xrefed.

To make matters worse our company has had 2 or 3 different titleblocks over the last 50 years. 2 are xrefs. This does not include the acquired company which has many more and 1 is an xref.

Any other ideas for the xref problem?

2004-07-23, 03:26 PM
Sounds like a great case for using ObjectDBX to clean up all the drawings at one time. Gather attribute info, erase the current level insertions, overlay the correct XRef, insert and repopulate the attributes. Note that attribute positions can be trouble in ObjectDBX if there are non-left-justified attributes.