.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to change Layer's Transparency?

6 REPLIES 6
Reply
Message 1 of 7
MGOMKD
3294 Views, 6 Replies

How to change Layer's Transparency?

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!

6 REPLIES 6
Message 2 of 7
Hallex
in reply to: MGOMKD

See article here

http://adndevblog.typepad.com/autocad/2012/04/setting-layer-transparency.html

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 7
MGOMKD
in reply to: Hallex

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!

Message 4 of 7
Hallex
in reply to: MGOMKD

Me too didn't solve this issue, sorry

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 5 of 7
Alfred.NESWADBA
in reply to: MGOMKD

Hi,

 

I also can reproduce the problem (AutoCAD 2012 x64 SP2 German).

The only way I currently found out is:

  • run your proc
  • change to any layout other than modelspace
  • change back to modelspace

 

It's a bad workaround, but at least it is one 😉

 

HTH, - alfred -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 7
MGOMKD
in reply to: Alfred.NESWADBA

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.

 

Message 7 of 7
MGOMKD
in reply to: MGOMKD

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.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost