• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    Posts: 13
    Registered: ‎05-05-2010

    Layer control in paperspace viewports with VB.net

    206 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.

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,334
    Registered: ‎10-08-2008

    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
    Please use plain text.
    Contributor
    Posts: 13
    Registered: ‎05-05-2010

    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.

    Please use plain text.