Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

(Nested) Xref reload

11 REPLIES 11
Reply
Message 1 of 12
felipe
331 Views, 11 Replies

(Nested) Xref reload

I need a routine that will do the following to all xrefs in a drawing, including nested xrefs:

1: Determine if the xref is currently loaded or unloaded
2: Reload the xref
3: Unload the xref if it was originally unloaded to begin with

Any takers?

Thanks in advance.
11 REPLIES 11
Message 2 of 12
drudder
in reply to: felipe

If this doesn't work - its close:::: Create a new DVB file with VBAIDE...

Sub NoUnloadXREF()
Dim myXref As AcadBlock
Dim Entity As AcadEntity

For Each myXref In ThisDrawing.Blocks
If myXref.IsXRef And myXref.Count = 0 Then
Dim xrName As String: xrName = myXref.Name
End If
Next Entity

End Sub
Message 3 of 12
drudder
in reply to: felipe

I messed up - this one works...

Sub NoUnloadXREF()
Dim myXref As AcadBlock
Dim Entity As AcadEntity

For Each myXref In ThisDrawing.Blocks
If myXref.IsXRef And myXref.Count = 0 Then
Dim xrName As String: xrName = myXref.Name
End If
Next myXref

End Sub
Message 4 of 12
felipe
in reply to: felipe

Can this be done using lisp, or only vba?

Also, I tried to implement it by pasting the code you gave me into a new dvb module but it doesn't seem to work.
Does this only reload xrefs that are unloaded or both ones that are loaded and unloaded?

Ideally, I want all the xrefs to be loaded, but I want the end result to be that when the reloading is done, all my xrefs are in their original unloaded/loaded states before the procedure. Message was edited by: flizit
Message 5 of 12
drudder
in reply to: felipe

I tried lsp - at first I would say no... but after gathering some other info - I guess you can...

you'll need to gather the XREF collection and cycle through them... here's how you find if it's unloaded...

Looking inside the XREF - you'll need to get the blocks collection and if the count of blocks in the XREF is zero (0)... then its unloaded...

VBA is much easier in that respect (to me anyway...)
Message 6 of 12
felipe
in reply to: felipe

You'll have to pardon me...my vba skills are somewhat lacking.
Does your vba code only determine if the xrefs are loaded or not or does it also perform the reload function on them as well?
Message 7 of 12
drudder
in reply to: felipe

oops - I left that part out - didn't I... here - this one works (I'm using it now)...

Sub NoUnloadXREF()
Dim myXref As AcadBlock
Dim Entity As AcadEntity
For Each myXref In ThisDrawing.Blocks
If myXref.IsXRef And myXref.Count = 0 Then
Dim xrName As String: xrName = UCase(myXref.Name)
myXref.Reload
End If
Next myXref
End Sub
Message 8 of 12
felipe
in reply to: felipe

That works great for the unloaded xrefs...I tweaked it so that it remembers to set them back to being unloaded...but what about the xrefs that are loaded? It seems to be ignoring them. I tried to adjust the code with an "else" statement but I keep getting errors.

Here's what I was working towards:

Sub NoUnloadXREF()
Dim myXref As AcadBlock
Dim Entity As AcadEntity
For Each myXref In ThisDrawing.Blocks
If myXref.IsXRef And myXref.Count = 0 Then
Dim xrName As String: xrName = UCase(myXref.Name)
myXref.Reload
myXref.Unload
Else
Dim xrName As String: xrName = UCase(myXref.Name)
myXref.Reload
End If
Next myXref
End Sub
Message 9 of 12
drudder
in reply to: felipe

I thought your original intent was to find the unloaded XREF drawings and reload them only...

So why do you want to reload the unloaded only to UNLOAD them again? Are you just trying to reload the already loaded XREF Drawings?
Message 10 of 12
felipe
in reply to: felipe

All this is in an effort to purge out layers that no longer exist in xrefed layers. I am leading up to doing a visretain flip of the switch coupled with a temporary layer state save to preserve how the drawing was setup before the process. I thought I mentioned in my posts my need to reload all xrefs, but restoring the state of those xrefs to their unload/load state. Sorry for the confusion.
Message 11 of 12
felipe
in reply to: felipe

I can't seem to figure out/understand why the processing of xrefs that are loaded in the drawing produce an error whereas the processing of xrefs that are unloaded in the drawing do not. I must be close but missing something, I suppose. Debugging seems to continually land on the "Next myXref" line with:
Run-time Error '-2147467259 (80004005)'
Automation error
Unspecified error

Here's the code:

Sub NoUnloadXREF()
Dim myXref As AcadBlock
Dim Entity As AcadEntity
Dim xrName As String
For Each myXref In ThisDrawing.Blocks
If myXref.IsXRef Then
xrName = UCase(myXref.Name)
If myXref.Count = 0 Then
myXref.Reload
myXref.Unload
Else
myXref.Reload
End If
End If
Next myXref
End Sub
Message 12 of 12
drudder
in reply to: felipe

Try this:

Sub NoUnloadXREF()
on error resume next 'This line will pound thru the errors
Dim myXref As AcadBlock
Dim Entity As AcadEntity
Dim xrName As String
For Each myXref In ThisDrawing.Blocks
If myXref.IsXRef Then
xrName = UCase(myXref.Name)
If myXref.Count = 0 Then
myXref.Reload
myXref.Unload
Else
myXref.Reload
End If
End If
Next myXref
End Sub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost