[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
No Data