.NET

Reply
Active Contributor
Alainmorin
Posts: 32
Registered: ‎05-05-2010
Message 1 of 3 (959 Views)

Layer control in paperspace viewports with VB.net

959 Views, 2 Replies
12-17-2012 06:04 AM

Hi to all, any one have suggestions to, how to control existing layers (Freeze On/Off), in an existing viewports  (5 of them in Paperspace) in AutoCad Existing drawing with VB.net?  I just want to trigger On or Off, different layers in each different viewports.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 3 (943 Views)

Re: Layer control in paperspace viewports with VB.net

12-17-2012 12:41 PM in reply to: Alainmorin

Found this one in my codes, author unknown,

try it for current viewport in Paper space

    <CommandMethod("VpLayersMan")> _
        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()''<-- 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 <> "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

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
Alainmorin
Posts: 32
Registered: ‎05-05-2010
Message 3 of 3 (926 Views)

Re: Layer control in paperspace viewports with VB.net

12-18-2012 04:52 AM in reply to: Alainmorin

Thank's Hallex, the problem I have is with this, is the viewport must be active to be able to freeze layers.  The drawings I have, have already viewport created (6 of them), and each one must have different frozen layer assign to it.  I must find a way to call viewport individually, and then change the required layer properties.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!