A dictionary of strings.

A dictionary of strings.

Anonymous
Not applicable
1,467 Views
4 Replies
Message 1 of 5

A dictionary of strings.

Anonymous
Not applicable

Hi all

 

I'm struggling to create a drawing specific dictionary of strings.

 

I have blocks that I'm inserting which will obey the properties of certain types. These types can be edited per drawing, so aren't predefined.

 

I've looked into the NOD, but so far I've only used it for xrecords, whose data isn't keyed. I was hoping to not have to create a new xrecord for each type, but rather store the information in a dictionary that can manipulated by the user.

 

I've seen and used DBDictionaries, but they appear to only accept DBObjects which strings are not. The first thing I want to store against a key is a hatch pattern background colour.

 

If there's a better way of doing what I'm looking for, I'm open to suggestions.

 

Thanks

 

MrRamsden

0 Likes
1,468 Views
4 Replies
Replies (4)
Message 2 of 5

Hallex
Advisor
Advisor

Thought, it might be interesting for you as a possible solution:

 

http://forums.augi.com/showpost.php?p=1155164&postcount=2

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 3 of 5

dgorsman
Consultant
Consultant

Use a dictionary to house an XRecord which contains a single string.  House the entire set of dictionaries under its own dictionary to avoid conflicts with other dictionaries.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 4 of 5

Anonymous
Not applicable

Thanks for your replies. I've ended up doing this:

 

Spoiler
Private Sub addColourDictionary() Using trans As Transaction = ed.Document.Database.TransactionManager.StartTransaction Try Dim nod As DBDictionary = trans.GetObject(ed.Document.Database.NamedObjectsDictionaryId, OpenMode.ForRead) If Not nod.Contains("colours") Then nod.UpgradeOpen() 'open nod Dim colourRecord As Xrecord = New Xrecord 'new xrecord in nod nod.SetAt("colours", colourRecord) 'set position of xrecord in nod colourRecord.CreateExtensionDictionary() 'create extension dictionary in xrecord Dim un As Xrecord = New Xrecord 'create xrecord in extension dictionary un.Data = New ResultBuffer(New TypedValue(DxfCode.Color, 1)) Dim sh As Xrecord = New Xrecord 'create xrecord in extension dictionary sh.Data = New ResultBuffer(New TypedValue(DxfCode.Color, 2)) Dim extDict As DBDictionary = trans.GetObject(colourRecord.ExtensionDictionary, OpenMode.ForWrite) extDict.SetAt("1", un) 'set position of xrecord in ext dict extDict.SetAt("2", sh) 'set position of xrecord in ext dict trans.AddNewlyCreatedDBObject(colourRecord, True) End If ed.WriteMessage(vbLf & "Colour dictionary creation successful") Catch ex As System.Exception ed.WriteMessage(vbLf & "Colour dictionary creation failed") End Try trans.Commit() End Using End Sub

 to set the dictionary, and this:

 

Spoiler
Private Sub changeHatchColour() Try Dim nod As DBDictionary = trans.GetObject(ed.Document.Database.NamedObjectsDictionaryId, OpenMode.ForRead) Dim blockTableRecord As BlockTableRecord = trans.GetObject(block.BlockTableRecord, OpenMode.ForRead) If nod.Contains("stand colours") Then ed.WriteMessage(vbLf & "nod doesn't contain 'stand colours'") Dim xrecord As Xrecord = trans.GetObject(nod.GetAt("stand colours"), OpenMode.ForRead) Dim extDict As DBDictionary = trans.GetObject(xrecord.ExtensionDictionary, OpenMode.ForRead) If extDict IsNot Nothing Then ed.WriteMessage(vbLf & "extDict contains stuff") ed.WriteMessage(vbLf & "selectedvalue is: " & standTypes.SelectedValue.ToString()) If extDict.Contains(standTypes.SelectedValue.ToString()) Then ed.WriteMessage(vbLf & "Selected value found") Dim record As Xrecord = trans.GetObject(extDict.GetAt(standTypes.SelectedValue.ToString()), OpenMode.ForRead) ed.WriteMessage(vbLf & "xrecord created") For Each objId As ObjectId In blockTableRecord ed.WriteMessage(vbLf & "For loop entered") Dim obj As DBObject = trans.GetObject(objId, OpenMode.ForRead) ed.WriteMessage(vbLf & "hatch variable created") If TypeOf obj Is Hatch Then ed.WriteMessage(vbLf & "Hatch found!") Dim hatch As Hatch = obj ed.WriteMessage(vbLf & "obj converted to hatch") hatch.UpgradeOpen() ed.WriteMessage(vbLf & "upgradeopen() run on hatch") Dim array() As TypedValue = record.Data.AsArray() ed.WriteMessage(vbLf & "Array of xrecord created") ed.WriteMessage(vbLf & "Current colour is: " & hatch.Color.ToString()) ed.WriteMessage(vbLf & "Value is: " & array(0).Value) hatch.ColorIndex = array(0).Value ed.WriteMessage(vbLf & "Colour changed") End If Next End If End If End If ed.WriteMessage(vbLf & "Changed colour successfully") Catch ex As System.Exception ed.WriteMessage(vbLf & "Colour change failed") End Try End Sub

 to retrieve it (lots of WriteMessages because debugging complains about symbols).

 

It's an Xrecord in the NOD, which has a DBDictionary of single value Xrecords in it. Just tested it and it works. Now I'm going to manipulate the list with the GUI...

 

Thanks again!

 

0 Likes
Message 5 of 5

Anonymous
Not applicable

Wow, spoilers really broke the code formatting 😞

 

If anyone wants it formatted, just shout.

0 Likes