Is it possible to change the saved xref path without reattaching the xref

Is it possible to change the saved xref path without reattaching the xref

Anonymous
Not applicable
767 Views
1 Reply
Message 1 of 2

Is it possible to change the saved xref path without reattaching the xref

Anonymous
Not applicable

Hi,

 

Is it possible to change the saved xref path without reattaching the xref

 

Please guide me

 

Regards,

Raman

0 Likes
Accepted solutions (1)
768 Views
1 Reply
Reply (1)
Message 2 of 2

BrentBurgess1980
Collaborator
Collaborator
Accepted solution

Try this - I haven' tested it yet though.

public static void Repath(Database db, string xrefName, string newPath)
            {
            if (string.IsNullOrEmpty(newPath))
                {
                throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.FileNotFound, "The path can not be found");
                }

            if (!File.Exists(newPath))
                {
                throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.FileNotFound, "The file can not be found");
                }

            BlockTableRecord btr = default(BlockTableRecord);
            using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                XrefGraph DbXrGraph = db.GetHostDwgXrefGraph(true);
                XrefGraphNode XrGraphNode = null;

                XrGraphNode = DbXrGraph.GetXrefNode(xrefName);
                btr = (BlockTableRecord)tr.GetObject(XrGraphNode.BlockTableRecordId, OpenMode.ForWrite);
                btr.PathName = newPath;
                tr.Commit();
                }
            }

 

0 Likes