• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    JanGrenov1325
    Posts: 22
    Registered: ‎10-27-2010

    How to rename an existing classification object

    183 Views, 6 Replies
    07-30-2012 05:00 AM

    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
    Please use plain text.
    ADN Support Specialist
    Posts: 21
    Registered: ‎08-26-2007

    Re: How to rename an existing classification object

    08-02-2012 08:43 AM in reply to: JanGrenov1325

    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
    Autodesk Developer Network

    Please use plain text.
    Contributor
    JanGrenov1325
    Posts: 22
    Registered: ‎10-27-2010

    Re: How to rename an existing classification object

    08-02-2012 11:13 PM in reply to: JanGrenov1325

    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
    Please use plain text.
    Contributor
    JanGrenov1325
    Posts: 22
    Registered: ‎10-27-2010

    Re: How to rename an existing classification object

    08-06-2012 09:00 AM in reply to: mikako.harada

    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
    Please use plain text.
    ADN Support Specialist
    Posts: 21
    Registered: ‎08-26-2007

    Re: How to rename an existing classification object

    08-06-2012 03:44 PM in reply to: JanGrenov1325

    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
    Autodesk Developer Network

    Please use plain text.
    Contributor
    JanGrenov1325
    Posts: 22
    Registered: ‎10-27-2010

    Re: How to rename an existing classification object

    08-07-2012 12:29 AM in reply to: JanGrenov1325

    I will do that.
    Thanks so far :-)

    Jan Grenov
    CAD Manager
    Orbicon A/S
    Please use plain text.
    Contributor
    JanGrenov1325
    Posts: 22
    Registered: ‎10-27-2010

    Re: How to rename an existing classification object

    08-07-2012 01:13 AM in reply to: mikako.harada

     

    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
    Please use plain text.