<?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: applying plot styles to layers in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/applying-plot-styles-to-layers/m-p/3201736#M58736</link>
    <description>&lt;P&gt;It appears nobody actually knows how to apply a plot style to a layer properly - there must be someone out there who has the infinite wisdom to be able to answer this - please!&lt;/P&gt;</description>
    <pubDate>Sun, 23 Oct 2011 19:55:07 GMT</pubDate>
    <dc:creator>EvolveTraining</dc:creator>
    <dc:date>2011-10-23T19:55:07Z</dc:date>
    <item>
      <title>applying plot styles to layers</title>
      <link>https://forums.autodesk.com/t5/net-forum/applying-plot-styles-to-layers/m-p/3199500#M58735</link>
      <description>&lt;P&gt;I am truely stuck, someone help me please.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As the subject states, I am trying to apply a plotstyle to a layer. I can create the layer and apply a plot style but as soon as I create another layer with a different plotstyle, the layers I previously created lose their plot style (it appears to be removed from the drawing)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried workarounds such as placing an object and applying a plotstyle then deleting that plot style and that still doesnt seem to append it to the drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is my code so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    Public Sub addPltStToLayer(ByVal id As ObjectId, ByVal pltsty As String)
        Dim thisDrawing As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim thisDB As Database = thisDrawing.Database
        Dim trans As Transaction = thisDB.TransactionManager.StartTransaction
        Using locker As DocumentLock = thisDrawing.LockDocument

            Dim dict As DictionaryWithDefaultDictionary = trans.GetObject(thisDB.PlotStyleNameDictionaryId, DatabaseServices.OpenMode.ForRead)
            Dim ltr As LayerTableRecord = trans.GetObject(id, DatabaseServices.OpenMode.ForWrite)
            ltr.PlotStyleNameId = dict.GetAt(pltsty)

        End Using
        trans.Commit()
        trans.Dispose()

    End Sub

    Public Sub addPstyle()

        Dim thisDrawing As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim thisDB As Database = thisDrawing.Database
        Using trans As Transaction = thisDB.TransactionManager.StartTransaction

            Using placeHold As PlaceHolder = New PlaceHolder
                Dim dict As DictionaryWithDefaultDictionary = trans.GetObject(thisDB.PlotStyleNameDictionaryId, DatabaseServices.OpenMode.ForWrite)

                If dict.Contains(PltStBut.Text) Then
                    'do nothing, its already here
                Else
                    dict.SetAt(PltStBut.Text, thisDB.AcadDatabase)
                End If
                trans.Commit()
            End Using
        End Using

    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2011 20:46:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/applying-plot-styles-to-layers/m-p/3199500#M58735</guid>
      <dc:creator>EvolveTraining</dc:creator>
      <dc:date>2011-10-20T20:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: applying plot styles to layers</title>
      <link>https://forums.autodesk.com/t5/net-forum/applying-plot-styles-to-layers/m-p/3201736#M58736</link>
      <description>&lt;P&gt;It appears nobody actually knows how to apply a plot style to a layer properly - there must be someone out there who has the infinite wisdom to be able to answer this - please!&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2011 19:55:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/applying-plot-styles-to-layers/m-p/3201736#M58736</guid>
      <dc:creator>EvolveTraining</dc:creator>
      <dc:date>2011-10-23T19:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: applying plot styles to layers</title>
      <link>https://forums.autodesk.com/t5/net-forum/applying-plot-styles-to-layers/m-p/3201790#M58737</link>
      <description>&lt;P&gt;After well over 7 hours of coding a bazillion different methods of trying to get this working, I got it!!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If and when I get a chance to tidy the code, I will do but this is rough and ready for anyone else stuck&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final code (There is, of course, a dialog behind the code which gives the layer properties):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Private Sub AddLayer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'1. append plot style to drawing
addPlotStyle()
'2. add layer
Dim layID As ObjectId = addLayerToDWG()
'2. AddPlotStyleTo Layer
appendPStyle(layID)
End Sub

Public Sub appendPStyle(ByVal layID As ObjectId)

        Dim thisDrawing As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim thisDB As Database = thisDrawing.Database
        If thisDB.PlotStyleMode = False Then
            Using locker As DocumentLock = thisDrawing.LockDocument
                Using trans As Transaction = thisDB.TransactionManager.StartTransaction
                    Dim dict As DictionaryWithDefaultDictionary = trans.GetObject(thisDB.PlotStyleNameDictionaryId, DatabaseServices.OpenMode.ForRead)
                    Dim ltr As LayerTableRecord = trans.GetObject(layID, DatabaseServices.OpenMode.ForWrite)
                    If dict.Contains(PltStBut.Text) = True Then
                        ltr.PlotStyleNameId = dict.GetAt(PltStBut.Text)
                    End If
                    trans.Commit()

                End Using
            End Using

        End If

    End Sub


    Public Sub addPlotStyle()

        Dim thisDrawing As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim thisDB As Database = thisDrawing.Database
        Using locker As DocumentLock = thisDrawing.LockDocument
            Using trans As Transaction = thisDB.TransactionManager.StartTransaction
                Using plHldr As PlaceHolder = New PlaceHolder
                    Dim dict As DictionaryWithDefaultDictionary = trans.GetObject(thisDB.PlotStyleNameDictionaryId, DatabaseServices.OpenMode.ForWrite)
                    If dict.Contains(PltStBut.Text) = True Then

                        dict.SetAt(PltStBut.Text, plHldr)
                        trans.Commit()
                    End If
                End Using
            End Using
        End Using


    End Sub

    Public Function addLayerToDWG()
        'create layer here
        Dim thisDrawing As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim thisDB As Database = thisDrawing.Database
        Dim trans As Transaction = thisDB.TransactionManager.StartTransaction
        Dim ed As Editor = thisDrawing.Editor
        Dim lt As LayerTable = trans.GetObject(thisDB.LayerTableId, DatabaseServices.OpenMode.ForRead)

        'else continue and create layer
        Dim lockMeUp As DocumentLock = thisDrawing.LockDocument
        Dim newLay As New LayerTableRecord
        newLay.Name = LaNmVal.Text

        newLay.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Colors.ColorMethod.ByAci, CType(Strings.Right(ColPickBut.Text, Len(ColPickBut.Text) - 7), Short))
        If lWeightBut.Text = "Default" Then
            newLay.LineWeight = -3
        Else
            newLay.LineWeight = Replace(lWeightBut.Text, ".", "")
        End If

        'add the linetype
        Dim acLinTbl As LinetypeTable
        acLinTbl = trans.GetObject(thisDB.LinetypeTableId, DatabaseServices.OpenMode.ForRead)
        If acLinTbl.Has(LStyleList.SelectedItem) = True Then
            'Set the linetype for the layer
            newLay.LinetypeObjectId = acLinTbl(LStyleList.SelectedItem)
        End If

        lt.UpgradeOpen()
        lt.Add(newLay)
        trans.AddNewlyCreatedDBObject(newLay, True)
        'add layer description
        newLay.Description = DescVal.Text

        trans.Commit()
        lockMeUp.Dispose()
        trans.Dispose()

        Return newLay.Id

    End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2011 23:12:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/applying-plot-styles-to-layers/m-p/3201790#M58737</guid>
      <dc:creator>EvolveTraining</dc:creator>
      <dc:date>2011-10-23T23:12:42Z</dc:date>
    </item>
  </channel>
</rss>

