<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Xrefs Loaded or Unloaded in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352782#M74333</link>
    <description>If the XREf is not resolved (unloaded or not found),&lt;BR /&gt;
then attempting to reference the XRefDatabase property&lt;BR /&gt;
of the corresponding Block object for the Xref will&lt;BR /&gt;
raise an error with the description "No database"&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Paynec" &lt;PAYNEC&gt; wrote in message&lt;BR /&gt;
news:f0dcb33.-1@WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; Need an example in VBA of checking to see if Xrefs are Loaded or Unloaded.&lt;BR /&gt;
&amp;gt; I can't seem to find anything for this.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Chris Payne&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/PAYNEC&gt;</description>
    <pubDate>Fri, 10 May 2002 09:26:50 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2002-05-10T09:26:50Z</dc:date>
    <item>
      <title>Xrefs Loaded or Unloaded</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352781#M74332</link>
      <description>Need an example in VBA of checking to see if Xrefs are Loaded or Unloaded.&lt;BR /&gt;
&lt;BR /&gt;
I can't seem to find anything for this.&lt;BR /&gt;
&lt;BR /&gt;
Chris Payne</description>
      <pubDate>Fri, 10 May 2002 06:36:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352781#M74332</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2002-05-10T06:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: Xrefs Loaded or Unloaded</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352782#M74333</link>
      <description>If the XREf is not resolved (unloaded or not found),&lt;BR /&gt;
then attempting to reference the XRefDatabase property&lt;BR /&gt;
of the corresponding Block object for the Xref will&lt;BR /&gt;
raise an error with the description "No database"&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Paynec" &lt;PAYNEC&gt; wrote in message&lt;BR /&gt;
news:f0dcb33.-1@WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; Need an example in VBA of checking to see if Xrefs are Loaded or Unloaded.&lt;BR /&gt;
&amp;gt; I can't seem to find anything for this.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Chris Payne&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/PAYNEC&gt;</description>
      <pubDate>Fri, 10 May 2002 09:26:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352782#M74333</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2002-05-10T09:26:50Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352783#M74334</link>
      <description>Thanks, Tony, I think that will fill my needs.&lt;BR /&gt;
&lt;BR /&gt;
Mike Weaver&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO at="" caddzone="" dot="" com=""&gt; wrote in message&lt;BR /&gt;
news:D2830174F828C8559BF56BEC9953DACF@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; If the XREf is not resolved (unloaded or not found),&lt;BR /&gt;
&amp;gt; then attempting to reference the XRefDatabase property&lt;BR /&gt;
&amp;gt; of the corresponding Block object for the Xref will&lt;BR /&gt;
&amp;gt; raise an error with the description "No database"&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; "Paynec" &lt;PAYNEC&gt; wrote in message&lt;BR /&gt;
&amp;gt; news:f0dcb33.-1@WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; &amp;gt; Need an example in VBA of checking to see if Xrefs are Loaded or&lt;BR /&gt;
Unloaded.&lt;BR /&gt;
&amp;gt; &amp;gt; I can't seem to find anything for this.&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; Chris Payne&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/PAYNEC&gt;&lt;/TONY.TANZILLO&gt;</description>
      <pubDate>Fri, 10 May 2002 10:35:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352783#M74334</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2002-05-10T10:35:47Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352784#M74335</link>
      <description>How's this Tony?&lt;BR /&gt;
&lt;BR /&gt;
Public Function IsXrefResolved(xref As AcadExternalReference) As Boolean&lt;BR /&gt;
    'If the XREf is not resolved (unloaded or not found),&lt;BR /&gt;
    'then attempting to reference the XRefDatabase property&lt;BR /&gt;
    'of the corresponding Block object for the Xref will&lt;BR /&gt;
    'raise an error with the description "No database".&lt;BR /&gt;
    On Error GoTo ErrHandler&lt;BR /&gt;
    Dim objBlock As AcadBlock&lt;BR /&gt;
    Dim cnt As Integer&lt;BR /&gt;
    &lt;BR /&gt;
    Set objBlock = ThisDrawing.Blocks(xref.Name)&lt;BR /&gt;
    If objBlock.IsXRef = True Then&lt;BR /&gt;
        'this is just to access the db,&lt;BR /&gt;
        'an error will occur if not loaded&lt;BR /&gt;
        cnt = objBlock.XRefDatabase.Blocks.Count&lt;BR /&gt;
        IsXrefResolved = True&lt;BR /&gt;
    Else&lt;BR /&gt;
        IsXrefResolved = False&lt;BR /&gt;
    End If&lt;BR /&gt;
    Exit Function&lt;BR /&gt;
    &lt;BR /&gt;
ErrHandler:&lt;BR /&gt;
    If Err.Number = -2145386390 Then&lt;BR /&gt;
        IsXrefResolved = False&lt;BR /&gt;
    Else&lt;BR /&gt;
        MsgBox Err.Number &amp;amp; vbCrLf &amp;amp; Err.Description, vbCritical, "function IsXrefResolved"&lt;BR /&gt;
    End If&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
-Ed</description>
      <pubDate>Fri, 10 May 2002 10:54:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352784#M74335</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2002-05-10T10:54:21Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352785#M74336</link>
      <description>That's fine but there are a few rules that&lt;BR /&gt;
you should follow when writing 'generic" or&lt;BR /&gt;
modular code that is designed to be resuable&lt;BR /&gt;
in many scenarios.&lt;BR /&gt;
&lt;BR /&gt;
The most important thing is that you avoid&lt;BR /&gt;
binding your code to the Active document, vis&lt;BR /&gt;
a vis the use of 'ThisDrawing'.&lt;BR /&gt;
&lt;BR /&gt;
In this particular case, you're passing in an&lt;BR /&gt;
AcadExternalReference to your function, but&lt;BR /&gt;
you are using the ThisDrawing variable to get&lt;BR /&gt;
the corresponding block. This is wrong, and&lt;BR /&gt;
impedes code modularity (not to mention the&lt;BR /&gt;
fact that you are making the assumption that&lt;BR /&gt;
the XRef is in the ActiveDocument).&lt;BR /&gt;
&lt;BR /&gt;
What if the XRef isn't in the ActiveDocument?&lt;BR /&gt;
&lt;BR /&gt;
What if it's in an AxDbDocument, or another&lt;BR /&gt;
document open in the editor (in this case, I&lt;BR /&gt;
don't think an AcadExternalReference would&lt;BR /&gt;
appear in an AxDbDocument, but the general&lt;BR /&gt;
concept I'm trying to convey here applies to any&lt;BR /&gt;
type of AcadEntity that you would pass into a&lt;BR /&gt;
modular function or sub).&lt;BR /&gt;
&lt;BR /&gt;
So, consider modifying the code thusly:&lt;BR /&gt;
&lt;BR /&gt;
Public Function IsResolved(XRef As AcadExternalReference) As Boolean&lt;BR /&gt;
   On Error Goto Catch&lt;BR /&gt;
   Dim objBlock As AcadBlock&lt;BR /&gt;
&lt;BR /&gt;
   ' Pay attention to the next line, it avoids&lt;BR /&gt;
   ' using ThisDrawing, and gets the document&lt;BR /&gt;
   ' from the XRef parameter:&lt;BR /&gt;
&lt;BR /&gt;
   Set objBlock = XRef.Document.Blocks(XRef.Name)&lt;BR /&gt;
&lt;BR /&gt;
   objBlock.XRefDatabase.Blocks&lt;BR /&gt;
   IsResolved = True&lt;BR /&gt;
   Exit Sub&lt;BR /&gt;
Catch:&lt;BR /&gt;
   IsResolved = False&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
With this change, you can now use this code on any&lt;BR /&gt;
AcadExternalReference because the code correctly&lt;BR /&gt;
avoids binding to the active document in the AutoCAD&lt;BR /&gt;
editor.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Ed_Jobe" &lt;ELJOBE&gt; wrote in message news:f0dcb33.5@WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; How's this Tony?&lt;BR /&gt;
&amp;gt; Public Function IsXrefResolved(xref As AcadExternalReference) As Boolean&lt;BR /&gt;
&amp;gt;     'If the XREf is not resolved (unloaded or not found),&lt;BR /&gt;
&amp;gt;     'then attempting to reference the XRefDatabase property&lt;BR /&gt;
&amp;gt;     'of the corresponding Block object for the Xref will&lt;BR /&gt;
&amp;gt;     'raise an error with the description "No database".&lt;BR /&gt;
&amp;gt;     On Error GoTo ErrHandler&lt;BR /&gt;
&amp;gt;     Dim objBlock As AcadBlock&lt;BR /&gt;
&amp;gt;     Dim cnt As Integer&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Set objBlock = ThisDrawing.Blocks(xref.Name)&lt;BR /&gt;
&amp;gt;     If objBlock.IsXRef = True Then&lt;BR /&gt;
&amp;gt;         'this is just to access the db,&lt;BR /&gt;
&amp;gt;         'an error will occur if not loaded&lt;BR /&gt;
&amp;gt;         cnt = objBlock.XRefDatabase.Blocks.Count&lt;BR /&gt;
&amp;gt;         IsXrefResolved = True&lt;BR /&gt;
&amp;gt;     Else&lt;BR /&gt;
&amp;gt;         IsXrefResolved = False&lt;BR /&gt;
&amp;gt;     End If&lt;BR /&gt;
&amp;gt;     Exit Function&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; ErrHandler:&lt;BR /&gt;
&amp;gt;     If Err.Number = -2145386390 Then&lt;BR /&gt;
&amp;gt;         IsXrefResolved = False&lt;BR /&gt;
&amp;gt;     Else&lt;BR /&gt;
&amp;gt;         MsgBox Err.Number &amp;amp; vbCrLf &amp;amp; Err.Description, vbCritical,&lt;BR /&gt;
"function IsXrefResolved"&lt;BR /&gt;
&amp;gt;     End If&lt;BR /&gt;
&amp;gt; End Function&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; -Ed&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/ELJOBE&gt;</description>
      <pubDate>Fri, 10 May 2002 11:39:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352785#M74336</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2002-05-10T11:39:02Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352786#M74337</link>
      <description>Good...assumptions can get ya. I get used to working in my own world sometimes. Thanks.</description>
      <pubDate>Fri, 10 May 2002 12:13:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352786#M74337</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2002-05-10T12:13:47Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352787#M74338</link>
      <description>In your function, I get an error at "objBlock.XRefDatabase.Blocks", "invalid use of property". That's why I had it checking the Count property.</description>
      <pubDate>Fri, 10 May 2002 12:24:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xrefs-loaded-or-unloaded/m-p/352787#M74338</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2002-05-10T12:24:55Z</dc:date>
    </item>
  </channel>
</rss>

