Layer Swap Error

Layer Swap Error

Anonymous
Not applicable
435 Views
2 Replies
Message 1 of 3

Layer Swap Error

Anonymous
Not applicable
Hi, all.
Below is the way to get error.
What do I have to check and fix it completely?
Thanks in advance.

How to Get Error
1.Create "SourceLayer" layer-------> Layer1
2.Create "TargetLayer" Layer-------> Layer2
3.Erase "SourceLayer" Layer
4.Create "SourceLayer" Layer
5.Excute Below Code
Then we can get "eDuplicateRecordName" error
6. Dim ltr As LayerTableRecord = tr.GetObject(lt.Item(Layer1), OpenMode.ForWrite, True, True)------> rewrite True to False
Then we can get "eWasErased" error

Shared Sub SwapLayers(ByVal Layer1 As String, ByVal Layer2 As String)
Using db As Database = HostApplicationServices.WorkingDatabase
Using tr As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction
Using lt As LayerTable = tr.GetObject(db.LayerTableId, OpenMode.ForWrite, True, True)
lt.UpgradeOpen()
If lt.Has(Layer1) AndAlso lt.Has(Layer2) Then
Dim ltr As LayerTableRecord = tr.GetObject(lt.Item(Layer1), OpenMode.ForWrite, True, True)
Dim ltr2 As LayerTableRecord = tr.GetObject(lt.Item(Layer2), OpenMode.ForWrite, True, True)
ltr.Name = "SwapLayers_temp"
ltr2.Name = Layer1
ltr.Name = Layer2
tr.Commit()
Application.DocumentManager.MdiActiveDocument.Editor.Regen()
End If
End Using
End Using
End Using
End Sub
0 Likes
436 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
If you search the group on eWasErased you will find plenty of discussion on this topic. As you have found out the API stupidly returns erased items so you have to loop through the table to find the non erased item.



The attached function retrieves the ObjectId of the SymbolTableRecord. The function requires the ObjectId of the SymbolTable and the name of the SymbolTableRecord as as string.



The function finds the non-erased item when there are erased ones with the same name. It returns ObjectId.Null if the record does not exist.



Regards - Nathan
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thank you so much.
It's working very well without an error.
0 Likes