Posts: 247
Registered: ‎04-15-2011
Message 1 of 3 (236 Views)
Accepted Solution

eInvalidLayer freezing thawing layer

236 Views, 2 Replies
03-15-2012 09:07 AM

There's something wrong with my freeze layer procedure. 

I get an eInvalidLayer error when it comes to changing the IsFrozen state.

Can anyone suggest what is causing it?


    Public Sub LayerFreeze(ByVal sLayerName As String, ByVal bFreeze As Boolean)
        '' Get the current document and database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        '' Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            '' Open the Layer table for read
            Dim acLyrTbl As LayerTable
            acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead)
            Dim acLyrTblRec As LayerTableRecord
            If acLyrTbl.Has(sLayerName) = False Then
                acLyrTblRec = New LayerTableRecord()
                '' Assign the layer a name
                acLyrTblRec.Name = sLayerName
                '' Upgrade the Layer table for write
                '' Append the new layer to the Layer table and the transaction
                acTrans.AddNewlyCreatedDBObject(acLyrTblRec, True)
                acLyrTblRec = acTrans.GetObject(acLyrTbl(sLayerName), OpenMode.ForWrite)
            End If
            ' Freeze or thaw the layer
            If acLyrTblRec.IsFrozen = Not bFreeze Then acLyrTblRec.IsFrozen = bFreeze
        End Using
    End Sub



Valued Contributor
Posts: 82
Registered: ‎06-26-2008
Message 2 of 3 (230 Views)

Re: eInvalidLayer freezing thawing layer

03-15-2012 09:51 AM in reply to: SRSDS



You need to check that you're not trying to freeze the current layer; you'll get the eInvalidLayer error if you are.





Posts: 247
Registered: ‎04-15-2011
Message 3 of 3 (218 Views)

Re: eInvalidLayer freezing thawing layer

03-15-2012 12:56 PM in reply to: Paulio

Thanks, makes a lot of sense and the problem is fixed.

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

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