Hi everybody,
I'm looking to find a way to change layer properties by viewport. I know how to freeze/thaw layer by viewport but not changing their properties. I'm using VB .Net.
Anybody have an idea?
Regards
André
Have you considered LayerViewportProperties?
This thread may also be of use.
"How we think determines what we do, and what we do determines what we get."
Thank you very much for your hint and link to the thread.
For your information, here the sub I created:
This sub overides layer settings in all viewport except the current one. The overrides properties came from a layer "template". (A layer with the properties to apply as overrides).
Public Sub SetLayerOverridesInOtherViewPort(ByVal LayerName As String, ByVal LayerNameTemplate As String)
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using doclock As DocumentLock = acDoc.LockDocument
'' Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'Define variables
Dim acLyrTbl As LayerTable
Dim CVPort As Viewport
Dim LVPO As LayerViewportProperties
'Get current viewport
CVPort = DirectCast(acTrans.GetObject(acDoc.Editor.CurrentViewportObjectId, OpenMode.ForRead), Viewport)
'Get current layout name
Dim layoutDict As DBDictionary = CType(acTrans.GetObject(acCurDb.LayoutDictionaryId, OpenMode.ForRead), DBDictionary)
Dim strCurrentLayoutName As String = LayoutManager.Current.CurrentLayout
'Get layer table object
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead)
If acLyrTbl.Has(LayerNameTemplate) = True Then
'Get layer template object
Dim acLyrTemplateTblRec As LayerTableRecord
acLyrTemplateTblRec = acTrans.GetObject(acLyrTbl(LayerNameTemplate), OpenMode.ForRead)
'Scan all viewport
For Each entry As DBDictionaryEntry In layoutDict
If entry.Key <> "Model" Then
Dim lay As Layout = CType(acTrans.GetObject(entry.Value, OpenMode.ForRead), Layout)
If lay.LayoutName.ToUpper <> strCurrentLayoutName.ToUpper Then
SetCurrentLayoutTab(lay.LayoutName)
Dim nCount As Integer = 0
For Each vpid As ObjectId In lay.GetViewports
nCount = nCount + 1
Dim vp As Viewport = CType(acTrans.GetObject(vpid, OpenMode.ForWrite), Viewport)
If vp.Handle <> CVPort.Handle Then
If nCount > 1 Then
'acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead)
For Each acObjId As ObjectId In acLyrTbl
Dim acLyrTblRec As LayerTableRecord
acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead)
If acLyrTblRec.Name.ToUpper = LayerName.ToUpper Then
Dim LaagTabelRec As LayerTableRecord = acTrans.GetObject(acLyrTblRec.ObjectId, OpenMode.ForRead)
LVPO = LaagTabelRec.GetViewportOverrides(vp.Id)
LVPO.Color = acLyrTemplateTblRec.Color
LVPO.LinetypeObjectId = acLyrTemplateTblRec.LinetypeObjectId
LVPO.LineWeight = acLyrTemplateTblRec.LineWeight
Exit For
End If
Next
End If
End If
Next
End If
End If
Next
acTrans.Commit()
SetCurrentLayoutTab(strCurrentLayoutName)
acDoc.Editor.Regen()
End If
End Using
End Using
End Sub
I also include a sub to set the current layout tab:
Public Sub SetCurrentLayoutTab(ByVal LayoutName As String)
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using doclock As DocumentLock = acDoc.LockDocument
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Try
Dim acLayoutMgr As LayoutManager
acLayoutMgr = LayoutManager.Current
acLayoutMgr.CurrentLayout = LayoutName
acTrans.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message & vbCr & ex.StackTrace)
acTrans.Abort()
End Try
End Using
End Using
End Sub
Regards
André
You're welcome; I'm happy to help.
As one of many things... If you implement the appropriate Imports directive (using in C#), you'll enable Type references without Namespace qualification... As one example, consider:
Imports acApp = Autodesk.AutoCAD.ApplicationServices.Application Public Sub GetCTab() acApp.GetSystemVariable("CTAB") End Sub Public Sub SetCTab(ByVal layoutName As String) acApp.SetSystemVariable("CTAB", layoutName) End Sub
"How we think determines what we do, and what we do determines what we get."
Can't find what you're looking for? Ask the community or share your knowledge.