Is it able to change the transparency of a layer?
I know how to get the value but i can't find how to set a new one!
Using acTrans = acDocs.MdiActiveDocument.Database.TransactionManager.StartTransaction() acLyrTbl = acTrans.GetObject(acDocs.MdiActiveDocument.Database.LayerTableId, OpenMode.ForRead) For Each acObjId As ObjectId In acLyrTbl acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead) Dim MyTransparency As Autodesk.AutoCAD.Colors.Transparency = acLyrTblRec.Transparency MsgBox(MyTransparency.ToString) Next acObjId
End Using
Dev center is a little bit poor about it? Or I didn't it!
See article here
http://adndevblog.typepad.com/autocad/2012/04/setting-layer-transparency.html
~'J'~
Hi!
I'm progressing on changing layer's transparency. I noticed that transparencies are changed in the layer manager but not in the modelspace! Is there a way to refresh this? I tried REGEN and REFRESH but it doesn'twork!
Here is my code
'Déclaration des variables' acDoc = Application.DocumentManager.MdiActiveDocument acCurDb = acDoc.Database 'Procédure' Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) If acLyrTbl.Has(LayerVal) = True Then acCurDb.Clayer = acLyrTbl(LayerVal) For Each acObjId As ObjectId In acLyrTbl acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite) If acLyrTblRec.Name <> LayerVal Then acLyrTblRec.Transparency = New Autodesk.AutoCAD.Colors.Transparency(CByte(50)) End If Next (acObjId) acTrans.Commit() End If End Using
This code turns the layer named layerval current, then iterate through layers collection and change their transparency if layer's name is different of Layerval.
Quietly but surely!
See you!
Me too didn't solve this issue, sorry
~'J'~
Hi,
I also can reproduce the problem (AutoCAD 2012 x64 SP2 German).
The only way I currently found out is:
It's a bad workaround, but at least it is one 😉
HTH, - alfred -
Hi friends!
I confirm, toggling from modelspace to layouts then getting back to modelspace works! But it's not the way I expected,
It should exist an easier one!
Go for it !!!
See you.
Hi friends,
By searching on the web and the .NET Developper's guide, I found a way to refresh layer after transparencies had changed.
Here's the source code:
Public Sub CurrentLayer(ByVal LayerVal) '************************************************************************************' '* Activation du calque séléctionné en calque courant et gestion de la transparence *' '************************************************************************************' 'Déclaration des variables' acDoc = Application.DocumentManager.MdiActiveDocument acCurDb = acDoc.Database Dim acObjId As ObjectId 'Procédure' Using acTrans = acCurDb.TransactionManager.StartTransaction() acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) If acLyrTbl.Has(LayerVal) = True Then acCurDb.Clayer = acLyrTbl(LayerVal) For Each acObjId In acLyrTbl acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite) If acLyrTblRec.Name <> LayerVal Then 'Transparence du calque à 80' acLyrTblRec.Transparency = New Autodesk.AutoCAD.Colors.Transparency(CByte(50)) Else 'Transparence du calque à 0' acLyrTblRec.Transparency = New Autodesk.AutoCAD.Colors.Transparency(CByte(255)) End If Next (acObjId) End If 'Application des changements' acTrans.Commit() 'Déclaration variable et appel de fonction' Dim acLyrTblIds As ObjectIdCollection = GetLayerObjectIds() 'Itération sur les calques dans la collection' Dim acLyrTblId(acLyrTblIds.Count - 1) As ObjectId For i = 0 To acLyrTblIds.Count - 1 acLyrTblId(i) = acLyrTblIds(i) Next 'Regénération des calques' Autodesk.AutoCAD.Internal.LayerUtilities.RegenLayers(acLyrTblId, Autodesk.AutoCAD.Internal.LayerUtilities.RegenPending) End Using End Sub Function GetLayerObjectIds() As ObjectIdCollection '****************************************************' '* Création du stockage de la collection de calques *' '****************************************************' 'Déclaration variable' Dim acLyrTblIds As New ObjectIdCollection 'Procédure' Using acTrans = acCurDb.TransactionManager.StartTransaction() acLyrTbl = acCurDb.LayerTableId.GetObject(OpenMode.ForWrite) 'Création de la collection de calques' For Each acObjId In acLyrTbl acLyrTblIds.Add(acObjId) Next 'Application des changements' acTrans.Commit() End Using 'Renvoi du résultat' Return acLyrTblIds End Function
See you!
Can't find what you're looking for? Ask the community or share your knowledge.