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

eInvalidLayer freezing thawing layer

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
SRSDS
995 Views, 3 Replies

eInvalidLayer freezing thawing layer

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
                acLyrTbl.UpgradeOpen()
                '' Append the new layer to the Layer table and the transaction
                acLyrTbl.Add(acLyrTblRec)
                acTrans.AddNewlyCreatedDBObject(acLyrTblRec, True)
            Else
                acLyrTblRec = acTrans.GetObject(acLyrTbl(sLayerName), OpenMode.ForWrite)
            End If
            ' Freeze or thaw the layer
            If acLyrTblRec.IsFrozen = Not bFreeze Then acLyrTblRec.IsFrozen = bFreeze
            acTrans.Commit()
        End Using
    End Sub

 

 

3 REPLIES 3
Message 2 of 4
Paulio
in reply to: SRSDS

Hi SRSDS,

 

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

 

Regards

 

Paul

Message 3 of 4
SRSDS
in reply to: Paulio

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

Message 4 of 4
SENL1362
in reply to: SRSDS

Dont't try to Thaw the current layer as well

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