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

How to rename an existing classification object

6 REPLIES 6
Reply
Message 1 of 7
BIM_Admin_Orbicon
569 Views, 6 Replies

How to rename an existing classification object

My task is to write an automated routine that checks for a certain classification added to Duct objects.

In the classification definition SfB all classification names of the form (XX)X should be altered/renamed to the form XX.X

 

Defining a Classification object Classfc as Autodesk.Aec.DatabaseServices.Classification my problem is that the property Classfc.Name is readonly

I struggled with finding another way to solve the problem but have not been able to find a solution.

 

Any ideas?

 

Jan Grenov
CAD Manager
Orbicon A/S
6 REPLIES 6
Message 2 of 7

Hi Jan,

 

How about Rename() method of DictionaryClassificationDefinition class?  Dictionary is a container class of dictionary record.  If you haven't looked at it, could you try? 


Mikako Harada
Developer Technical Services
Message 3 of 7

Thanks t for the hint. I will give it a try and let you know how it went.

Jan Grenov
CAD Manager
Orbicon A/S
Message 4 of 7

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

Jan Grenov
CAD Manager
Orbicon A/S
Message 5 of 7

Hi Jan,

 

Could you post this question to AutoCAD Architecture customization forum? 

 

http://forums.autodesk.com/t5/AutoCAD-Architecture/bd-p/54

 

Sounds like your question became AutoCAD Architecture specific. The audience of this forum is probably wondering what we are talking about 🙂  It will be more appropriate to post in AutoCAD Architecture one.  

 

Glad to hear you have solved the initial question of renaming the classification definition.

  

Thank you for cooperation. 

 


Mikako Harada
Developer Technical Services
Message 6 of 7

I will do that.
Thanks so far 🙂

Jan Grenov
CAD Manager
Orbicon A/S
Message 7 of 7

 

Posted question in the Architecture customization forum as "How to make the rename-method of the Classificationtree work?"

Jan Grenov
CAD Manager
Orbicon A/S

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