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

    .NET

    Reply
    Active Contributor
    Posts: 26
    Registered: ‎08-29-2008

    A dictionary of strings.

    247 Views, 4 Replies
    01-23-2012 06:58 AM

    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

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,332
    Registered: ‎10-08-2008

    Re: A dictionary of strings.

    01-23-2012 07:39 AM in reply to: MrRamsden

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

     

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

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    *Expert Elite*
    dgorsman
    Posts: 3,278
    Registered: ‎10-12-2006

    Re: A dictionary of strings.

    01-23-2012 08:12 AM in reply to: MrRamsden

    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.
    Adopt. Adapt. Overcome. Or be overcome.


    Please use plain text.
    Active Contributor
    Posts: 26
    Registered: ‎08-29-2008

    Re: A dictionary of strings.

    01-23-2012 09:27 AM in reply to: dgorsman

    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!

     

    Please use plain text.
    Active Contributor
    Posts: 26
    Registered: ‎08-29-2008

    Re: A dictionary of strings.

    01-23-2012 09:28 AM in reply to: MrRamsden

    Wow, spoilers really broke the code formatting :smileysad:

     

    If anyone wants it formatted, just shout.

    Please use plain text.