Message 1 of 2
Plot style is being used but it cannot find my style

Not applicable
03-25-2020
05:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I have a routine below that i am using to copy the Plot Styles and layer colors and states in from a list I extracted from my first set up drawing. For whatever reason, I have to go and use each of the styles at least once so that it will find them in the stb file being applied. The funny thing is that at the end, despite me manually and automatically applying the styles, I am able to purge the stb file. Does anyone have any understanding of what i am doing wrong? Any help would be much appreciated as it is driving me around the twist.
<CommandMethod("ImportLayerStyles")> Public Sub ImportLayerStyles()
Dim lslist As New List(Of Laystate)
Dim ls As New Laystate
Dim errpt As String = "Import plotstyle"
' Get the plotstyle
If db.PlotStyleMode = False Then
Using tr As Transaction = db.TransactionManager.StartTransaction()
Using hldr As PlaceHolder = New PlaceHolder()
Dim d As DictionaryWithDefaultDictionary = CType(tr.GetObject(db.PlotStyleNameDictionaryId, OpenMode.ForWrite), DictionaryWithDefaultDictionary)
d.SetAt("MR_Full Size Colour.stb", hldr)
tr.Commit()
End Using
End Using
End If
' open the file
Dim ofd As New Autodesk.AutoCAD.Windows.OpenFileDialog("Select Template", Nothing, "txt", "PlotStyles", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles)
Dim dr As System.Windows.Forms.DialogResult = ofd.ShowDialog()
If dr <> System.Windows.Forms.DialogResult.OK Then
Return
End If
Dim sName As String = ofd.Filename
Dim dictLays As New Dictionary(Of String, String)
Dim sr As StreamReader = New StreamReader(sName)
Dim line As String
Try
errpt = "Writing"
If System.IO.File.Exists(sName) = True Then
While sr.Peek() <> -1
line = sr.ReadLine()
Dim sspl() As String = line.Split("=")
ls.sName = sspl(0)
ls.sStyle = sspl(1)
ls.sFrozen = sspl(2)
ls.iColour = sspl(3)
lslist.Add(ls)
End While
sr.Close()
End If
Catch ex As System.Exception
ed.WriteMessage(vbLf & ex.Message)
End Try
Dim psmode As Boolean = db.PlotStyleMode
' True = ctb, false = stb
'ed.WriteMessage(vbLf & "PSMODE = {0}", db.PlotStyleMode)
'ed.WriteMessage(vbLf & "Transaction")
Try
Using transaction As Transaction = db.TransactionManager.StartTransaction()
Dim symTable As SymbolTable = CType(transaction.GetObject(db.LayerTableId, OpenMode.ForWrite), SymbolTable)
For Each id As ObjectId In symTable
Dim symbol As LayerTableRecord = CType(transaction.GetObject(id, OpenMode.ForWrite), LayerTableRecord)
Dim sLay As String = symbol.Name
Dim idLay As ObjectId = Nothing
errpt = "Layer " & sLay
Dim q = (From l In lslist
Where l.sName.Equals(sLay)
Select l).First
'sw.WriteLine(sLay)
Try
If Not IsNothing(q) Then
Select Case db.PlotStyleMode
Case False : errpt = "Plotstyle " & q.sStyle : symbol.PlotStyleName = q.sStyle
End Select
errpt = "Freezing Layer " & sLay
If q.sFrozen.Equals("F") Then
ed.WriteMessage(vbLf & "Freezing {0}", sLay)
If Not symbol.IsFrozen = True Then symbol.IsFrozen = True
End If
errpt = "Colouring Layer " & sLay
symbol.Color = Color.FromColorIndex(ColorMethod.ByAci, q.iColour)
End If
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(vbLf & "Error: " & errpt)
End Try
Next
transaction.Commit()
End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
End Try
End Sub