GenerativeComponents Help

Using an anonymous function within the ByFunction technique

There are a number of different things that can be done using an anonymous function within the ByFunction technique. All of the following four examples in effect produce the same result.

  1. This function demonstrates one way to create a child node: By passing 'this' to the child node's constructor.

    Here, 'this' refers to the node being created; in the following example, the node basicLine1. Here 'this' is used in the sense of: in 'this' room (the one we are in).

    transaction 1 modelChange 'Add baseCS'
    {
        node User.Objects.baseCS Bentley.GC.NodeTypes.CoordinateSystem
        {
            Technique                 = 'AtModelOrigin';
            DGNModelName              = '3D Metric Design';
            SymbolSize                = 1;
            GraphLocation             = <auto> {40.0, 40.0};
        }
    }
    
    transaction 2 modelChange 'Add point01'
    {
        node User.Objects.point01 Bentley.GC.NodeTypes.Point
        {
            Technique                 = 'ByCartesianCoordinates';
            CoordinateSystem          = baseCS;
            XTranslation              = <free> -8.22917908270345;
            YTranslation              = <free> 8.47685877997411;
            ZTranslation              = <free> 0.0;
            GraphLocation             = <auto> {314.0, 40.0};
        }
    }
    
    transaction 3 modelChange 'Add point02'
    {
        node User.Objects.point02 Bentley.GC.NodeTypes.Point
        {
            Technique                 = 'ByCartesianCoordinates';
            CoordinateSystem          = baseCS;
            XTranslation              = <free> -1.34246198466439;
            YTranslation              = <free> 20.5289981902082;
            ZTranslation              = <free> 0.0;
            GraphLocation             = <auto> {314.0, 235.87};
        }
    }
    
    transaction 4 modelChange 'Create Line by Function – 1st Approach'
    {
        node User.Objects.basicLine1 Bentley.GC.NodeTypes.Line
        {
            Function                  = function(Point startPoint, Point endPoint)
                                        {
                                        Line exampleLine = new Line(this); 
                                        exampleLine.ByPoints(startPoint, endPoint); 
                                        };
            FunctionArguments         = {point01, point02};
        }
    	}  
  2. This function demonstrates how to directly modify the top-level node.

    The second way is the shortest and most direct approach, but there won't be any help from auto-complete with this one. Generally the user must write it as above and then abbreviate it, or know the method name and arguments by heart. Again, 'this' refers to the node being created.

    transaction 1 modelChange 'Add baseCS'
    {
        node User.Objects.baseCS Bentley.GC.NodeTypes.CoordinateSystem
        {
            Technique                 = 'AtModelOrigin';
            DGNModelName              = '3D Metric Design';
            SymbolSize                = 1;
            GraphLocation             = <auto> {40.0, 40.0};
        }
    }
    
    transaction 2 modelChange 'Add point01'
    {
        node User.Objects.point01 Bentley.GC.NodeTypes.Point
        {
            Technique                 = 'ByCartesianCoordinates';
            CoordinateSystem          = baseCS;
            XTranslation              = <free> -8.22917908270345;
            YTranslation              = <free> 8.47685877997411;
            ZTranslation              = <free> 0.0;
            GraphLocation             = <auto> {314.0, 40.0};
        }
    }
    
    transaction 3 modelChange 'Add point02'
    {
        node User.Objects.point02 Bentley.GC.NodeTypes.Point
        {
            Technique                 = 'ByCartesianCoordinates';
            CoordinateSystem          = baseCS;
            XTranslation              = <free> -1.34246198466439;
            YTranslation              = <free> 20.5289981902082;
            ZTranslation              = <free> 0.0;
            GraphLocation             = <auto> {314.0, 235.87};
        }
    }
    
    transaction 4 modelChange 'Create Line by Function 3rd Approach'
    {
        node User.Objects.basicLine3 Bentley.GC.NodeTypes.Line
        {
            Function                  = function(Point startPoint, Point endPoint)
                                        {
                                        Line exampleLine = new Line();  
                                        exampleLine.ByPoints(startPoint, endPoint);
                                        return exampleLine; 
                                        };
            FunctionArguments         = {point01, point02};
        }
    }
    
  3. This function demonstrates another way to create a child node: By passing no arguments to the child node's constructor, then returning the child node as the result of the function.

    Types are nodes for example, a Point, Line, Plane, etc.  Here the function is of type Line. Correspondingly a Line is returned at the end of the function. Specifying the type of the function is not mandatory within GenerativeComponents but doing so allows GenerativeComponents to enforce that returned value is of the same type.

    transaction 1 modelChange 'Add baseCS'
    {
        node User.Objects.baseCS Bentley.GC.NodeTypes.CoordinateSystem
        {
            Technique                 = 'AtModelOrigin';
            DGNModelName              = '3D Metric Design';
            SymbolSize                = 1;
            GraphLocation             = <auto> {40.0, 40.0};
        }
    }
    
    transaction 2 modelChange 'Add point01'
    {
        node User.Objects.point01 Bentley.GC.NodeTypes.Point
        {
            Technique                 = 'ByCartesianCoordinates';
            CoordinateSystem          = baseCS;
            XTranslation              = <free> -8.22917908270345;
            YTranslation              = <free> 8.47685877997411;
            ZTranslation              = <free> 0.0;
            GraphLocation             = <auto> {314.0, 40.0};
        }
    }
    
    transaction 3 modelChange 'Add point02'
    {
        node User.Objects.point02 Bentley.GC.NodeTypes.Point
        {
            Technique                 = 'ByCartesianCoordinates';
            CoordinateSystem          = baseCS;
            XTranslation              = <free> -1.34246198466439;
            YTranslation              = <free> 20.5289981902082;
            ZTranslation              = <free> 0.0;
            GraphLocation             = <auto> {314.0, 235.87};
        }
    }
    
    transaction 4 modelChange 'Create Line by Function 3rd Approach'
    {
        node User.Objects.basicLine3 Bentley.GC.NodeTypes.Line
        {
            Function                  = function(Point startPoint, Point endPoint)
                                        {
                                        Line exampleLine = new Line();  
                                        exampleLine.ByPoints(startPoint, endPoint);
                                        return exampleLine; 
                                        };
            FunctionArguments         = {point01, point02};
        }
    }
    
  4. This function demonstrates how to set the 'Success' status of the top-level node, regardless of whatever else the function is doing.

    bool is a boolean variable which is either true or false.  In this case the bool refers to the 'Success' status of the new node. Care is needed when using this syntax as the user can return true, even if no node is actually created.

    transaction 1 modelChange 'Add baseCS'
    {
        node User.Objects.baseCS Bentley.GC.NodeTypes.CoordinateSystem
        {
            Technique                 = 'AtModelOrigin';
            DGNModelName              = '3D Metric Design';
            SymbolSize                = 1;
            GraphLocation             = <auto> {40.0, 40.0};
        }
    }
    
    transaction 2 modelChange 'Add point01'
    {
        node User.Objects.point01 Bentley.GC.NodeTypes.Point
        {
            Technique                 = 'ByCartesianCoordinates';
            CoordinateSystem          = baseCS;
            XTranslation              = <free> -8.22917908270345;
            YTranslation              = <free> 8.47685877997411;
            ZTranslation              = <free> 0.0;
            GraphLocation             = <auto> {314.0, 40.0};
        }
    }
    
    transaction 3 modelChange 'Add point02'
    {
        node User.Objects.point02 Bentley.GC.NodeTypes.Point
        {
            Technique                 = 'ByCartesianCoordinates';
            CoordinateSystem          = baseCS;
            XTranslation              = <free> -1.34246198466439;
            YTranslation              = <free> 20.5289981902082;
            ZTranslation              = <free> 0.0;
            GraphLocation             = <auto> {314.0, 235.87};
        }
    }
    
    transaction 4 modelChange 'Create Line by Function - 4th Approach'
    {
        node User.Objects.basicLine4 Bentley.GC.NodeTypes.Line
        {
            Function                  = bool function(Point startPoint, Point
                                        endPoint)
                                        {
                                        Line exampleLine = new Line(this);
                                         
                                        exampleLine.ByPoints(startPoint, endPoint); 
                                        return true; 
                                        };
            FunctionArguments         = {point01, point02};
        }
    }