Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i want to change path of nested xrefs if it is unloaded, but my code only works to the parent xrefs only.
It works if we open dwg one by one manually (not batch mode).
Please help me to fix this, or give me solution to open all dwgs one by one as a batch process and run this code and close the dwg.
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 > 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 > 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
Solved! Go to Solution.