<?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: Layer control in paperspace viewports with VB.net in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/layer-control-in-paperspace-viewports-with-vb-net/m-p/3738568#M51995</link>
    <description>&lt;P&gt;Found this one in my codes, author unknown,&lt;/P&gt;&lt;P&gt;try it for current viewport in Paper space&lt;/P&gt;&lt;PRE&gt;    &amp;lt;CommandMethod("VpLayersMan")&amp;gt; _
        Public Sub TestLayerFreeze()
           '' add layer names to freeze/ thaw in paperspace viewports separated by commas

            Dim layers As List(Of String) = {"Wall", "ANNO-TEXT"}.ToList()''&amp;lt;-- layers for test

            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            Dim ed As Editor = doc.Editor

            Dim db As Database = doc.Database

            Dim idLay As ObjectId

            Dim idLayTblRcd As ObjectId

            Dim lt As LayerTableRecord

            Dim layOut As Layout

            Dim tm As Autodesk.AutoCAD.ApplicationServices.TransactionManager = db.TransactionManager

            Dim ta As Transaction = tm.StartTransaction()

            Try
                Dim acLayoutMgr As LayoutManager

                acLayoutMgr = LayoutManager.Current

                Dim layDict As DBDictionary = DirectCast(ta.GetObject(db.LayoutDictionaryId, OpenMode.ForRead, False), DBDictionary)

                For Each itmdict As DBDictionaryEntry In layDict

                    layOut = DirectCast(ta.GetObject(itmdict.Value, OpenMode.ForRead, False), Layout)

                    ed.WriteMessage(vbLf + "Layout: {0}" + vbLf, layOut.LayoutName)

                    If layOut.LayoutName &amp;lt;&amp;gt; "Model" Then

                        acLayoutMgr.CurrentLayout = layOut.LayoutName

                        Dim ltt As LayerTable = DirectCast(ta.GetObject(db.LayerTableId, OpenMode.ForRead, False), LayerTable)

                        For Each lname As String In layers

                            idLay = ltt(lname)

                            lt = ta.GetObject(idLay, OpenMode.ForRead)

                            If ltt.Has(lname) Then

                                idLayTblRcd = ltt.Item(lname)

                            Else

                                ed.WriteMessage("Layer: """ + lname + """ not available")


                                Return

                            End If

                            Dim idCol As ObjectIdCollection = New ObjectIdCollection

                            idCol.Add(idLayTblRcd)

                            ' Check that we are in paper space 

                            Dim vpid As ObjectId = ed.CurrentViewportObjectId

                            If vpid.IsNull() Then

                                ed.WriteMessage("No Viewport current.")

                                Return

                            End If

                            'VP need to be open for write 

                            Dim oViewport As Viewport = DirectCast(tm.GetObject(vpid, OpenMode.ForWrite, False), Viewport)

                            If Not oViewport.IsLayerFrozenInViewport(idLayTblRcd) Then

                                oViewport.FreezeLayersInViewport(idCol.GetEnumerator())

                            Else

                                oViewport.ThawLayersInViewport(idCol.GetEnumerator())

                            End If
                        Next
                    End If
                Next

                ta.Commit()

            Finally

                ta.Dispose()

            End Try

        End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Dec 2012 20:41:27 GMT</pubDate>
    <dc:creator>Hallex</dc:creator>
    <dc:date>2012-12-17T20:41:27Z</dc:date>
    <item>
      <title>Layer control in paperspace viewports with VB.net</title>
      <link>https://forums.autodesk.com/t5/net-forum/layer-control-in-paperspace-viewports-with-vb-net/m-p/3738241#M51994</link>
      <description>&lt;P&gt;Hi to all, any one have suggestions&amp;nbsp;to, how to control existing layers (Freeze On/Off), in an existing viewports&amp;nbsp; (5 of them in Paperspace) in AutoCad Existing drawing with VB.net?&amp;nbsp; I just want to trigger On or Off, different layers in each different viewports.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2012 14:04:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layer-control-in-paperspace-viewports-with-vb-net/m-p/3738241#M51994</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-17T14:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Layer control in paperspace viewports with VB.net</title>
      <link>https://forums.autodesk.com/t5/net-forum/layer-control-in-paperspace-viewports-with-vb-net/m-p/3738568#M51995</link>
      <description>&lt;P&gt;Found this one in my codes, author unknown,&lt;/P&gt;&lt;P&gt;try it for current viewport in Paper space&lt;/P&gt;&lt;PRE&gt;    &amp;lt;CommandMethod("VpLayersMan")&amp;gt; _
        Public Sub TestLayerFreeze()
           '' add layer names to freeze/ thaw in paperspace viewports separated by commas

            Dim layers As List(Of String) = {"Wall", "ANNO-TEXT"}.ToList()''&amp;lt;-- layers for test

            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            Dim ed As Editor = doc.Editor

            Dim db As Database = doc.Database

            Dim idLay As ObjectId

            Dim idLayTblRcd As ObjectId

            Dim lt As LayerTableRecord

            Dim layOut As Layout

            Dim tm As Autodesk.AutoCAD.ApplicationServices.TransactionManager = db.TransactionManager

            Dim ta As Transaction = tm.StartTransaction()

            Try
                Dim acLayoutMgr As LayoutManager

                acLayoutMgr = LayoutManager.Current

                Dim layDict As DBDictionary = DirectCast(ta.GetObject(db.LayoutDictionaryId, OpenMode.ForRead, False), DBDictionary)

                For Each itmdict As DBDictionaryEntry In layDict

                    layOut = DirectCast(ta.GetObject(itmdict.Value, OpenMode.ForRead, False), Layout)

                    ed.WriteMessage(vbLf + "Layout: {0}" + vbLf, layOut.LayoutName)

                    If layOut.LayoutName &amp;lt;&amp;gt; "Model" Then

                        acLayoutMgr.CurrentLayout = layOut.LayoutName

                        Dim ltt As LayerTable = DirectCast(ta.GetObject(db.LayerTableId, OpenMode.ForRead, False), LayerTable)

                        For Each lname As String In layers

                            idLay = ltt(lname)

                            lt = ta.GetObject(idLay, OpenMode.ForRead)

                            If ltt.Has(lname) Then

                                idLayTblRcd = ltt.Item(lname)

                            Else

                                ed.WriteMessage("Layer: """ + lname + """ not available")


                                Return

                            End If

                            Dim idCol As ObjectIdCollection = New ObjectIdCollection

                            idCol.Add(idLayTblRcd)

                            ' Check that we are in paper space 

                            Dim vpid As ObjectId = ed.CurrentViewportObjectId

                            If vpid.IsNull() Then

                                ed.WriteMessage("No Viewport current.")

                                Return

                            End If

                            'VP need to be open for write 

                            Dim oViewport As Viewport = DirectCast(tm.GetObject(vpid, OpenMode.ForWrite, False), Viewport)

                            If Not oViewport.IsLayerFrozenInViewport(idLayTblRcd) Then

                                oViewport.FreezeLayersInViewport(idCol.GetEnumerator())

                            Else

                                oViewport.ThawLayersInViewport(idCol.GetEnumerator())

                            End If
                        Next
                    End If
                Next

                ta.Commit()

            Finally

                ta.Dispose()

            End Try

        End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2012 20:41:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layer-control-in-paperspace-viewports-with-vb-net/m-p/3738568#M51995</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-12-17T20:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Layer control in paperspace viewports with VB.net</title>
      <link>https://forums.autodesk.com/t5/net-forum/layer-control-in-paperspace-viewports-with-vb-net/m-p/3738917#M51996</link>
      <description>&lt;P&gt;Thank's Hallex, the problem I have is with this, is the viewport must be active to be able to freeze layers.&amp;nbsp; The drawings I have, have already viewport created (6 of them), and each one must have different frozen layer assign to it.&amp;nbsp; I must find a way to call viewport individually, and then change the required layer properties.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2012 12:52:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layer-control-in-paperspace-viewports-with-vb-net/m-p/3738917#M51996</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-18T12:52:06Z</dc:date>
    </item>
  </channel>
</rss>

