Setting General Inputs via function

Hello All,

I am trying to use a function to create a series of spheres which I have been able to complete.  My questions is how do I get the "for loop" to change the Level Name of each sphere, what is the best way to change a objects colour/level etc each time it is created?

Cheers,

Alex

PS, if anyone has a good way to add an "Asset Tag" to a GC custom object I would be really keen to know how.

Parents Reply Children
  • Sure, bear in mind I just chucked it together yesterday so it could do with a bit of polish but it gets the job done. The basic concept is:

    1. Take a GeometricNode as an input
    2. Get the Element associated with that node (Bentley.DgnPlatformNET.Element)
    3. Create a property setter
    4. Set the level you want
    5. Apply the property to the input Element
    6. Set the output feature of the active node to be our new element

            public NodeUpdateResult SetLevel
            (
                NodeUpdateContext updateContext,
                [GCDgnModelProvider, GCIn, GCReplicatable] GeometricNode Feature,
                [GCIn, GCReplicatable] string levelName
            )
            {
                try
                {
                    long id = Feature.GCElement().ElementId();
                    
                    DgnModel model = Session.Instance.GetActiveDgnModel();
                    Element element = model.FindElementById(new ElementId(ref id));
    
                    LevelId levelId = Settings.GetLevelIdFromName(levelName);
                    ElementPropertiesSetter elePropSetter = new ElementPropertiesSetter();
    
                    elePropSetter.SetLevel(levelId);
                    elePropSetter.Apply(element);
    
                    this.SetElement(element);
                }
                catch (Exception ex)
                {
                    return new NodeUpdateResult.TechniqueException(new Exception(String.Format("Error applying element symbology: {0}", ex.ToString())));
                }
    
                return NodeUpdateResult.Success;
            }

    One thing you still need to consider is how to output the resulting geometry though. If you cast the result as a specific node type then the export function will work, however if you leave the node type as a generic ElementBasedNode this will not get exported at all. For me personally there are a few options that I am currently considering to fix this issue:

    1. Create my own custom export node that will export all node geometry, regardless of type
    2. Create my own custom GeometricNodes for each GCType (solid, surface, curve etc) that have this function as a technique available. It would be quite a bit more work to do it this way, but keeps it in alignment with how the rest of GC works and I have a bunch of other custom nodes I've made that would also benefit from this approach
    3. Create this node such that it outputs each type as a separate constituent node output for use downstream in the graph
    4. Simply just output the 'ElementPath' as a node output, that can then be consumed by the default nodes

    I don't think there is a right or wrong answer to this problem, but certainly it needs a bit more thought since it will affect my future development plans and also the end-user experience. The perfect option in mind is if we could somehow cast the node output type at runtime, however this does not seem to be possible due to the nature of type inheritance

    Cheers,

    Ed

  • Hi Ed, 

    Thanks a lot for sharing your valuable knowledge. 

    Thanks, 

    Anik