Accessing Element information - GC

Afternoon,

i'm trying to access the element information via GC and then export the information to excel in a structured way.

does anyone know how to get the element information?

Thanks 

Parents Reply Children
  • Hi L,

    In the current versions of GenerativeComponents, there is no ready-made functionality to achieve what you are looking for.  However, utilizing GC's extensibility, the development team suggests the following solution:

    Using the example solution that is delivered with GenerativeComponents, a couple of functions can be added to the ScriptFunctions.cs file.

    Here are the steps:

    (1)

    At the top of ScriptFunctions.cs add:

    using Bentley.GenerativeComponents;
    using Bentley.GenerativeComponents.Features;
    using Bentley.GenerativeComponents.MicroStationElements;

    (2)

    In the Load method, add this statement:

    nameCatalog.AddNamespaceLevelFunction("GetElementID", "long function(Node node)", GetElementID);

    There are already two similar statements.  Just add this one below those two.

    (3)

    Below the Load method, add these two functions:

    /// <summary> Returns the element ID of a node. If the node does not have a corresponding geometric element, returns 0. </summary>
    static private void GetElementID(CallFrame callFrame)
    {
       IGCObject result = Boxer.Box(0);
       INode node = callFrame.UnboxArgument<INode>(0);
       Feature feature = node as Feature;
       if (feature != null)
          result = GetElementID(feature);
       callFrame.SetFunctionResult(result);
    }

    static IGCObject GetElementID( Feature feature)  
    {
       if (feature.ContainsReplicatedChildFeatures())
       {
          GCList result = new GCList();
          foreach (Feature child in feature.ReplicatedChildFeatures())
             result.Add(GetElementID(child)); // Recursive call.
          return result;
       }
       else
       {
          long elementID = feature.Element.SafeID64();
          return Boxer.Box(elementID);
       }
    }

    (4)

    Compile the sample project and load the DLL into GenerativeComponents.  In the list of functions you will see GetElementID.

    (5)

    Drag GetElementID into the Graph (will create a FunctionCall node) and hook the Cell node as input to the "node" input port.

    (6)

    The result of that function call is a single long integer for non-nested geometric nodes, a list of long integers for geometric nodes containing child nodes, etc. (there is a recursive call in GetElementID that will return the element IDs in whichever nesting the elements are contained in the top level node.)

       

  • I seem to be getting two errors, do you know why ?

  • Sorry, you ran up against a formatting error that I overlooked in the HTML version of the code. The last statement was missing the space between return and Boxer.Box. This should remove the two errors that you are showing in the screen capture. I have inserted that missing space in my previous response.

       

  • Wow! What else can you do by accessing the assemblies provided by GC?
  • With appropriate hyperbole: anything is possible!

    By design, the extensibility of GenerativeComponents is one of its intended strengths. There are so many things that can be done that even I cannot comprehensively enumerate them all.

    Here is a list of how extensibility in GC works:
    By modeling assemblies of nodes and encapsulating them as Generated Node Types (GNT). No coding required. Note that these assemblies of nodes may include nodes using the ByFunction technique.
    By using expressions in input properties of nodes (e.g. Length entry for line02.ByStartPointDirectionLength could be "line01.Length + 5.0"). Minimal "coding" from basic math expressions and calling built-in or scripted functions to more advanced one-line logical, search, and lambda expressions.
    By writing Script Transactions using C-language control flow (if, while, for, foreach, etc.). A step up in scripting/coding.
    By writing/scripting functions (C/C# syntax) and adding them to the available built-in functions. Another step up in scripting/coding.
    By using those or anonymous functions to generate nodes using their ByFunction technique.
    Any coding/scripting is supported by GC's built-in development environment, the Script Editor, with Statement Builder and auto-completion lowering the coding threshold.

    Access to assemblies that do not expose function libraries to GC's list of functions is available by unpacking the sample solution (C#) and then coding extensions to GenerativeComponents using a bona fide development environment, e.g. Visual Studio. Note that assemblies' APIs may need proper wrapping as shown in the coding example in order to expose them to GC application users.

    I hope I did not miss something...