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

Rename a Dictionary

6 REPLIES 6
Reply
Message 1 of 7
ChrisPicklesimer
392 Views, 6 Replies

Rename a Dictionary

I have created a dictionary that contains one "sub" dictionary and multiple XRecords. This dictionary was created a couple of dictionaries below the NOD. I was wondering if .net provided a way to rename this dictionary.

Thanks.

Chris
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: ChrisPicklesimer

Have you tried the DBDictionary.SetName() method?


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6272381@discussion.autodesk.com...
I have created a dictionary that contains one "sub" dictionary and multiple
XRecords. This dictionary was created a couple of dictionaries below the
NOD. I was wondering if .net provided a way to rename this dictionary.

Thanks.

Chris
Message 3 of 7

I tried -> sub2Dict.SetName(strOld, strNew) in the following sub but I error out. Is this the way it is to be used?

Thanks.

Chris

Public Sub RenameCategory(ByVal strOld As String, ByVal strNew As String)

Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

'get working database
Dim dwg As Database = ed.Document.Database

Using trans As Transaction = dwg.TransactionManager.StartTransaction()
Try
Dim NOD As DBDictionary = CType(trans.GetObject(dwg.NamedObjectsDictionaryId, OpenMode.ForWrite), DBDictionary)
Dim MainDict As DBDictionary = CType(trans.GetObject(NOD.GetAt("PH_Dictionaries"), OpenMode.ForWrite), DBDictionary)
Dim sub1Dict As DBDictionary = CType(trans.GetObject(MainDict.GetAt("PH_Revisions"), OpenMode.ForWrite), DBDictionary)
Dim sub2Dict As DBDictionary = CType(trans.GetObject(sub1Dict.GetAt(strOld), OpenMode.ForWrite), DBDictionary)

sub2Dict.SetName(strOld, strNew)
trans.Commit()

Catch caught As System.Exception
MessageBox.Show(caught.StackTrace)
End Try
End Using


End Sub
Message 4 of 7
Anonymous
in reply to: ChrisPicklesimer

What's the error?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6272805@discussion.autodesk.com...
I tried -> sub2Dict.SetName(strOld, strNew) in the following sub but I
error out. Is this the way it is to be used?

Thanks.

Chris

Public Sub RenameCategory(ByVal strOld As String, ByVal strNew As
String)

Dim ed As Editor =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

'get working database
Dim dwg As Database = ed.Document.Database

Using trans As Transaction =
dwg.TransactionManager.StartTransaction()
Try
Dim NOD As DBDictionary =
CType(trans.GetObject(dwg.NamedObjectsDictionaryId, OpenMode.ForWrite),
DBDictionary)
Dim MainDict As DBDictionary =
CType(trans.GetObject(NOD.GetAt("PH_Dictionaries"), OpenMode.ForWrite),
DBDictionary)
Dim sub1Dict As DBDictionary =
CType(trans.GetObject(MainDict.GetAt("PH_Revisions"), OpenMode.ForWrite),
DBDictionary)
Dim sub2Dict As DBDictionary =
CType(trans.GetObject(sub1Dict.GetAt(strOld), OpenMode.ForWrite),
DBDictionary)

sub2Dict.SetName(strOld, strNew)
trans.Commit()

Catch caught As System.Exception
MessageBox.Show(caught.StackTrace)
End Try
End Using


End Sub
Message 5 of 7

Once I hit sub2Dict.SetName(strOld, strNew) I get the following error description: "Operation is not valid due to the current state of the object."
Message 6 of 7
Anonymous
in reply to: ChrisPicklesimer

You call SetName() on the DBDictionary that *contains* the item whose name
you want to change.

Your code is calling SetName() on the item (sub2Dict, another dictionary in
your case) whose name you want to change.

Try sub1Dict.SetName(...), and don't even bother opening sub2Dict.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6273105@discussion.autodesk.com...
Once I hit sub2Dict.SetName(strOld, strNew) I get the following error
description: "Operation is not valid due to the current state of the
object."
Message 7 of 7

That did it. Thanks for the help again.

Chris

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