.NET
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Layer control in paperspace viewports with VB.net
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.
Re: Layer control in paperspace viewports with VB.net
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.D ocumentManager.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.TransactionMa nager = 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.GetEnumerat or())
Else
oViewport.ThawLayersInViewport(idCol.GetEnumerator ())
End If
Next
End If
Next
ta.Commit()
Finally
ta.Dispose()
End Try
End Sub
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
C6309D9E0751D165D0934D0621DFF27919
Re: Layer control in paperspace viewports with VB.net
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.

