<?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: Absolute Path to Relative Path in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/absolute-path-to-relative-path/m-p/9841247#M18089</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/99495"&gt;@David_Prontnicki&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Relative path for "&lt;FONT color="#0000FF"&gt;R:\Projects\2018\18001808A\Survey\dwg\ASBLT\&lt;/FONT&gt;18001808A-FENCE As Built.dwg" will be "&lt;FONT color="#0000FF"&gt;R:\Projects\2018\18001808A\Survey\dwg\ASBLT\&lt;/FONT&gt;&lt;STRONG&gt;Survey\dwg\ASBLT\18001808A-BaseFile.dwg&lt;/STRONG&gt;"&lt;/P&gt;
&lt;P&gt;Are you sure that you have file with such path?&lt;/P&gt;</description>
    <pubDate>Mon, 02 Nov 2020 22:40:09 GMT</pubDate>
    <dc:creator>Alexander.Rivilis</dc:creator>
    <dc:date>2020-11-02T22:40:09Z</dc:date>
    <item>
      <title>Absolute Path to Relative Path</title>
      <link>https://forums.autodesk.com/t5/net-forum/absolute-path-to-relative-path/m-p/9841218#M18088</link>
      <description>&lt;P&gt;I found an old post on devBlog about changing absolute paths to relative paths for XREFs. Seems straight forward but I keep getting a eFileAccessEr during the Reload Xref's portion. I will eventually turn this into a batch processor to run on all drawing in a folder but for now I'm just trying to get the core of it done.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you will see I take the full xref drawing name and path from the ReadDwgFile drawing file. For Example: R:\Projects\2018\18001808A\Survey\dwg\ASBLT\18001808A-BaseFile.dwg (This is the xref in the ReadDwgFile)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then in this example I want it to set the relative path to .\Survey\dwg\ASBLT\18001808A-BaseFile.dwg&lt;/P&gt;&lt;P&gt;So it will start at that top folder and look down for the xref file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The program sets the new paths during debugging but when it gets to reloading them, that's where the error appears.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;&amp;lt;Autodesk.AutoCAD.Runtime.CommandMethod("ChangeXRefPath")&amp;gt;
    Public Sub ChangeXRefPathMethod()

        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim collection As ObjectIdCollection = New ObjectIdCollection()

        Using db As Database = New Database(False, True)

            db.ReadDwgFile("R:\Projects\2018\18001808A\Survey\dwg\ASBLT\18001808A-FENCE As Built.dwg", FileOpenMode.OpenForReadAndWriteNoShare, False, "")

            Using tr As Transaction = db.TransactionManager.StartTransaction()

                Dim bt As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)

                For Each btrId As ObjectId In bt

                    Dim btr As BlockTableRecord = TryCast(tr.GetObject(btrId, OpenMode.ForRead), BlockTableRecord)

                    If btr.IsFromExternalReference Then

                        btr.UpgradeOpen()
                        Dim oldPath As String = btr.PathName

                        Dim oldPathArray As String() = oldPath.Split("\"c)
                        Dim oldPathRoot As String = oldPathArray(0) &amp;amp; "\" &amp;amp; oldPathArray(1) &amp;amp; "\" &amp;amp; oldPathArray(2) &amp;amp; "\" &amp;amp; oldPathArray(3)

                        Dim newPath As String = oldPath.Replace(oldPathRoot, ".")
                        btr.PathName = newPath
                        collection.Add(btrId)
                        ed.WriteMessage(String.Format("{0}Old Path : {1} New Path : {2}", Environment.NewLine, oldPath, newPath))

                    End If

                Next

                tr.Commit()

            End Using

            If collection.Count &amp;gt; 0 Then

                db.ReloadXrefs(collection) '&amp;lt;--- errors here

            End If

            db.SaveAs(db.OriginalFileName, True, db.OriginalFileVersion, db.SecurityParameters)

        End Using

    End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 22:29:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/absolute-path-to-relative-path/m-p/9841218#M18088</guid>
      <dc:creator>David_Prontnicki</dc:creator>
      <dc:date>2020-11-02T22:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Absolute Path to Relative Path</title>
      <link>https://forums.autodesk.com/t5/net-forum/absolute-path-to-relative-path/m-p/9841247#M18089</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/99495"&gt;@David_Prontnicki&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Relative path for "&lt;FONT color="#0000FF"&gt;R:\Projects\2018\18001808A\Survey\dwg\ASBLT\&lt;/FONT&gt;18001808A-FENCE As Built.dwg" will be "&lt;FONT color="#0000FF"&gt;R:\Projects\2018\18001808A\Survey\dwg\ASBLT\&lt;/FONT&gt;&lt;STRONG&gt;Survey\dwg\ASBLT\18001808A-BaseFile.dwg&lt;/STRONG&gt;"&lt;/P&gt;
&lt;P&gt;Are you sure that you have file with such path?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 22:40:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/absolute-path-to-relative-path/m-p/9841247#M18089</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2020-11-02T22:40:09Z</dc:date>
    </item>
  </channel>
</rss>

