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