Short Element in sequence

Hi,

I am trying to find a way to sort the list of elements in a sequential manner. In the given example below, I want GC to read the circles from 1 to 9 from left to right. The circles are drawn in Microstation and I will be using the range node to use it in GC. But when I will convert MS element to GC element, the list will be random. I know the way to manual fix the list but I am looking a way to automatically fix the list in increasing numbers from left to right. The other option I was thinking is to draw a curve or alignment along the element and somehow use GC to find elements along that curve so they will be in sequence.

Regards,

Jaimin Patel

Parents
  • If I understand your problem correctly then I have done something very similar before. Your process should be something like this:

    1. Get the points
    2. Project these points onto the alignment curve
    3. Sort them by the distance they are along the curve
    4. Return the original points (prior to projection) after they are sorted

    There are some good examples of sorting if you search the help documents in GC, but to help you out here is the function adapted for your use case, where all the magic happens:

    Point function(Point PointsToSort)
    {
        //Declare our output points variable as a list
        Point sortedPoints = {};
        
        //Declare the sorting function
        bool sortByDistanceAlong(Point pt1, Point pt2)
        {
            return pt1.DistanceAlongCurve < pt2.DistanceAlongCurve;
        }
        
        //Sort the input points using our sorting function
        sortedPoints = Sort(PointsToSort, sortByDistanceAlong);
        
        //Return the sorted points (as the original points prior to projecting onto curve)
        return sortedPoints.PointToProjectOntoCurve;
    }

    And the original GCT

    // Bentley GenerativeComponents Transaction File -- File structure version 1.60. (Please do not delete or change this line.)
    
    environment
    {
        GCVersion                 = '10.09.00.68';
        MSVersion                 = '10.09.00.83';
        MSProject                 = '';
        MSDesignFile              = 'C:\Users\Ed\Desktop\Test\Sorting.dgn';
        MSMasterUnit              = {Meter, 'mm', Metric, 1.0, 1000.0};
        MSSubUnit                 = {Meter, 'mm', Metric, 1.0, 1000.0};
        MSStorageUnit             = {Meter, '', Metric, 1.0, 1000.0};
        MSUorsPerStorageUnit      = 1000.0;
    }
    
    transaction 1 stateChange 'Add baseCS'
    {
        gcModel
        {
            node User.Objects.baseCS Bentley.GC.NodeTypes.CoordinateSystem
            {
                Technique                 = 'AtDGNModelOrigin';
                DGNModelName              = 'Design Model';
                SymbolSize                = 1.0;
                GraphLocation             = <auto> {40.0, 40.0, 0.0, 118.59};
            }
        }
    }
    
    transaction 2 stateChange 'Add point1, point2, point3, point4, point5'
    {
        gcModel
        {
            node User.Objects.point1 Bentley.GC.NodeTypes.Point
            {
                Technique                 = 'ByCartesianCoordinates';
                CoordinateSystem          = baseCS;
                XTranslation              = <free> 17499.6416776672;
                YTranslation              = <free> 8323.52045326385;
                ZTranslation              = <free> 0.0;
                GraphLocation             = <auto> {314.0, 40.0, 0.0, 158.87};
            }
            node User.Objects.point2 Bentley.GC.NodeTypes.Point
            {
                Technique                 = 'ByCartesianCoordinates';
                CoordinateSystem          = baseCS;
                XTranslation              = <free> 28148.3227252336;
                YTranslation              = <free> 27086.9094148109;
                ZTranslation              = <free> 0.0;
                GraphLocation             = <auto> {314.0, 238.87, 0.0, 158.87};
            }
            node User.Objects.point3 Bentley.GC.NodeTypes.Point
            {
                Technique                 = 'ByCartesianCoordinates';
                CoordinateSystem          = baseCS;
                XTranslation              = <free> 40660.5229561241;
                YTranslation              = <free> 36668.214416452;
                ZTranslation              = <free> 0.0;
                GraphLocation             = <auto> {314.0, 437.74, 0.0, 158.87};
            }
            node User.Objects.point4 Bentley.GC.NodeTypes.Point
            {
                Technique                 = 'ByCartesianCoordinates';
                CoordinateSystem          = baseCS;
                XTranslation              = <free> 61691.6680250677;
                YTranslation              = <free> 40527.3511532241;
                ZTranslation              = <free> 0.0;
                GraphLocation             = <auto> {314.0, 636.61, 0.0, 158.87};
            }
            node User.Objects.point5 Bentley.GC.NodeTypes.Point
            {
                Technique                 = 'ByCartesianCoordinates';
                CoordinateSystem          = baseCS;
                XTranslation              = <free> 77531.5810833227;
                YTranslation              = <free> 48245.6246267683;
                ZTranslation              = <free> 0.0;
                GraphLocation             = <auto> {314.0, 835.48, 0.0, 158.87};
            }
        }
    }
    
    transaction 3 stateChange 'Add bsplineCurve1'
    {
        gcModel
        {
            node User.Objects.bsplineCurve1 Bentley.GC.NodeTypes.BSplineCurve
            {
                Technique                 = 'ByPoles';
                Poles                     = {point1, point2, point3, point4, point5};
                Order                     = 0;
                GraphLocation             = {602.531, 45.039, 0.0, 118.59};
            }
        }
    }
    
    transaction 4 stateChange 'Add point6'
    {
        gcModel
        {
            node User.Objects.point6 Bentley.GC.NodeTypes.Point
            {
                Technique                 = 'ByCartesianCoordinates';
                CoordinateSystem          = baseCS;
                XTranslation              = <free> 36134.8335109083;
                YTranslation              = <free> 50774.0245577569;
                ZTranslation              = <free> 0.0;
                GraphLocation             = <auto> {862.0, 40.0, 0.0, 158.87};
            }
        }
    }
    
    transaction 5 stateChange 'Add point7'
    {
        gcModel
        {
            node User.Objects.point7 Bentley.GC.NodeTypes.Point
            {
                Technique                 = 'ByCartesianCoordinates';
                CoordinateSystem          = baseCS;
                XTranslation              = <free> 21626.0055835992;
                YTranslation              = <free> 38398.1722639705;
                ZTranslation              = <free> 0.0;
                GraphLocation             = <auto> {862.0, 238.87, 0.0, 158.87};
            }
        }
    }
    
    transaction 6 stateChange 'Add point8'
    {
        gcModel
        {
            node User.Objects.point8 Bentley.GC.NodeTypes.Point
            {
                Technique                 = 'ByCartesianCoordinates';
                CoordinateSystem          = baseCS;
                XTranslation              = <free> 52640.2891346363;
                YTranslation              = <free> 56230.0454614692;
                ZTranslation              = <free> 0.0;
                GraphLocation             = <auto> {862.0, 437.74, 0.0, 158.87};
            }
        }
    }
    
    transaction 7 stateChange 'Add randomPoints'
    {
        gcModel
        {
            node User.Objects.randomPoints Bentley.GC.NodeTypes.Point
            {
                Technique                 = 'ProjectOntoCurve';
                Curve                     = bsplineCurve1;
                PointToProjectOntoCurve   = {point6, point7, point8};
                GraphLocation             = {1173.258, 46.239, 0.0, 132.017};
            }
        }
    }
    
    transaction 8 stateChange 'Add sortedPoints'
    {
        gcModel
        {
            node User.Objects.sortedPoints Bentley.GC.NodeTypes.Point
            {
                Technique                 = 'ByFunction';
                Function                  = Point function(Point PointsToSort)
                                            {
                                                //Declare our output points variable as a list
                                                Point sortedPoints = {};
                                            
                                                //Declare the sorting function
                                                bool sortByDistanceAlong(Point pt1, Point pt2)
                                                {
                                                    return pt1.DistanceAlongCurve < pt2.DistanceAlongCurve;
                                                }
                                            
                                                //Sort the input points using our sorting function
                                                sortedPoints = Sort(PointsToSort, sortByDistanceAlong);
                                            
                                                //Return the sorted points (as the original points prior to projecting onto curve)
                                                return sortedPoints.PointToProjectOntoCurve;
                                            };
                DebuggerTrigger           = DebuggerTriggerLevel.Breakpoints;
                PointsToSort              = randomPoints;
                GraphLocation             = {1500.329, 50.571, 0.0, 132.017};
            }
        }
    }

    Answer Verified By: Jaimin Patel 

  • Nice Ed,
    I like that function.

    I have used a simple expression in the past if you wanted to just grab them in order related to X direction.

    from CL in circle1 orderby CL.CenterPoint.X

    That will give them in order of x distance. 
    I guess you could then do a circle bycopytransform using the baseCS for both the from and to and then just the sorted list. that would give you nice new circle names in order if needed.

  • Nice one Wayne... didn't realise that you could also do this with a linq query expression! I suppose you could adapt this to work with the same script above for an easier read

    Edit - couldn't help myself, wanted to try it out...  here is the syntax if you want to use Linq Query syntax:
    (from pt in randomPoints orderby pt.DistanceAlongCurve reverse).PointToProjectOntoCurve

    Note that you need to reverse the order as it seems to sort from largest to smallest otherwise, and then encapsulate the output of the sort so that we can access the original "PointToProjectOntoCurve" parameter (to return the original points before projection)

    Edit2 - If you want to use this directly within a Point node (using the Point.ByFunction method), you could write it like this:

    Point function(Point PointsToSort)
    {
        return (from pt in PointsToSort orderby pt.DistanceAlongCurve reverse).PointToProjectOntoCurve;
    }

    Pretty neat since it's just one line of code... Thanks for the suggestion Wayne!

  • Hi Wayne,

    Thanks for your suggestion. From my limited understanding of coding, your method is taking distance from baseCS in the X direction, it works when all the objects are placed in increasing X-direction value, however in my case I would have a scenario, where I will have objects which will be in decreasing X-direction distance and I still need a sequential number along my alignment. For this, I found another way which I think works fine. Please refer to the response I provided to Ed and let me know if there is any improvisation or feedback.

    Regards,

    Jaimin Patel

Reply
  • Hi Wayne,

    Thanks for your suggestion. From my limited understanding of coding, your method is taking distance from baseCS in the X direction, it works when all the objects are placed in increasing X-direction value, however in my case I would have a scenario, where I will have objects which will be in decreasing X-direction distance and I still need a sequential number along my alignment. For this, I found another way which I think works fine. Please refer to the response I provided to Ed and let me know if there is any improvisation or feedback.

    Regards,

    Jaimin Patel

Children
No Data