<?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 change xref path (batch) in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/change-xref-path-batch/m-p/9001543#M21375</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;Trying to change xref path if xref is unloaded, but it only reloads, path is not changing.&lt;/P&gt;&lt;P&gt;please help me to figure it out.&lt;/P&gt;&lt;PRE&gt;Private Sub button_Publish_Click(sender As Object, e As EventArgs) Handles button_Publish.Click

        Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

               If openFile1.FileNames.Length &amp;gt; 0 Then
            Dim strFile As String
            For Each strFile In openFile1.FileNames

                Using db As Database = New Database(False, True)
                    db.ReadDwgFile(strFile, FileOpenMode.OpenForReadAndAllShare, False, Nothing)

                    Dim doc As Document = Application.DocumentManager.MdiActiveDocument
                    Dim collection As ObjectIdCollection = New ObjectIdCollection()

                    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 And btr.IsUnloaded Then

                                Collection.Add(btrId)
                                btr.UpgradeOpen()
                                Dim oldPath As String = btr.PathName
                                Dim newpath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Temp.dwg")
                                btr.PathName = newpath
                                ed.WriteMessage(String.Format("{0}Old Path : {1} New Path : {2}", Environment.NewLine, oldPath, newpath))
                            End If
                        Next
                        If Collection.Count &amp;gt; 0 Then
                            db.ReloadXrefs(Collection)
                        End If
                        tr.Commit()
                    End Using
                    db.SaveAs(db.OriginalFileName, True, db.OriginalFileVersion, db.SecurityParameters)
                End Using


            Next
        End If

    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Sep 2019 16:00:54 GMT</pubDate>
    <dc:creator>yoitsarun</dc:creator>
    <dc:date>2019-09-02T16:00:54Z</dc:date>
    <item>
      <title>change xref path (batch)</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-xref-path-batch/m-p/9001543#M21375</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;Trying to change xref path if xref is unloaded, but it only reloads, path is not changing.&lt;/P&gt;&lt;P&gt;please help me to figure it out.&lt;/P&gt;&lt;PRE&gt;Private Sub button_Publish_Click(sender As Object, e As EventArgs) Handles button_Publish.Click

        Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

               If openFile1.FileNames.Length &amp;gt; 0 Then
            Dim strFile As String
            For Each strFile In openFile1.FileNames

                Using db As Database = New Database(False, True)
                    db.ReadDwgFile(strFile, FileOpenMode.OpenForReadAndAllShare, False, Nothing)

                    Dim doc As Document = Application.DocumentManager.MdiActiveDocument
                    Dim collection As ObjectIdCollection = New ObjectIdCollection()

                    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 And btr.IsUnloaded Then

                                Collection.Add(btrId)
                                btr.UpgradeOpen()
                                Dim oldPath As String = btr.PathName
                                Dim newpath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Temp.dwg")
                                btr.PathName = newpath
                                ed.WriteMessage(String.Format("{0}Old Path : {1} New Path : {2}", Environment.NewLine, oldPath, newpath))
                            End If
                        Next
                        If Collection.Count &amp;gt; 0 Then
                            db.ReloadXrefs(Collection)
                        End If
                        tr.Commit()
                    End Using
                    db.SaveAs(db.OriginalFileName, True, db.OriginalFileVersion, db.SecurityParameters)
                End Using


            Next
        End If

    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2019 16:00:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-xref-path-batch/m-p/9001543#M21375</guid>
      <dc:creator>yoitsarun</dc:creator>
      <dc:date>2019-09-02T16:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: change xref path (batch)</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-xref-path-batch/m-p/9002521#M21376</link>
      <description>&lt;P&gt;any solution?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 07:50:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-xref-path-batch/m-p/9002521#M21376</guid>
      <dc:creator>yoitsarun</dc:creator>
      <dc:date>2019-09-03T07:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: change xref path (batch)</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-xref-path-batch/m-p/9006381#M21377</link>
      <description>&lt;P&gt;Please help&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 18:38:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-xref-path-batch/m-p/9006381#M21377</guid>
      <dc:creator>yoitsarun</dc:creator>
      <dc:date>2019-09-04T18:38:34Z</dc:date>
    </item>
  </channel>
</rss>

