Hi Mikako
That got me some of the way. Now I can rename the classification definition using the code below. Now I just need to rename som nodes inside the classification tree. However I am having troubles using the classificationtree-rename method. (Have a look at the RenameClassification below).
Any sugestions?
Code example:
<Autodesk.AutoCAD.Runtime.
CommandMethod("RenameClassificationDef")> _
PublicSub RenameClassificationDef()
Dim ed AsEditor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db AsDatabase = HostApplicationServices.WorkingDatabase
Dim dictClsfcDef AsDictionaryClassificationDefinition = NewDictionaryClassificationDefinition(db)
Dim id AsObjectId = dictClsfcDef.GetAt("AAU_SfBClassification")
Try
Using tr AsTransaction = db.TransactionManager.StartTransaction
Dim SfBClsfc AsObjectId
Dim AAUClsfc AsObjectId
Try
SfBClsfc = dictClsfcDef.GetAt(
"SfB")
Catch
EndTry
Try
AAUClsfc = dictClsfcDef.GetAt(
"AAU_SfBClassification")
Catch
EndTry
If AAUClsfc.IsNull AndAlsoNot SfBClsfc.IsNull Then
dictClsfcDef.Rename(
"SfB", "AAU_SfBClassification", tr)
EndIf
Dim Recs AsObjectIdCollection = dictClsfcDef.Records
ForEach RecID AsObjectIdIn Recs
Dim RecObj AsClassificationDefinition = RecID.GetObject(OpenMode.ForWrite)
Dim VVSID AsObjectId = RecObj.GetClassification("VVS-anlæg")
Dim VVSObj AsClassification = VVSID.GetObject(OpenMode.ForWrite)
Next
tr.Commit()
EndUsing
Catch ex AsException
ed.WriteMessage(
"Error : " + ex.ToString + vbCrLf)
EndTry
EndSub
Here is the RenameClassification-sub (that fails):
Public Sub RenameClassification(ByRef tr AsTransaction, ByRef node AsClassificationTree)
Dim ed AsEditor = Application.DocumentManager.MdiActiveDocument.Editor
If node IsNothingThen
Return
EndIf
IfNot (node.Id.IsNull) Then
Dim classi AsClassification = CType(tr.GetObject(node.Id, OpenMode.ForRead), Classification)
node.Rename(classi.ObjectId,"SomeNewName") THIS FAILS!
EndIf
If node.Children.Count > 0 Then
ForEach ChildTree In node.Children
RenameClassification(tr, ChildTree)
Next
EndIf
EndSub