1

To map a text table in a DWG file, I created dictionaries.

I loaded the text data and made a dictionary for each column.

I would like to make a new dictionary which merges each column.

When making a dictionary of each column, the dictionary is sorted by order. I just want to assemble each column for making a new table dictionary.

If you have a more easy way to map text, please comment.

This picture shows the problem:

enter image description here

// make a dictionary of text in the table
if ((vText.Point1.X <= xBoundaryEnd) && (vText.Point.X >= xBoundaryStart) && (vText.Point1.Y <= yBoundaryEnd) && (vText.Point.Y >= yBoundaryStart)){

    bomTextDictionary.Add(vText.Handle,
    new textDataType
    {  
        text = vText.UnicodeText,
        refPointX = vText.Point1.X,
        refPointY = vText.Point1.Y
    });
}

// first column of table (number) dictionay by distingushing vertical line from the bomTextDictionary. 
var numberDict = bomTextDictionary.Where(x => x.Value.refPointX >= verticalLineDictionary.ElementAt(0).Value.xStart && x.Value.refPointX <= verticalLineDictionary.ElementAt(1).Value.xStart)
                                 .ToDictionary(text => text.Key, text => text.Value.text);

Markus Dresch
  • 5,290
  • 3
  • 20
  • 40
Jaeseo Lee
  • 17
  • 7
  • Sounds painful. Have you considered simply using a [`DataTable`](https://learn.microsoft.com/en-us/dotnet/api/system.data.datatable?view=netframework-4.8)? If you do it that way, there are various [methods](https://stackoverflow.com/questions/6073382/read-sql-table-into-c-sharp-datatable) out there to help you populate the data from SQL and [bind to UI controls](https://www.youtube.com/watch?v=4fGOLn3azZA), and you wouldn't have to deal with problems like this one. – John Wu Sep 26 '19 at 15:50
  • @JohnWu Thanks for your comment. I will consider it! – Jaeseo Lee Sep 27 '19 at 00:01

1 Answers1

1

You can create a model class to store the columns (e.g. name, quantity, part, drawing), and then use the dictionary with the model.

Example :

public class TableDWG
{
    public int Key { get; set; }

    public string Name { get; set; }

    public int Quantity { get; set; }

    public string Part { get; set; }

    public string Drawing { get; set; }

    public TableDWG() { }

    public TableDWG(int key, string name, int quatity, string part, string drawing)
    {
        Key = key;
        Name = name;
        Quantity = quatity;
        Part = part;
        Drawing = drawing;
    }

}

Then you do this :

IDictionary<int, TableDWG> table = new Dictionary<int, TableDWG>
{
    // you can do this
    { 1, new TableDWG(1, "something", 5, "part", "drawing") },
    { 2, new TableDWG(2, "something2", 2, "part2", "drawing2") },

    // OR this 
    {3, new TableDWG()
    {
        Key = 3, 
        Name = "Something3", 
        Quantity = 1, 
        Part = "Part 3", 
        Drawing = "Drwaing 3"
    } }
};

This is just an example on how to store multiple columns in one dictionary, there are other ways, but this is the easier one. In the model.

iSR5
  • 3,274
  • 2
  • 14
  • 13