GC Node for Item Types

HI Alifur,

Great Coffee Corner last week.

You mentioned that GC does not support Item Types.

Are there any plans to support this? I know you mentioned using DataGroups but this is only available for OBD.

DataGroups also do not support Expressions and is quite limited functionality-wise. It seems like a lot of new developments will be done at platform level using Item Types, which duplicates a lot of the DGS functions..and would be easier for other verticals like OpenRoads, OpenBridge etc to adopt and share info.

Parents
  • Dominic. Check out Edward Ashbolt's GitHub repository called GCcommunity it included an Item Types node

    Regards

    Chris


    AECOM Roads UK&I Digital Engineering, Design & Solutions Lead | Sector Information Management Lead

    Associate Director – Digital

    OpenRoads Designer 10.12 | MicroStation 2023 | ProjectWise CE 10.3.4 | ContextCapture | ProjectWise PowerShell 2023 | ProjectWise WSG API | Generative Components | OpenBridge Designer 10.12

    Civil 3D 2023 | Dynamo | Navisworks Manage

    PowerShell | Visual Studio | Office 365 | Power Platform | Teams | SharePoint | Visio

    Speckle | BIMVision | Revizto | Solibri

    Answer Verified By: dominic SEAH 

  • Thanks Chris. I have been a bit slack in keeping my repo updated, but let me know if you would like a revised version with improvements made and support for update 8.
    Cheers,

    Ed

  • Not too sure I haven't tested expressions since I didn't have a requirement for it... If you find a solution please let me know about it though! Have a look within the Bentley.ECObjects.Expressions lib, there are a number of methods available for working with expressions there. 

    The (slightly) complicated part would be taking GC inputs (I assume as a string) for your expressions since there would be no validation tools available, and then having to parse those strings as ECProperties. One way to achieve this might be via symbols, e.g. <prop1> * <prop2> but you would need to obviously consider the fact you may need '<' and '>' chars for other purposes like greater than / less than; so perhaps xml would be the best option here since you could explicitly specify your input is an expression and also which items within the string are properties rather than plain text e.g.
    <ECExpression><ECProperty>prop1</ECProperty> * <ECProperty>prop2</ECProperty></ECExpression>

    That would make it much easier to consume and validate each component of your expression.

    BTW here is the updated version of my item types class:

    using System;
    using System.Windows;
    using System.Collections.Generic;
    using System.ComponentModel;
    using Bentley.GenerativeComponents;
    using Bentley.GenerativeComponents.AddInSupport;
    using Bentley.GenerativeComponents.ElementBasedNodes;
    using Bentley.GenerativeComponents.ElementBasedNodes.Specific;
    using Bentley.GenerativeComponents.GCScript;
    using Bentley.GenerativeComponents.View;
    using Bentley.DgnPlatformNET;
    using Bentley.DgnPlatformNET.Elements;
    using Bentley.MstnPlatformNET;
    using Bentley.DgnPlatformNET.DgnEC;
    using Bentley.ECObjects.Schema;
    using Bentley.ECObjects.Instance;
    
    namespace GCCommunity_ORD
    {
        [GCNamespace("User")]
        [GCNodeTypePaletteCategory("Custom")]
        [GCNodeTypeIcon("Resources/Items.png")]
        [GCSummary("Read, attach and update item properties on elements.")]
    
        public class ItemTypes : GeometricNode
        {
            [GCDefaultTechnique]
            [GCSummary("Read Items that are attached to the input elements.")]
            [GCParameter("ElementsToRead", "Input elements to read from.")]
            [GCParameter("ItemTypeName", "The Item Type.")]
    
            public NodeUpdateResult ReadItems
            (
                NodeUpdateContext updateContext,
                [GCIn, GCReplicatable, GCDgnModelProvider] GeometricNode ElementsToRead,
                [GCOut, GCReplicatable, GCInitiallyPinned] ref string[] Items,
                [GCOut, GCReplicatable, GCInitiallyPinned] ref string[][] ItemProps,
                [GCOut, GCReplicatable, GCInitiallyPinned] ref string[][] ItemValues
            )
            {
                try
                {
                    DgnFile dgnFile = Session.Instance.GetActiveDgnFile();
                    DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
    
                    long id = ElementsToRead.GCElement().ElementId();
                    Element element = dgnModel.FindElementById(new ElementId(ref id));
                    //Element element = ElementsToRead.Element();
    
                    CustomItemHost customItemHost = new CustomItemHost(element, false);
    
                    IList<IDgnECInstance> ecInstanceList = customItemHost.CustomItems;
    
                    List<string> typenames = new List<string>();
                    List<string[]> props = new List<string[]>();
                    List<string[]> values = new List<string[]>();
    
                    foreach (IDgnECInstance ecInstance in ecInstanceList)
                    {
                        typenames.Add(ecInstance.ClassDefinition.DisplayLabel);
    
                        List<string> iprops = new List<string>();
                        List<string> ivalues = new List<string>();
    
                        IEnumerator<IECPropertyValue> ie = ecInstance.GetEnumerator(true, true);
                        while (ie.MoveNext())
                        {
                            iprops.Add(ie.Current.Property.DisplayLabel);
    
                            string propValue = ie.Current.StringValue;
                            bool getValue = Bentley.ECObjects.Schema.ECNameValidation.DecodeFromValidName(ref propValue);
                            ivalues.Add(propValue);
                        }
    
                        props.Add(iprops.ToArray());
                        values.Add(ivalues.ToArray());
                    }
    
                    Items = typenames.ToArray();
                    ItemProps = props.ToArray();
                    ItemValues = values.ToArray();
                    //this.AddOrSetOutputOnlyAdHocProperty("ItemTypeNames", typenames.ToArray(), null, true);
                    //this.AddOrSetOutputOnlyAdHocProperty("ParameterNames", props.ToArray(), null, true);
                    //this.AddOrSetOutputOnlyAdHocProperty("ParameterValues", values.ToArray(), null, true);
                }
                catch (Exception ex)
                {
                    return new NodeUpdateResult.TechniqueException(ex);
                }
                return NodeUpdateResult.Success;
            }
    
            [GCTechnique]
            [GCSummary("Attach an ItemTypeLibrary and/or write new values to Items on the input elements.")]
            [GCParameter("Elements", "Input elements to write to.")]
            public NodeUpdateResult WriteItems
            (
                NodeUpdateContext updateContext,
                [GCDgnModelProvider, GCReplicatable] GeometricNode ElementsToWriteTo,
                [GCReplicatable] string ItemTypeLibraryName,
                [GCReplicatable] string Item,
                [GCReplicatable] string[] Properties,
                [GCReplicatable] object[] Values
            )
            {
                try
                {
                    DgnFile dgnFile = Session.Instance.GetActiveDgnFile();
                    DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
    
                    long id = ElementsToWriteTo.GCElement().ElementId();
                    Element element = dgnModel.FindElementById(new ElementId(ref id));
    
    
                    ItemTypeLibrary itl = ItemTypeLibrary.FindByName(ItemTypeLibraryName, dgnFile);
                    ItemType itemType = itl.GetItemTypeByName(Item);
    
                    CustomItemHost customItemHost = new CustomItemHost(element, false);
    
                    IDgnECInstance ecInstance = customItemHost.GetCustomItem(ItemTypeLibraryName, Item);
                    if (ecInstance == null)
                    {
                        ecInstance = customItemHost.ApplyCustomItem(itemType);
                    }
                    for (int i = 0; i < Properties.Length; i++)
                    {
                        string propName = Properties[i];
                        bool getName = Bentley.ECObjects.Schema.ECNameValidation.EncodeToValidName(ref propName);
                        ecInstance.SetAsString(propName, Values[i].ToString());
                    }
                    ecInstance.WriteChanges();
                }
                catch (Exception ex)
                {
                    return new NodeUpdateResult.TechniqueException(ex);
                }
    
                return NodeUpdateResult.Success;
            }
        }
    }

    Previously there was no name validation for property names, and due to the syntax requirements any spaces or special chars within the property name would cause issues in the previous class.

    Good luck!


    Ed

  • Thanks, Ed.

    Snoopping around, it does look there is already a bit of support for verification within the Item Types API, even a bit for VBA

    Verification of expressions seems to be covered. I would have thought verification of properties would be an even more common task.

    Do you know if BDN uses github as well?

    What kind of performance are you getting with your Node?

  • Hi Alifur,

    I've verified Chris' response, but the question was actually for you. It would be great if you could confirm if this in on the roadmap. Seems like something that would good to have at the core, optimised and chugging away?

  • Hello Dominic, 

    Are there any plans to support this? I know you mentioned using DataGroups but this is only available for OBD.

    Yes, so far there is nothing planned with Item types yet to get in GC. The possible workflow for building users is to use datagroup. 

    It seems like a lot of new developments will be done at platform level using Item Types, which duplicates a lot of the DGS functions..and would be easier for other verticals like OpenRoads, OpenBridge etc to adopt and share info.

    Definitely the working functionality of item types are same as that of Datagroup. As of now Edward's custom Item Types node is an solid workaround for the time being. 

    I will discuss with Product management & the development team about the scope of Item Types in GC. 

    Regards,
    Alifur

    Answer Verified By: dominic SEAH 

  • Hi Ed, Dominic

    I've just pushed my latest work on the GC Communities addon to github in a Forked version.

    In it you'll see my working Alignment, Terrain, Corridor and Template nodes, as well as a modified version of the Item Types one (will merge your new code today Ed) which i have added a third function to instead of write properties to item type properties, it simply attaches an item type. I wrote this as I have lots of Item Types with expressions built in.

    Link below:

    github.com/.../generative-components

    Regards

    Chris


    AECOM Roads UK&I Digital Engineering, Design & Solutions Lead | Sector Information Management Lead

    Associate Director – Digital

    OpenRoads Designer 10.12 | MicroStation 2023 | ProjectWise CE 10.3.4 | ContextCapture | ProjectWise PowerShell 2023 | ProjectWise WSG API | Generative Components | OpenBridge Designer 10.12

    Civil 3D 2023 | Dynamo | Navisworks Manage

    PowerShell | Visual Studio | Office 365 | Power Platform | Teams | SharePoint | Visio

    Speckle | BIMVision | Revizto | Solibri

Reply
  • Hi Ed, Dominic

    I've just pushed my latest work on the GC Communities addon to github in a Forked version.

    In it you'll see my working Alignment, Terrain, Corridor and Template nodes, as well as a modified version of the Item Types one (will merge your new code today Ed) which i have added a third function to instead of write properties to item type properties, it simply attaches an item type. I wrote this as I have lots of Item Types with expressions built in.

    Link below:

    github.com/.../generative-components

    Regards

    Chris


    AECOM Roads UK&I Digital Engineering, Design & Solutions Lead | Sector Information Management Lead

    Associate Director – Digital

    OpenRoads Designer 10.12 | MicroStation 2023 | ProjectWise CE 10.3.4 | ContextCapture | ProjectWise PowerShell 2023 | ProjectWise WSG API | Generative Components | OpenBridge Designer 10.12

    Civil 3D 2023 | Dynamo | Navisworks Manage

    PowerShell | Visual Studio | Office 365 | Power Platform | Teams | SharePoint | Visio

    Speckle | BIMVision | Revizto | Solibri

Children