A Table Seed is a model in a DGN file. Usually the DGN file is a DGNLib listed in configuration variable MS_DGNLIBLIST. To find a table seed programmatically, I suppose that the procedure looks like this...
MS_DGNLIBLIST
Here's some code...
public int GetTableSeedModels () { int nModels = 0; DgnLibIterator iterator = new DgnLibIterator(DgnLibSelector.ElementStyles); foreach (DgnFile lib in iterator) { // Examine each DGN model in the file var indices = lib.GetModelIndexCollection(); foreach (var index in indices) { StatusInt status; DgnModel model = lib.LoadRootModelById(out status, index.Id); if (IsTableSeed(model)) { string s = $"Table seed: {lib.GetFileName ()}.{model.ModelName}"; MessageCenter.Instance.ShowMessage(MessageType.Debug, s, s, MessageAlert.None); ++nModels; } } } return nModels; }
private bool IsTableSeed (DgnModel model) { ElementId dummy = DgnTextStyle.GetSettings(Session.Instance.GetActiveDgnFile()).Id; // Use static method to create a TextTable for testing TextTable someTable = TextTable.Create(1, 1, dummy, 1.0, model); // Attempt to copy the DGN model to see if it is a Table Seed TextTable table = someTable.Copy(model); return (null != table); }
That almost works. It gives me the models that contain a Table Seed, but it also gives me the default model in each DGN file when that does not contain a Table Seed. I admit that function IsTableSeed looks clunky. Is there a better way?
IsTableSeed
Yongan.Fu said:Get the only one graphical element and judge if it is a TextTable element
Thanks! So my above approach to test whether a DGN model can be used as a TextTable Seed is incorrect?
Here a new test, implemented for .NET, that appears to work...
private bool IsTableSeed(DgnModel model) { var elements = model.GetGraphicElements(); return (elements.Count() == 1 && elements.First() is TextTableElement); }
Here's an article Table Seed Harvester that summarises the findings in this thread.
Regards, Jon Summers LA Solutions
Answer Verified By: Jon Summers
Jon Summers said:How do we answer that question programmatically?
Jon Summers said:Is my function IsTableSeed() implemented correctly, or can it be improved?
IsTableSeed()
Iterate all models in available dgnlib files and check if the model only contains one graphical element and this element is a TextTable element.
To verify this, I did below steps:
Then the TableSeed dropdown list only displays the copied model name. Shown as below:
Jon Summers said:What is the C++ or .NET procedure to determine if a DGN model contains a Table?
Get the only one graphical element and judge if it is a texttable element. For C++, we can use dynamic_cast<TextTableHandler *>(&eh.GetHandler()) to determine if an ElementHandle is a textTable element.
Yongan.Fu said:To be a valid seed, the model must contain only one graphical element and that element must be a table
I'm well aware of that. When placing a table manually, the menu offers a choice of seeds.
My question is: How do we answer that question programmatically? What is the C++ or .NET procedure to determine if a DGN model contains a Table?
Is my function IsTableSeed() implemented correctly, or can it be improved?
To be a valid seed, the model must contain only one graphical element and that element must be a table.