Hello,
I am using GenerativeComponents Update 8 (10.08.00.40).
I am trying to build upon the C# Sample Solution to create a Generative Component in C# which produces a PointNode as an output parameter but I am having no success and I cannot locate the SDK documentation for the GC Object Model. Please see a simple conceptual example for a generative component which takes two points and a coordinate system as inputs, and should provide a point node as an output that can be used for other purposes.
public class MidpointTestNode : ElementBasedNode { [GCDefaultTechnique] public NodeUpdateResult Default ( NodeUpdateContext updateContext, [GCDgnModelProvider] CoordinateSystemNode InputCoordSystem, IPointNode StartPoint, IPointNode EndPoint, [GCOut] ref PointNode MidPoint ) { // check inputs for validity if (StartPoint == EndPoint) return new NodeUpdateResult.TechniqueInvalidArguments(nameof(StartPoint), nameof(EndPoint)); DPoint3d startPt = StartPoint.GetDPoint3d(); DPoint3d endPt = EndPoint.GetDPoint3d(); DPoint3d uorStartPt = NativeDgnTools.FromMUToUOR(startPt); DPoint3d uorEndPt = NativeDgnTools.FromMUToUOR(endPt); // get the midpoint of the two input points DPoint3d midPt = 0.5 * (uorStartPt + uorEndPt); // create the midpoint node as an output MidPoint = new PointNode(); MidPoint.FromDPoint3d(midPt); // <-- this generates a NullReferenceException return NodeUpdateResult.Success; } }
I am guessing that I am supposed to use one of the static methods like PointNode.CreatePointNode() or PointNode.CreateConstituentNode() but without the SDK documentation or any sample code to adapt, I am not sure how to use them.
Can someone provide an example of how to return a Point node as an output parameter?
Regards,
Trevor
Hi Trevor,
A node technique method (such as 'Default') is intended to manage only the node's internal state. It's highly unusual for a technique method to create a new Node instance for the sole purpose of handing it off and otherwise forgetting about it.
Please try this:
1. Remove the parameter 'MidPoint' from your method's parameter list:
[GCOut] ref PointNode MidPoint // Remove
2. Replace these two statements:
MidPoint = new PointNode(); MidPoint.FromDPoint3d(midPt);
with this one:
CreateConstituentNode<PointNode>(this, "MidPoint", addToParent:true).FromDPoint3d(midPt);
From the user's point of view, there's no difference between an output parameter and a named constituent node.
HTH
Jeff
Answer Verified By: Trevor Watling
Ah thank you Jeff. That is in fact what I was trying to achieve. I need "output" nodes from various generative components to be inputs for other nodes.
Much appreciated.