[CONNECT .NET] Find Table Seeds

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...

  1. Examine DGN files found in MS_DGNLIBLIST
  2. For each file, examine its models
  3. If model is a Table, then do something with it

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?

Parents Reply Children
  • 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?

     
    Regards, Jon Summers
    LA Solutions

  • How do we answer that question programmatically? 
    Is my function IsTableSeed() implemented correctly, or can it be improved?

    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:

    1. Open the MSCE delivered dgnlib file C:\ProgramData\Bentley\MicroStation CONNECT Edition\Configuration\WorkSpaces\Example\WorkSets\MetroStation\Standards\Dgnlib\MetroStation.dgnlib
    2. Copy the model Standard Table
    3. Add a shape element in Standard Table model.

    Then the TableSeed dropdown list only displays the copied model name. Shown as below:

    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.



    Answer Verified By: Jon Summers 

  • 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);
    }

    Table Seed Harvester

    Here's an article Table Seed Harvester that summarises the findings in this thread.

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: Jon Summers