Message 1 of 12
ReadDwgFile for layer purge restore Xref layer settings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I am running below code to purge the layers from drawing by opening the file in ReadDwgFile method.
After running the code, when I open the file all the xref's layer settings is reloaded from the reference drawing.
I checked VISRETAIN variable and it is set to 1 only.
This is the steps I followed.
- From the attached zip file open Master.dwg.
- There is an xref called Xref.dwg attached to Master.dwg
- Change the Xref layer color in the Master.dwg.
- Save and close the Master.dwg
- From any other drawing run the command LAYER-PURGE-TEST and select Master.dwg to purge.
- Open Master.dwg to check whether the xref layer color has changed.
For me after running this command the xref layer settings are always changing.
Xref layer settings are restored to reference drawing and the VISRETAIN value is 1 only.
Also another issue is drawing preview is blank/nothing even I set retainthumbnail to True.
Side_dbase.RetainOriginalThumbnailBitmap = True
Here's the code
Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Runtime Public Class Class1 <CommandMethod("LAYER-PURGE-TEST")> _ Public Sub Layer_Purge() Dim f_opts As PromptOpenFileOptions = New PromptOpenFileOptions("Open") f_opts.Filter = "Drawing (*.dwg)|*.dwg" Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor Dim rslt As PromptFileNameResult = ed.GetFileNameForOpen(f_opts) If rslt.Status = PromptStatus.OK Then Dim Side_dbase As Database = New Database(False, False) Try Side_dbase.ReadDwgFile(rslt.StringResult, FileOpenMode.OpenForReadAndWriteNoShare, True, "") Side_dbase.RetainOriginalThumbnailBitmap = True Side_dbase.CloseInput(True) Purge_Layers(Side_dbase) Side_dbase.SaveAs(rslt.StringResult, False, DwgVersion.Current, Side_dbase.SecurityParameters) Side_dbase.Dispose() Catch ex As Exception End Try End If ed.WriteMessage(vbCrLf + " Purge Finished") End Sub 'This is the function using to Purge the Layers.
'---------------------------------------------------------------------------------------------------- Public Shared Function Purge_Layers(ByVal db As Database) As String Dim count As String = "0" Dim tm1 As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager Dim prmtr As ProgressMeter = New ProgressMeter Using TR3 As Transaction = tm1.StartTransaction Dim Id_to_Purge = New ObjectIdCollection() Dim Layer_Table As LayerTable = TR3.GetObject(db.LayerTableId, OpenMode.ForRead) For Each obid As ObjectId In Layer_Table If obid.IsValid Then Id_to_Purge.Add(obid) End If Next db.Purge(Id_to_Purge) count = Id_to_Purge.Count.ToString prmtr.Start("Deleting Layers : ") prmtr.SetLimit(Id_to_Purge.Count) For Each obid_del As ObjectId In Id_to_Purge Dim obj As DBObject = TR3.GetObject(obid_del, OpenMode.ForWrite) obj.Erase() prmtr.MeterProgress() Next prmtr.Stop() TR3.Commit() End Using Return count End Function End Class