eFileAccessErr at db.ReloadXrefs()

New to this and understanding a lot of things as I develop this. Basically, I have a dwg file with some Xrefs linked in whose links might be broken. I wish to refresh all the Xrefs but when I do this, it gives me that eFileAccessErr error. Below is my code and any hint will be much appreciated.

with adoc.LockDocument():
	with adoc.Database as db:
		xrefsIds = ObjectIdCollection()	
		with db.TransactionManager.StartTransaction() as t:
			xg = db.GetHostDwgXrefGraph('true')		
			xrefcount = xg.NumNodes
			for x in range(xrefcount):
				xrNode = xg.GetXrefNode(x)
				xrefid = xrNode.BlockTableRecordId
				if str(xrefid) != "(0)":

@Paolo_Emilio_Serra1 @mzjensen any insights you can provide on this? Stuck on this for long now.

Looks as though this may help.

Realigned my script and still getting the error. I think its something to do with the document or maybe the references I missing. But here is the full code if that helps you debug for me:

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

with adoc.LockDocument():
	with adoc.Database as db:
		with db.TransactionManager.StartTransaction() as tr:
			ids = ObjectIdCollection();
			table = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
			for id in table:
				record = tr.GetObject(id, OpenMode.ForRead)
				if record.IsFromExternalReference:
		if ids.Count != 0:

# Assign your output to the OUT variable.
OUT = ids

If I comment out the db.Reload the output comes out to be fine. The issue only exists at that line.

Are you sure you need to Lock the doc? I don’t see that step in the C# example?

Hi @Gauzdx

I have just tried your python and it seems to work fine:

Try adding tr.Commit at the end:

1 Like

Thank you. I think I now the issue. I tried with a sample file and it worked. The issue only occurs when the Xref is ‘Not Found’ which for most cases is stored in a network directory for us. I will have to put in a condition to detach those Xref if this occurs by checking its status.