.NET

Reply
Active Contributor
MGOMKD
Posts: 33
Registered: ‎06-23-2011
Message 1 of 7 (1,677 Views)

How to change Layer's Transparency?

1677 Views, 6 Replies
09-03-2012 06:38 AM

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!

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 7 (1,668 Views)

Re: How to change Layer's Transparency?

09-03-2012 09:20 AM in reply to: MGOMKD

See article here

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

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
MGOMKD
Posts: 33
Registered: ‎06-23-2011
Message 3 of 7 (1,605 Views)

Re: How to change Layer's Transparency?

09-17-2012 11:16 AM 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!

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 7 (1,593 Views)

Re: How to change Layer's Transparency?

09-17-2012 12:56 PM in reply to: MGOMKD

Me too didn't solve this issue, sorry

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
*Expert Elite*
Alfred.NESWADBA
Posts: 9,084
Registered: ‎06-29-2007
Message 5 of 7 (1,589 Views)

Re: How to change Layer's Transparency?

09-17-2012 01:35 PM 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 :smileywink:

 

HTH, - alfred -

 

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Active Contributor
MGOMKD
Posts: 33
Registered: ‎06-23-2011
Message 6 of 7 (1,559 Views)

Re: How to change Layer's Transparency?

09-21-2012 12:55 PM 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.

 

Active Contributor
MGOMKD
Posts: 33
Registered: ‎06-23-2011
Message 7 of 7 (1,531 Views)

Re: How to change Layer's Transparency?

10-02-2012 01:13 AM 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!

 

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.