.NET

Reply
Valued Contributor
RamanSBV
Posts: 88
Registered: ‎02-28-2012
Message 1 of 2 (324 Views)
Accepted Solution

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

324 Views, 1 Replies
08-29-2012 12:49 AM

Hi,

 

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

 

Please guide me

 

Regards,

Raman

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();
}
}

 

Mentor
BrentBurgess1980
Posts: 162
Registered: ‎06-16-2008
Message 2 of 2 (309 Views)

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

08-29-2012 05:26 PM in reply to: RamanSBV

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();
                }
            }

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!