[CONNECT C#] Grid created by Grid Manager

Hi,

I am trying to access the grid properties (grid lines, coordinates, orientation, etc.) of a OpenBuildings Designer model from a c# addin. I can see from the XML export that the used EC schema should be StructuralModelingComponents.06.00.

When I ask the DgnECManager for discover-able schemas, it doesn´t include that schema though.

List<string> schemas = Enumerable.ToList(manager.DiscoverSchemas(Session.Instance.GetActiveDgnFile(), ReferencedModelScopeOption.All, true));

I also tried

FindInstancesScope scope = FindInstancesScope.CreateScope(Session.Instance.GetActiveDgnFile(), new FindInstancesScopeOption(DgnECHostType.All, true));
IECSchema schema = manager.LocateSchemaInScope(scope, "StructuralModelingComponents", 6, 0, SchemaMatchType.Latest);


but with no success. 

The IntegratedStructuralModel schema wouldn´t work either.

Are grid lines somehow not part of the model or should I look in a different schema? 

Might there be a different way to access grids? 

See also https://www.itwinjs.org/bis/domains/processphysical.ecschema/#ismcartesiangrid for reference.

Parents Reply Children
  • There are functions available to access the GridSystem, but they seem to not be included in the c# wrappers

    While you're waiting for the OBD developers to extend their API, you'll have to write your own P/Invoke wrappers for the functions you want.

    It isn't hard to write a wrapper, provided you known the data types of the parameters.  Sometimes it's not so easy to translate between C-style data types and .NET.  Here's an example from the ProjectWise programming people (MostOfDavesClasses.cs)...

    [DllImport("dmscli.dll", CharSet = CharSet.Unicode)]
    public static extern bool aaApi_SelectDatasourceStatistics();
    

    That C# file is full of useful examples, definitions, and idioms that help get you from C to C#.

    Unfortunately, I think OBD API is the worst and most fragmented API from power platform products APIs, where the most of functionality is available only in (very) old C API

    The ProjectWise APIs are similarly antiquated.  That's why I found MostOfDavesClasses.cs extremely useful when programming with C# for PW Explorer.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Tilman,

    There are functions available to access the GridSystem

    Yes, good old C TriForma API ;-)

    Unfortunately, I think OBD API is the worst and most fragmented API from power platform products APIs, where the most of functionality is available only in (very) old C API, existing from MicroStation TriForma times, and only some are available in other APIs.

    but they seem to not be included in the c# wrappers.

    As Jon wrote, use P/Invoke (which is standard and often used feature of NET Framework).

    I have not extensive experience with OBD development, but what I heard from other people, to use C/C++ API is still "must do", when code for OBD is written.

    With regards,

      Jan

  • Hi everyone,

    thanks again for all your answers. 

    Bentley.Building.Api actually does provide an (undocumented) API.

    Luckily I finally found the following example in the SDK:

                BBA.ITFDrawingGrid drawingGrid = null;
                BBA.ITFGridSystemList gridSystems = null;
    
                BBA.ITFLoadableProject proj = GetCurrentProject();
    
                if (null == proj)
                    return;
    
                proj.GetDrawingGrid(false, 0, out drawingGrid);
    
                if (null == drawingGrid)
                    return;
    
                drawingGrid.GetGridSystems(0, out gridSystems);
                BBA.ITFGridSystemList gridSystemNode = gridSystems;
    
                for (BBA.ITFGridSystem gridSystem = gridSystemNode.AsTFGridSystem;
                    gridSystem != null;
                    gridSystemNode.GetNext("", out gridSystemNode), gridSystem = (gridSystemNode != null) ? gridSystemNode.AsTFGridSystem : null)
                {
                    BBA.ITFGridCurveList curves;
                    gridSystem.GetGridCurves(0, out curves);
                    BBA.ITFGridCurveList gridCurveNode = curves;
    
                    for (BBA.ITFGridCurve gridCurve = gridCurveNode.AsTFGridCurve;
                        gridCurve != null;
                        gridCurveNode.GetNext("", out gridCurveNode), gridCurve = gridCurveNode != null ? gridCurveNode.AsTFGridCurve : null)
                    {
                        BBA.TFdGridCurveType curveType;
                        gridCurve.GetType(0, out curveType);
                        double gridValue;
                        gridCurve.GetValue(0, out gridValue);
                    }
                }

    Cheers

    Tilman

  • Hi Tilman,

    Bentley.Building.Api actually does provide an (undocumented) API.

    You should be aware when any API is not documented, it's typically likely "subject to change". On the other hand, when it is used in example SDK, it's probably an omission.

    Luckily I finally found the following example in the SDK:

    The code looks fine, even when I would expect better code from anything written as example ;-)

    With regards,

      Jan