Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Recommended Posts

I find myself starring at the screen instead of making any progress. I have attached the before and after photo of my intent. Would this particular instance be easier with strings?

My current code works at coloring entities that start with a point (one of the shown orange ones to be specific) and it's listed below.

I believe my logic is correct, but am going about it the incorrect manner.

Any assist is appreciated!

 

Logic ::

GET ALL CHAIN PIECES
COLOR ALL ENTITIES COLOR 3 (CHECKS TO SEE WHAT'S LEFT)

IF ANY ENTITIES ARE COLOR 3 THEN LOOP
     FIND START POINT (N1)
         IF START POINT = aPOINT THEN COLOR 2 AND FIND NEXT CONNECTING SEGMENT AND GOTO N2
         IF START POINT =/= aPOINT THEN FIND NEXT CONNECTING SEGMENT AND GOTO N1

     FIND END POINT (N2)
         IF ENDPOINT = aPOINT THEN COLOR 2 AND FIND NEXT CONNECTING SEGMENT GOTO N3
         IF ENDPOINT =/= aPOINT THEN COLOR 2 AND FIND NEXT CONNECTING SEGMENT AND GOTO N2

     FIND NEXT START POINT (N3)
         IF START POINT = aPOINT THEN COLOR 2 AND FIND NEXT CONNECTING SEGMENT AND GOTO N2
         IF START POINT =/= aPOINT THEN COLOR 1 AND FIND NEXT CONNECTING SEGMENT AND GOTO N3

          FIND NEXT CONNECTING SEGMENT
              IF FIRST ENTITY ENDPOINT = SECOND ENTITY STARTPOINT THEN isNextSegment & RETURN ENTITY ID#
              IF FIRST ENTITY ENDPOINT =/= SECOND ENTITY STARTPOINT THEN isNotNextSegment & LOOP UNTIL TRUE

 

 

 

 

                foreach (var i in tempList8){
                    var GeoID = Geometry.RetrieveEntity(i);
                    var firstEntity = 0;
                    var secondEntity = 0;

                    if (GeoID is ArcGeometry arc){ // if first entity is arc
                        arcX1 = arc.EndPoint1.x; // Arc 1 x 1
                        arcX2 = arc.EndPoint2.x; // Arc 1 x 2
                        arcY1 = arc.EndPoint1.y; // Arc 1 y 1
                        arcY2 = arc.EndPoint2.y; // Arc 1 y 2
                        arcStartPoint = new Point3D(arcX1, arcY1, 0.0);
                        arcEndPoint = new Point3D(arcX2, arcY2, 0.0);
                        firstEntity = 1;
                    }

                    if (GeoID is LineGeometry line){ // if first entity is line
                        lineX1 = line.EndPoint1.x; // line 1 x 1
                        lineX2 = line.EndPoint2.x; // line 1 x 2
                        lineY1 = line.EndPoint1.y; // line 1 y 1
                        lineY2 = line.EndPoint2.y; // line 1 y 2
                        lineStartPoint = new Point3D(lineX1, lineY1, 0.0);
                        lineEndPoint = new Point3D(lineX2, lineY2, 0.0);
                        firstEntity = 2;
                    }

                    foreach (var u in tempList8){
                        var nextGeoID = Geometry.RetrieveEntity(u);

                        if (nextGeoID is ArcGeometry nextarc){ // if second entity is arc
                            nextarcX1 = nextarc.EndPoint1.x; // Arc 2 x 1
                            nextarcX2 = nextarc.EndPoint2.x; // Arc 2 x 2
                            nextarcY1 = nextarc.EndPoint1.y; // Arc 2 y 1
                            nextarcY2 = nextarc.EndPoint2.y; // Arc 2 y 2
                            nextarcStartPoint = new Point3D(nextarcX1, nextarcY1, 0.0);
                            nextarcEndPoint = new Point3D(nextarcX2, nextarcY2, 0.0);
                            secondEntity = 1;
                        }

                        if (nextGeoID is LineGeometry nextline){ // if second entity is line
                            nextlineX1 = nextline.EndPoint1.x; // line 2 x 1
                            nextlineX2 = nextline.EndPoint2.x; // line 2 x 2
                            nextlineY1 = nextline.EndPoint1.y; // line 2 y 1
                            nextlineY2 = nextline.EndPoint2.y; // line 2 y 2
                            nextlineStartPoint = new Point3D(nextlineX1, nextlineY1, 0.0);
                            nextlineEndPoint = new Point3D(nextlineX2, nextlineY2, 0.0);
                            secondEntity = 2;
                        }

                        if ((firstEntity == 1) && (secondEntity == 1)){
                            foreach (var v in tempList9){
                                var w = PointGeometry.RetrieveEntity(v);
                                if (w is PointGeometry point){
                                    var ux = point.Data.x;
                                    var uy = point.Data.y;
                                    Point3D uPoint = new Point3D(ux, uy, 0.0);
                                    var startDistance = Math.Abs(VectorManager.Distance(uPoint, arcStartPoint));
                                    var endDistance = Math.Abs(VectorManager.Distance(uPoint, arcEndPoint));
                                    if (startDistance <= tolerance){
                                        GeoID.Color = 10;
                                        GeoID.Commit();
                                    }
                                }
                            }
                        }//If arc and arc
                        if ((firstEntity == 1) && (secondEntity == 2)){}//If arc and line
                        if ((firstEntity == 2) && (secondEntity == 1)){}//If line and arc
                        if ((firstEntity == 2) && (secondEntity == 2)){}//If line and line
                    }
                }

 

crossoverColor.png

Link to comment
Share on other sites

Update :: It only finds ONE match. Even though it checks all four chains.

I've tried changing chainDirection and also looking for endpoints instead of startpoints.

🤷‍♂️

 

                //If any entity in chain is color 12, loop through step 0, step 1, and step 2
                //step 0 -- get entity
                //step 0 -- see if entity start point is crossover point (point from templist9)
                //step 0 -- if match, send to step 1
                //step 0 -- if not match, get next entity and repeat step 0
                //step 1 -- get entity
                //step 1 -- color 10
                //step 1 -- get next entity
                //step 1 -- see if next entity start point is a crossover point (point from templist9)
                //step 1 -- if match, send next entity to step 2
                //step 1 -- if not match, color 10 and send next entity to step 1
                //step 2 -- get entity
                //step 2 -- color 11
                //step 2 -- get next entity
                //step 2 -- see if next entity start point is a crossover point (point from templist9)
                //step 2 -- if match, send next entity to step 1
                //step 2 -- if not match, color 11 and send next entity to step 2
                var chainDetails = new Mastercam.Database.Interop.ChainDetails();// Preps the ChainDetails plugin
                var selectedChains = ChainManager.ChainAll(75);// Chains all geometry on level 75
                var chainDirection = ChainDirectionType.CounterClockwise;// Going to be used to make sure all chains go the same direction
                foreach (var chain in selectedChains)// For each of the chains selected
                {
                    templist10.Clear();
                    chain.Direction = chainDirection;//Makes all chains go same direction
                    var chainData = chainDetails.GetData(chain);//Gets the data of the chain
                    var chainEntityList = chainData.ChainEntities;//Creates a list of entities in (geometry format) the selected chain
                    var step = 0;//Sets to step 0 (should be 0 until an entity on chain is found with start point matching crossover point)
                    foreach (var t in chainEntityList)// For each entity in that chain
                    {
                        templist10.Add(t.Key.GetEntityID());// Changes to INT format
                        foreach (var chainEntity in templist10)//For each chain entity in the selected chain
                        {
                            if (step == 1) { break;};//If step is 1 (match is found in chain for start point and point location) exit the loop through entities
                            var entity = Geometry.RetrieveEntity(chainEntity);//Gets entity based on GeoID
                            if (entity is ArcGeometry arc && step == 0)//If first entity is arc and at step 0
                            { 
                                arcX1 = arc.EndPoint1.x; // Arc 1 x 1
                                arcX2 = arc.EndPoint2.x; // Arc 1 x 2
                                arcY1 = arc.EndPoint1.y; // Arc 1 y 1
                                arcY2 = arc.EndPoint2.y; // Arc 1 y 2
                                arcStartPoint = new Point3D(arcX1, arcY1, 0.0); // Arc 1 start point
                                arcEndPoint = new Point3D(arcX2, arcY2, 0.0); // Arc 1 end point
                                firstEntity = 1; // Saves that first entity is Arc
                                foreach (var v in tempList9)// For each point marked as crossover location
                                {
                                    var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                    if (w is PointGeometry point && step == 0)//Confirms GeoID is a point and checks we are on step 0
                                    {
                                        var ux = point.Data.x;// X location of point
                                        var uy = point.Data.y;// Y location of point
                                        Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                        var arcStartDistance = Math.Abs(VectorManager.Distance(uPoint, arcEndPoint));// Distance between entity start point and crossover point
                                        if (arcStartDistance <= tolerance)// If distance is less than tolerance, complete task
                                        {
                                            entity.Color = 10;// Changes color of entity to 10
                                            entity.Commit();// Saves entity into Mastercam Database
                                            step = 1;// Sets step to 1
                                            break;//Exits the check to see if entity start point matches point location
                                        }
                                    }
                                }
                            }
                            if (entity is LineGeometry line && step == 0)//If first entity is line and at step 0
                            {
                                lineX1 = line.EndPoint1.x; // line 1 x 1
                                lineX2 = line.EndPoint2.x; // line 1 x 2
                                lineY1 = line.EndPoint1.y; // line 1 y 1
                                lineY2 = line.EndPoint2.y; // line 1 y 2
                                lineStartPoint = new Point3D(lineX1, lineY1, 0.0); // Line 1 start point
                                lineEndPoint = new Point3D(lineX2, lineY2, 0.0); // Line 1 end point
                                firstEntity = 2; // Saves that first entity is Line
                                foreach (var v in tempList9)// For each point marked as crossover location
                                {
                                    var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                    if (w is PointGeometry point && step == 0)//Confirms GeoID is a point and checks we are on step 0
                                    {
                                        var ux = point.Data.x;// X location of point
                                        var uy = point.Data.y;// Y location of point
                                        Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                        var lineStartDistance = Math.Abs(VectorManager.Distance(uPoint, lineEndPoint));// Distance between entity start point and crossover point
                                        if (lineStartDistance <= tolerance)// If distance is less than tolerance, complete task
                                        {
                                            entity.Color = 10;// Changes color of entity to 10
                                            entity.Commit();// Saves entity into Mastercam Database
                                            step = 1;// Sets step to 1
                                            break;//Exits the check to see if entity start point matches point location
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

 

Link to comment
Share on other sites

It now operates halfway. It goes to step 0, step 1, and then step 3, but then it stops on that chain. It's supposed to go to step 2 after that. Ideas?

 

                var step = 0;
                var chainDetails = new Mastercam.Database.Interop.ChainDetails();// Preps the ChainDetails plugin
                var selectedChains = ChainManager.ChainAll(75);// Chains all geometry on level 75
                var chainDirection = ChainDirectionType.CounterClockwise;// Going to be used to make sure all chains go the same direction
                ChainManager.StartChainAtLongest(selectedChains);
                foreach (var chain in selectedChains){
                    var chainData = chainDetails.GetData(chain);
                    var chainEntityList = chainData.ChainEntities;
                    foreach (var t in chainEntityList){
                        (t.Key).Color = 9;
                        (t.Key).Commit();
                    }
                }
                foreach (var chain in selectedChains){
                    templist10.Clear();
                    step = 0;
                    chain.Direction = chainDirection;
                    var chainEntity = ChainManager.GetGeometryInChain(chain);
                    if (step == 0){
                        System.Windows.Forms.MessageBox.Show("step 0");
                        foreach (var entity in chainEntity){
                            if (entity is ArcGeometry arc && step == 0){
                                arcX1 = arc.EndPoint1.x; // Arc 1 x 1
                                arcX2 = arc.EndPoint2.x; // Arc 1 x 2
                                arcY1 = arc.EndPoint1.y; // Arc 1 y 1
                                arcY2 = arc.EndPoint2.y; // Arc 1 y 2
                                arcStartPoint = new Point3D(arcX1, arcY1, 0.0); // Arc 1 start point
                                arcEndPoint = new Point3D(arcX2, arcY2, 0.0); // Arc 1 end point
                                firstEntity = 1; // Saves that first entity is Arc
                                foreach (var v in tempList9){
                                    var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                    if (w is PointGeometry point && step == 0){
                                        var ux = point.Data.x;// X location of point
                                        var uy = point.Data.y;// Y location of point
                                        Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                        var arcStartDistance = Math.Abs(VectorManager.Distance(uPoint, arcStartPoint));// Distance between entity start point and crossover point
                                        var arcEndDistance = Math.Abs(VectorManager.Distance(uPoint, arcEndPoint));// Distance between entity end point and crossover point
                                        if (arcStartDistance <= tolerance && step == 0){
                                            entity.Color = 10;// Changes color of entity to 10
                                            entity.Commit();// Saves entity into Mastercam Database
                                            step = 1;// Sets step to 1
                                            templist10.Add(entity.GetEntityID());
                                        }
                                    }
                                }
                            }
                            if (entity is LineGeometry line && step == 0){
                                lineX1 = line.EndPoint1.x; // line 1 x 1
                                lineX2 = line.EndPoint2.x; // line 1 x 2
                                lineY1 = line.EndPoint1.y; // line 1 y 1
                                lineY2 = line.EndPoint2.y; // line 1 y 2
                                lineStartPoint = new Point3D(lineX1, lineY1, 0.0); // Line 1 start point
                                lineEndPoint = new Point3D(lineX2, lineY2, 0.0); // Line 1 end point
                                firstEntity = 2; // Saves that first entity is Line
                                foreach (var v in tempList9){
                                    var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                    if (w is PointGeometry point && step == 0){
                                        var ux = point.Data.x;// X location of point
                                        var uy = point.Data.y;// Y location of point
                                        Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                        var lineStartDistance = Math.Abs(VectorManager.Distance(uPoint, lineStartPoint));// Distance between entity start point and crossover point
                                        var lineEndDistance = Math.Abs(VectorManager.Distance(uPoint, lineEndPoint));// Distance between entity end point and crossover point
                                        if (lineStartDistance <= tolerance && step == 0){
                                            entity.Color = 10;// Changes color of entity to 10
                                            entity.Commit();// Saves entity into Mastercam Database
                                            step = 1;// Sets step to 1
                                            templist10.Add(entity.GetEntityID());
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (step == 1){
                        System.Windows.Forms.MessageBox.Show("step 1");
                        foreach (var entity in chainEntity){
                            if (firstEntity == 1 && step == 1){
                                var thisEntity = ArcGeometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is ArcGeometry arc && step == 1){
                                arcX1 = arc.EndPoint1.x; // Arc 1 x 1
                                arcX2 = arc.EndPoint2.x; // Arc 1 x 2
                                arcY1 = arc.EndPoint1.y; // Arc 1 y 1
                                arcY2 = arc.EndPoint2.y; // Arc 1 y 2
                                arcStartPoint = new Point3D(arcX1, arcY1, 0.0); // Arc 1 start point
                                arcEndPoint = new Point3D(arcX2, arcY2, 0.0); // Arc 1 end point
                                    if (entity is ArcGeometry nextArc && (entity.GetEntityID() != templist10[0]) && step == 1){
                                        nextArcX1 = nextArc.EndPoint1.x;
                                        nextArcX2 = nextArc.EndPoint2.x;
                                        nextArcY1 = nextArc.EndPoint1.y;
                                        nextArcY2 = nextArc.EndPoint2.y;
                                        nextArcStartPoint = new Point3D(nextArcX1, nextArcY1, 0.0); // Arc 2 start point
                                        nextArcEndPoint = new Point3D(nextArcX2, nextArcY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint);
                                        var entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 1){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 2;
                                            firstEntity = 1;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcEndPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 3;
                                                    }
                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 1){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 4;
                                            firstEntity = 1;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 3;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (entity is LineGeometry nextLine && (entity.GetEntityID() != templist10[0]) && step == 1){
                                        nextLineX1 = nextLine.EndPoint1.x;
                                        nextLineX2 = nextLine.EndPoint2.x;
                                        nextLineY1 = nextLine.EndPoint1.y;
                                        nextLineY2 = nextLine.EndPoint2.y;
                                        nextLineStartPoint = new Point3D(nextLineX1, nextLineY1, 0.0); // Arc 2 start point
                                        nextLineEndPoint = new Point3D(nextLineX2, nextLineY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint);
                                        var entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 1){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 2;
                                            firstEntity = 2;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineEndPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 3;
                                                    }
                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 1){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 4;
                                            firstEntity = 2;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineStartPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 3;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (firstEntity == 2 && step == 1){
                                
                                    var thisEntity = LineGeometry.RetrieveEntity(templist10[0]);
                                    if (thisEntity is LineGeometry line && step == 1){
                                        lineX1 = line.EndPoint1.x; // Arc 1 x 1
                                        lineX2 = line.EndPoint2.x; // Arc 1 x 2
                                        lineY1 = line.EndPoint1.y; // Arc 1 y 1
                                        lineY2 = line.EndPoint2.y; // Arc 1 y 2
                                        lineStartPoint = new Point3D(lineX1, lineY1, 0.0); // Arc 1 start point
                                        lineEndPoint = new Point3D(lineX2, lineY2, 0.0); // Arc 1 end point
                                        if (entity is ArcGeometry nextArc && (entity.GetEntityID() != templist10[0]) && step == 1){
                                            nextArcX1 = nextArc.EndPoint1.x;
                                            nextArcX2 = nextArc.EndPoint2.x;
                                            nextArcY1 = nextArc.EndPoint1.y;
                                            nextArcY2 = nextArc.EndPoint2.y;
                                            nextArcStartPoint = new Point3D(nextArcX1, nextArcY1, 0.0); // Arc 2 start point
                                            nextArcEndPoint = new Point3D(nextArcX2, nextArcY2, 0.0); // Arc 2 end point
                                            var entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint);
                                            var entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint);
                                            if (entityStartDistance <= tolerance && step == 1){
                                                entity.Color = 10;
                                                entity.Commit();
                                                templist10.Clear();
                                                templist10.Add(entity.GetEntityID());
                                                step = 2;
                                                firstEntity = 1;
                                                foreach (var v in tempList9){
                                                    var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                    if (w is PointGeometry point){
                                                        var ux = point.Data.x;// X location of point
                                                        var uy = point.Data.y;// Y location of point
                                                        Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                        var entityPointDistance = VectorManager.Distance(uPoint, nextArcEndPoint);
                                                        if (entityPointDistance <= tolerance){
                                                            step = 3;
                                                        }
                                                    }
                                                }
                                            }
                                            if (entityEndDistance <= tolerance && step == 1){
                                                entity.Color = 10;
                                                entity.Commit();
                                                templist10.Clear();
                                                templist10.Add(entity.GetEntityID());
                                                step = 4;
                                                firstEntity = 1;
                                                foreach (var v in tempList9){
                                                    var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                    if (w is PointGeometry point){
                                                        var ux = point.Data.x;// X location of point
                                                        var uy = point.Data.y;// Y location of point
                                                        Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                        var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                                        if (entityPointDistance <= tolerance){
                                                            step = 3;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (entity is LineGeometry nextLine && (entity.GetEntityID() != templist10[0]) && step == 1){
                                            nextLineX1 = nextLine.EndPoint1.x;
                                            nextLineX2 = nextLine.EndPoint2.x;
                                            nextLineY1 = nextLine.EndPoint1.y;
                                            nextLineY2 = nextLine.EndPoint2.y;
                                            nextLineStartPoint = new Point3D(nextLineX1, nextLineY1, 0.0); // Arc 2 start point
                                            nextLineEndPoint = new Point3D(nextLineX2, nextLineY2, 0.0); // Arc 2 end point
                                            var entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint);
                                            var entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint);
                                            if (entityStartDistance <= tolerance && step == 1){
                                                entity.Color = 10;
                                                entity.Commit();
                                                templist10.Clear();
                                                templist10.Add(entity.GetEntityID());
                                                step = 2;
                                                firstEntity = 2;
                                                foreach (var v in tempList9){
                                                    var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                    if (w is PointGeometry point){
                                                        var ux = point.Data.x;// X location of point
                                                        var uy = point.Data.y;// Y location of point
                                                        Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                        var entityPointDistance = VectorManager.Distance(uPoint, nextLineEndPoint);
                                                        if (entityPointDistance <= tolerance){
                                                            step = 3;
                                                        }
                                                    }
                                                }
                                            }
                                            if (entityEndDistance <= tolerance && step == 1){
                                                entity.Color = 10;
                                                entity.Commit();
                                                templist10.Clear();
                                                templist10.Add(entity.GetEntityID());
                                                step = 4;
                                                firstEntity = 2;
                                                foreach (var v in tempList9){
                                                    var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                    if (w is PointGeometry point){
                                                        var ux = point.Data.x;// X location of point
                                                        var uy = point.Data.y;// Y location of point
                                                        Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                        var entityPointDistance = VectorManager.Distance(uPoint, nextLineStartPoint);
                                                        if (entityPointDistance <= tolerance){
                                                            step = 3;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                
                            }
                        }
                    }
                    if (step == 2){
                        System.Windows.Forms.MessageBox.Show("step 2");
                        foreach (var entity in chainEntity){
                            if (firstEntity == 1 && step == 2){
                                var thisEntity = ArcGeometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is ArcGeometry arc && step == 2){
                                    arcX1 = arc.EndPoint1.x; // Arc 1 x 1
                                    arcX2 = arc.EndPoint2.x; // Arc 1 x 2
                                    arcY1 = arc.EndPoint1.y; // Arc 1 y 1
                                    arcY2 = arc.EndPoint2.y; // Arc 1 y 2
                                    arcStartPoint = new Point3D(arcX1, arcY1, 0.0); // Arc 1 start point
                                    arcEndPoint = new Point3D(arcX2, arcY2, 0.0); // Arc 1 end point
                                    if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2){
                                        nextArcX1 = nextArc.EndPoint1.x;
                                        nextArcX2 = nextArc.EndPoint2.x;
                                        nextArcY1 = nextArc.EndPoint1.y;
                                        nextArcY2 = nextArc.EndPoint2.y;
                                        nextArcStartPoint = new Point3D(nextArcX1, nextArcY1, 0.0); // Arc 2 start point
                                        nextArcEndPoint = new Point3D(nextArcX2, nextArcY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint);
                                        var entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 2){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 2;
                                            firstEntity = 1;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcEndPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 3;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 2){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 4;
                                            firstEntity = 1;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 5;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                    }
                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2){
                                        nextLineX1 = nextLine.EndPoint1.x;
                                        nextLineX2 = nextLine.EndPoint2.x;
                                        nextLineY1 = nextLine.EndPoint1.y;
                                        nextLineY2 = nextLine.EndPoint2.y;
                                        nextLineStartPoint = new Point3D(nextLineX1, nextLineY1, 0.0); // Arc 2 start point
                                        nextLineEndPoint = new Point3D(nextLineX2, nextLineY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint);
                                        var entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 2){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 2;
                                            firstEntity = 2;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineEndPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 3;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 2){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 4;
                                            firstEntity = 2;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineStartPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 5;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (firstEntity == 2 && step == 2){
                                var thisEntity = LineGeometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is LineGeometry line && step == 2){
                                    lineX1 = line.EndPoint1.x; // Arc 1 x 1
                                    lineX2 = line.EndPoint2.x; // Arc 1 x 2
                                    lineY1 = line.EndPoint1.y; // Arc 1 y 1
                                    lineY2 = line.EndPoint2.y; // Arc 1 y 2
                                    lineStartPoint = new Point3D(lineX1, lineY1, 0.0); // Arc 1 start point
                                    lineEndPoint = new Point3D(lineX2, lineY2, 0.0); // Arc 1 end point
                                    if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2){
                                        nextArcX1 = nextArc.EndPoint1.x;
                                        nextArcX2 = nextArc.EndPoint2.x;
                                        nextArcY1 = nextArc.EndPoint1.y;
                                        nextArcY2 = nextArc.EndPoint2.y;
                                        nextArcStartPoint = new Point3D(nextArcX1, nextArcY1, 0.0); // Arc 2 start point
                                        nextArcEndPoint = new Point3D(nextArcX2, nextArcY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint);
                                        var entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 2){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 2;
                                            firstEntity = 1;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcEndPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 3;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 2){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 4;
                                            firstEntity = 1;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 5;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                    }
                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2){
                                        nextLineX1 = nextLine.EndPoint1.x;
                                        nextLineX2 = nextLine.EndPoint2.x;
                                        nextLineY1 = nextLine.EndPoint1.y;
                                        nextLineY2 = nextLine.EndPoint2.y;
                                        nextLineStartPoint = new Point3D(nextLineX1, nextLineY1, 0.0); // Arc 2 start point
                                        nextLineEndPoint = new Point3D(nextLineX2, nextLineY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint);
                                        var entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 2){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 2;
                                            firstEntity = 2;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineEndPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 3;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 2){
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 4;
                                            firstEntity = 2;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineStartPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 5;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } // Gets Geo that connects first entity end point to second entity start point (offset 2)
                    if (step == 3){
                        System.Windows.Forms.MessageBox.Show("step 3");
                        foreach (var entity in chainEntity){
                            if (firstEntity == 1 && step == 3){
                                var thisEntity = ArcGeometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is ArcGeometry arc && step == 3){
                                    arcX1 = arc.EndPoint1.x; // Arc 1 x 1
                                    arcX2 = arc.EndPoint2.x; // Arc 1 x 2
                                    arcY1 = arc.EndPoint1.y; // Arc 1 y 1
                                    arcY2 = arc.EndPoint2.y; // Arc 1 y 2
                                    arcStartPoint = new Point3D(arcX1, arcY1, 0.0); // Arc 1 start point
                                    arcEndPoint = new Point3D(arcX2, arcY2, 0.0); // Arc 1 end point
                                    if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3){
                                        nextArcX1 = nextArc.EndPoint1.x;
                                        nextArcX2 = nextArc.EndPoint2.x;
                                        nextArcY1 = nextArc.EndPoint1.y;
                                        nextArcY2 = nextArc.EndPoint2.y;
                                        nextArcStartPoint = new Point3D(nextArcX1, nextArcY1, 0.0); // Arc 2 start point
                                        nextArcEndPoint = new Point3D(nextArcX2, nextArcY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint);
                                        var entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3){
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 3;
                                            firstEntity = 1;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcEndPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 2;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 3){
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 5;
                                            firstEntity = 1;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 4;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                    }
                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3){
                                        nextLineX1 = nextLine.EndPoint1.x;
                                        nextLineX2 = nextLine.EndPoint2.x;
                                        nextLineY1 = nextLine.EndPoint1.y;
                                        nextLineY2 = nextLine.EndPoint2.y;
                                        nextLineStartPoint = new Point3D(nextLineX1, nextLineY1, 0.0); // Arc 2 start point
                                        nextLineEndPoint = new Point3D(nextLineX2, nextLineY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint);
                                        var entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3){
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 3;
                                            firstEntity = 2;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineEndPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 2;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 3){
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 5;
                                            firstEntity = 2;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineStartPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 4;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (firstEntity == 2 && step == 3){
                                var thisEntity = LineGeometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is LineGeometry line && step == 3){
                                    lineX1 = line.EndPoint1.x; // Arc 1 x 1
                                    lineX2 = line.EndPoint2.x; // Arc 1 x 2
                                    lineY1 = line.EndPoint1.y; // Arc 1 y 1
                                    lineY2 = line.EndPoint2.y; // Arc 1 y 2
                                    lineStartPoint = new Point3D(lineX1, lineY1, 0.0); // Arc 1 start point
                                    lineEndPoint = new Point3D(lineX2, lineY2, 0.0); // Arc 1 end point
                                    if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3){
                                        nextArcX1 = nextArc.EndPoint1.x;
                                        nextArcX2 = nextArc.EndPoint2.x;
                                        nextArcY1 = nextArc.EndPoint1.y;
                                        nextArcY2 = nextArc.EndPoint2.y;
                                        nextArcStartPoint = new Point3D(nextArcX1, nextArcY1, 0.0); // Arc 2 start point
                                        nextArcEndPoint = new Point3D(nextArcX2, nextArcY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint);
                                        var entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3){
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 3;
                                            firstEntity = 1;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcEndPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 2;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 3){
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 5;
                                            firstEntity = 1;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 4;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                    }
                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3){
                                        nextLineX1 = nextLine.EndPoint1.x;
                                        nextLineX2 = nextLine.EndPoint2.x;
                                        nextLineY1 = nextLine.EndPoint1.y;
                                        nextLineY2 = nextLine.EndPoint2.y;
                                        nextLineStartPoint = new Point3D(nextLineX1, nextLineY1, 0.0); // Arc 2 start point
                                        nextLineEndPoint = new Point3D(nextLineX2, nextLineY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint);
                                        var entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3){
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 3;
                                            firstEntity = 2;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineEndPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 2;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 3){
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 5;
                                            firstEntity = 2;
                                            foreach (var v in tempList9){
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point){
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineStartPoint);
                                                    if (entityPointDistance <= tolerance){
                                                        step = 4;
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } // Gets Geo that connects first entity end point to second entity start point (offset 1)
                    if (step == 4)
                    {
                        System.Windows.Forms.MessageBox.Show("step 4");
                        foreach (var entity in chainEntity)
                        {
                            if (firstEntity == 1 && step == 2)
                            {
                                var thisEntity = ArcGeometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is ArcGeometry arc && step == 2)
                                {
                                    arcX1 = arc.EndPoint1.x; // Arc 1 x 1
                                    arcX2 = arc.EndPoint2.x; // Arc 1 x 2
                                    arcY1 = arc.EndPoint1.y; // Arc 1 y 1
                                    arcY2 = arc.EndPoint2.y; // Arc 1 y 2
                                    arcEndPoint = new Point3D(arcX1, arcY1, 0.0); // Arc 1 start point
                                    arcStartPoint = new Point3D(arcX2, arcY2, 0.0); // Arc 1 end point
                                    if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                    {
                                        nextArcX1 = nextArc.EndPoint1.x;
                                        nextArcX2 = nextArc.EndPoint2.x;
                                        nextArcY1 = nextArc.EndPoint1.y;
                                        nextArcY2 = nextArc.EndPoint2.y;
                                        nextArcStartPoint = new Point3D(nextArcX1, nextArcY1, 0.0); // Arc 2 start point
                                        nextArcEndPoint = new Point3D(nextArcX2, nextArcY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint);
                                        var entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 2)
                                        {
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 2;
                                            firstEntity = 1;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcEndPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 3;

                                                    }

                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 2)
                                        {
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 4;
                                            firstEntity = 1;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 5;

                                                    }

                                                }
                                            }
                                        }
                                    }
                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                    {
                                        nextLineX1 = nextLine.EndPoint1.x;
                                        nextLineX2 = nextLine.EndPoint2.x;
                                        nextLineY1 = nextLine.EndPoint1.y;
                                        nextLineY2 = nextLine.EndPoint2.y;
                                        nextLineStartPoint = new Point3D(nextLineX1, nextLineY1, 0.0); // Arc 2 start point
                                        nextLineEndPoint = new Point3D(nextLineX2, nextLineY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint);
                                        var entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 2)
                                        {
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 2;
                                            firstEntity = 2;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineEndPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 3;

                                                    }

                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 2)
                                        {
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 4;
                                            firstEntity = 2;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineStartPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 5;

                                                    }

                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (firstEntity == 2 && step == 2)
                            {
                                var thisEntity = LineGeometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is LineGeometry line && step == 2)
                                {
                                    lineX1 = line.EndPoint1.x; // Arc 1 x 1
                                    lineX2 = line.EndPoint2.x; // Arc 1 x 2
                                    lineY1 = line.EndPoint1.y; // Arc 1 y 1
                                    lineY2 = line.EndPoint2.y; // Arc 1 y 2
                                    lineEndPoint = new Point3D(lineX1, lineY1, 0.0); // Arc 1 start point
                                    lineStartPoint = new Point3D(lineX2, lineY2, 0.0); // Arc 1 end point
                                    if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                    {
                                        nextArcX1 = nextArc.EndPoint1.x;
                                        nextArcX2 = nextArc.EndPoint2.x;
                                        nextArcY1 = nextArc.EndPoint1.y;
                                        nextArcY2 = nextArc.EndPoint2.y;
                                        nextArcStartPoint = new Point3D(nextArcX1, nextArcY1, 0.0); // Arc 2 start point
                                        nextArcEndPoint = new Point3D(nextArcX2, nextArcY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint);
                                        var entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 2)
                                        {
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 2;
                                            firstEntity = 1;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcEndPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 3;

                                                    }

                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 2)
                                        {
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 4;
                                            firstEntity = 1;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 5;

                                                    }

                                                }
                                            }
                                        }
                                    }
                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                    {
                                        nextLineX1 = nextLine.EndPoint1.x;
                                        nextLineX2 = nextLine.EndPoint2.x;
                                        nextLineY1 = nextLine.EndPoint1.y;
                                        nextLineY2 = nextLine.EndPoint2.y;
                                        nextLineStartPoint = new Point3D(nextLineX1, nextLineY1, 0.0); // Arc 2 start point
                                        nextLineEndPoint = new Point3D(nextLineX2, nextLineY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint);
                                        var entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 2)
                                        {
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 2;
                                            firstEntity = 2;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineEndPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 3;

                                                    }

                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 2)
                                        {
                                            entity.Color = 10;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 4;
                                            firstEntity = 2;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineStartPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 5;

                                                    }

                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } // Gets Geo that connects first entity start point to second entity start point (offset 2)
                    if (step == 5)
                    {
                        System.Windows.Forms.MessageBox.Show("step 5");
                        foreach (var entity in chainEntity)
                        {
                            if (firstEntity == 1 && step == 3)
                            {
                                var thisEntity = ArcGeometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is ArcGeometry arc && step == 3)
                                {
                                    arcX1 = arc.EndPoint1.x; // Arc 1 x 1
                                    arcX2 = arc.EndPoint2.x; // Arc 1 x 2
                                    arcY1 = arc.EndPoint1.y; // Arc 1 y 1
                                    arcY2 = arc.EndPoint2.y; // Arc 1 y 2
                                    arcEndPoint = new Point3D(arcX1, arcY1, 0.0); // Arc 1 start point
                                    arcStartPoint = new Point3D(arcX2, arcY2, 0.0); // Arc 1 end point
                                    if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                    {
                                        nextArcX1 = nextArc.EndPoint1.x;
                                        nextArcX2 = nextArc.EndPoint2.x;
                                        nextArcY1 = nextArc.EndPoint1.y;
                                        nextArcY2 = nextArc.EndPoint2.y;
                                        nextArcStartPoint = new Point3D(nextArcX1, nextArcY1, 0.0); // Arc 2 start point
                                        nextArcEndPoint = new Point3D(nextArcX2, nextArcY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint);
                                        var entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3)
                                        {
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 3;
                                            firstEntity = 1;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcEndPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 2;

                                                    }

                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 3)
                                        {
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 5;
                                            firstEntity = 1;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 4;

                                                    }

                                                }
                                            }
                                        }
                                    }
                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                    {
                                        nextLineX1 = nextLine.EndPoint1.x;
                                        nextLineX2 = nextLine.EndPoint2.x;
                                        nextLineY1 = nextLine.EndPoint1.y;
                                        nextLineY2 = nextLine.EndPoint2.y;
                                        nextLineStartPoint = new Point3D(nextLineX1, nextLineY1, 0.0); // Arc 2 start point
                                        nextLineEndPoint = new Point3D(nextLineX2, nextLineY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint);
                                        var entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3)
                                        {
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 3;
                                            firstEntity = 2;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineEndPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 2;

                                                    }

                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 3)
                                        {
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 5;
                                            firstEntity = 2;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineStartPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 4;

                                                    }

                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (firstEntity == 2 && step == 3)
                            {
                                var thisEntity = LineGeometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is LineGeometry line && step == 3)
                                {
                                    lineX1 = line.EndPoint1.x; // Arc 1 x 1
                                    lineX2 = line.EndPoint2.x; // Arc 1 x 2
                                    lineY1 = line.EndPoint1.y; // Arc 1 y 1
                                    lineY2 = line.EndPoint2.y; // Arc 1 y 2
                                    lineEndPoint = new Point3D(lineX1, lineY1, 0.0); // Arc 1 start point
                                    lineStartPoint = new Point3D(lineX2, lineY2, 0.0); // Arc 1 end point
                                    if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                    {
                                        nextArcX1 = nextArc.EndPoint1.x;
                                        nextArcX2 = nextArc.EndPoint2.x;
                                        nextArcY1 = nextArc.EndPoint1.y;
                                        nextArcY2 = nextArc.EndPoint2.y;
                                        nextArcStartPoint = new Point3D(nextArcX1, nextArcY1, 0.0); // Arc 2 start point
                                        nextArcEndPoint = new Point3D(nextArcX2, nextArcY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint);
                                        var entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3)
                                        {
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 3;
                                            firstEntity = 1;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcEndPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 2;

                                                    }

                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 3)
                                        {
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 5;
                                            firstEntity = 1;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 4;

                                                    }

                                                }
                                            }
                                        }
                                    }
                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                    {
                                        nextLineX1 = nextLine.EndPoint1.x;
                                        nextLineX2 = nextLine.EndPoint2.x;
                                        nextLineY1 = nextLine.EndPoint1.y;
                                        nextLineY2 = nextLine.EndPoint2.y;
                                        nextLineStartPoint = new Point3D(nextLineX1, nextLineY1, 0.0); // Arc 2 start point
                                        nextLineEndPoint = new Point3D(nextLineX2, nextLineY2, 0.0); // Arc 2 end point
                                        var entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint);
                                        var entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3)
                                        {
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 3;
                                            firstEntity = 2;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineEndPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 2;

                                                    }

                                                }
                                            }
                                        }
                                        if (entityEndDistance <= tolerance && step == 3)
                                        {
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 5;
                                            firstEntity = 2;
                                            foreach (var v in tempList9)
                                            {
                                                var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID
                                                if (w is PointGeometry point)
                                                {
                                                    var ux = point.Data.x;// X location of point
                                                    var uy = point.Data.y;// Y location of point
                                                    Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                                    var entityPointDistance = VectorManager.Distance(uPoint, nextLineStartPoint);
                                                    if (entityPointDistance <= tolerance)
                                                    {
                                                        step = 4;

                                                    }

                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } // Gets Geo that connects first entity start point to second entity start point (offset 1)
                }
            }

 

Link to comment
Share on other sites

I think you should be using else if or the break command, or just put a step++ at the end of the loop rather than step = 1, step = 2, steo = 3

 

or a bit better 

 for(var steo = 0; step < selectedChains.Length;step++)
{
if(step == 0)
{
//handle chain 1
}
else if(step == 1)
{
//handle chain 2
}
else if(step == 2)
{
//handle chain 3
}
else
{
//handle some other chain greater than 3
}
}

 

 

 

Link to comment
Share on other sites

That looks super clean.

How would that look if I wanted to pass data between steps?

This loop checks each entity in the chain, not just the chain. There are 4 possible outcomes so I created four different steps (one to handle each outcome).

If outcome is A -> step 2 
If outcome is B -> step 3
If outcome is C -> step 4
If outcome is D -> step 5

but after this part, it checks the next entity and sees which outcome is next , thus which step it needs to go to.

This "step" system is just a generic system I'm using to sort each entity until the all the entities in the chain are sorted. Essentially.

Link to comment
Share on other sites

1>    What is the goal of this add-in?
I’ve read the Logic:: description. (Not that I understood it.)
I see the image you posted, but that itself doesn’t help me know that me what the process is supposed to be. 
2>    This is just  a code fragment (albeit a very large one!) 
It has many repeated code sections. I would suggest breaking it down. *
Trying to follow logic through a 1300+ lines of code in one method is going to cause you grief.
3>    Why the templist9 and templist10 that contain the geometry entity IDs?
Seems it may be an unnecessary complication.


*Example:  Don’t repeat code if possible. Break that out to its own method.

This section of code is essentially repeated 40+ times!
(Copy/Paste is not your friend here.)
//foreach (var v in tempList9)
   //{
   //    var w = Geometry.RetrieveEntity(v);// Gets point based on GeoID
   //    if (w is PointGeometry point)
   //    {
   //        var ux = point.Data.x;// X location of point
   //        var uy = point.Data.y;// Y location of point
   /        Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
   //        var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
   //        if (entityPointDistance <= tolerance)
   //        {
   //            step = 4;
   //        }
   //    }
   //}
if (SearchTempList9(tempList9, nextArcStartPoint))
   {
   step = 4;
   }

A single method to call can replace those instances of repeated code.
///<summary> Search the list of entities for a matching point position </summary>
///
///<param name="entIdList"> The list of entity IDs to search </param>
///<param name="pt">        The point position to look for in the list </param>\
///
///<returns> Thrue if a match was found, else false </returns>
private bool SearchTempList9(List<int> entIdList, Point3D pt)
 {
   foreach (var entId in entIdList)
    {
        var geom = Geometry.RetrieveEntity(entId);
        if (geom is PointGeometry point)
        {
            var ux = point.Data.x; // X location of point
            var uy = point.Data.y; // Y location of point
            var uPoint = new Point3D(ux, uy, 0.0); // Saves point location
            var entityPointDistance = VectorManager.Distance(uPoint, pt);
            if (entityPointDistance <= tolerance)
              {
                return true;
              }
        }
     }

     return false;
  }
 

The code below builds but is not tested.  (since I do not know exactly want it is supposed to do!)

Could I have introduced new bugs to this quick & dirty refactoring or the code>?  Absolutely.

using System;
using System.Collections.Generic;

using Mastercam.BasicGeometry;
using Mastercam.Curves;
using Mastercam.Database;
using Mastercam.Database.Types;
using Mastercam.Math;

namespace Customer
{
    public class Support
    {
        private double tolerance = Mastercam.IO.SettingsManager.SystemTolerance;
        private List<int> tempList9 = new List<int>();
        private List<int> templist10 = new List<int>();

        public void DoIt()
        {
            double entityStartDistance;
            double entityEndDistance;

            Point3D lineStartPoint;
            Point3D lineEndPoint;
            Point3D nextLineStartPoint;
            Point3D nextLineEndPoint;

            Point3D arcStartPoint;
            Point3D arcEndPoint;
            Point3D nextArcStartPoint;
            Point3D nextArcEndPoint;                              

            var firstEntity = 0;
            var step = 0;


            var chainDetails = new Mastercam.Database.Interop.ChainDetails();// Preps the ChainDetails plugin
            var selectedChains = ChainManager.ChainAll(75);// Chains all geometry on level 75
            var chainDirection = ChainDirectionType.CounterClockwise;// Going to be used to make sure all chains go the same direction

            ChainManager.StartChainAtLongest(selectedChains);
            foreach (var chain in selectedChains)
            {
                var chainData = chainDetails.GetData(chain);
                var chainEntityList = chainData.ChainEntities;
                foreach (var t in chainEntityList)
                {
                    (t.Key).Color = 9;
                    (t.Key).Commit();
                }
            }

            foreach (var chain in selectedChains)
            {
                templist10.Clear();
                step = 0;
                chain.Direction = chainDirection;
                var chainEntity = ChainManager.GetGeometryInChain(chain);
                if (step == 0)
                {
                    System.Windows.Forms.MessageBox.Show("step 0");
                    foreach (var entity in chainEntity)
                    {
                        if (entity is ArcGeometry arc && step == 0)
                        {
                            step = SearchTempList9Arcs(entity, step);
                        }                        
                        else if (entity is LineGeometry line && step == 0)
                        {
                            step = SearchTempList9Lines(entity, step);
                        }
                        
                    }
                }

                if (step == 1)
                {
                    System.Windows.Forms.MessageBox.Show("step 1");
                    foreach (var entity in chainEntity)
                    {
                        if (firstEntity == 1 && step == 1)
                        {
                            var thisEntity = Geometry.RetrieveEntity(templist10[0]);

                            if (thisEntity is ArcGeometry arc && step == 1)
                            {
                                GetEndPoints(arc, out arcStartPoint, out arcEndPoint);

                                if (entity is ArcGeometry nextArc && (entity.GetEntityID() != templist10[0]) && step == 1)
                                {
                                    GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint);
                                    entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint);
                                    entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint);
                                    if (entityStartDistance <= tolerance && step == 1)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcEndPoint))
                                        {
                                            step = 3;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 1)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcStartPoint))
                                        {
                                            step = 3;
                                        }
                                    }
                                }

                                if (entity is LineGeometry nextLine && (entity.GetEntityID() != templist10[0]) && step == 1)
                                {
                                    GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint);
                                    entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint);
                                    entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint);
                                    if (entityStartDistance <= tolerance && step == 1)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineEndPoint))
                                        {
                                            step = 3;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 1)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineStartPoint))
                                        {
                                            step = 3;
                                        }                                        
                                    }
                                }
                            }
                        }

                        if (firstEntity == 2 && step == 1)
                        {
                            var thisEntity = Geometry.RetrieveEntity(templist10[0]);
                            if (thisEntity is LineGeometry line && step == 1)
                            {
                                GetEndPoints(line, out lineStartPoint, out lineEndPoint);                                
                                if (entity is ArcGeometry nextArc && (entity.GetEntityID() != templist10[0]) && step == 1)
                                {
                                    GetEndPoints(entity as ArcGeometry, out nextArcStartPoint, out nextArcEndPoint);
                                    entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint);
                                    entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint);
                                    if (entityStartDistance <= tolerance && step == 1)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcEndPoint))
                                        {
                                            step = 3;
                                        }                                    
                                    }

                                    if (entityEndDistance <= tolerance && step == 1)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcStartPoint))
                                        {
                                            step = 3;
                                        }
                                    }
                                }

                                if (entity is LineGeometry nextLine && (entity.GetEntityID() != templist10[0]) && step == 1)
                                {
                                    GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint);
                                    entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint);
                                    entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint);
                                    if (entityStartDistance <= tolerance && step == 1)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineEndPoint))
                                        {
                                            step = 3;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 1)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineStartPoint))
                                        {
                                            step = 3;
                                        }
                                    }
                                }
                            }

                        }
                    }
                }

                if (step == 2)
                {
                    System.Windows.Forms.MessageBox.Show("step 2");
                    foreach (var entity in chainEntity)
                    {
                        if (firstEntity == 1 && step == 2)
                        {
                            var thisEntity = Geometry.RetrieveEntity(templist10[0]);
                            if (thisEntity is ArcGeometry arc && step == 2)
                            {
                                GetEndPoints(arc, out arcStartPoint, out arcEndPoint);
                                if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                {
                                    GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint);
                                    entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint);
                                    entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint);
                                    if (entityStartDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcEndPoint))
                                        {
                                            step = 3;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcStartPoint))
                                        {
                                            step = 5;
                                        }
                                    }
                                }

                                if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                {
                                    GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint);
                                    entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint);
                                    entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint);

                                    if (entityStartDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineEndPoint))
                                        {
                                            step = 3;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineStartPoint))
                                        {
                                            step = 5;
                                        }
                                    }
                                }
                            }
                        }

                        if (firstEntity == 2 && step == 2)
                        {
                            var thisEntity = Geometry.RetrieveEntity(templist10[0]);
                            if (thisEntity is LineGeometry line && step == 2)
                            {
                                GetEndPoints(line, out lineStartPoint, out lineEndPoint);
                                if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                {                                    
                                    GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint);
                                    entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint);
                                    entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint);
                                    if (entityStartDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcEndPoint))
                                        {
                                            step = 3;
                                        }                                        
                                    }

                                    if (entityEndDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcStartPoint))
                                        {
                                            step = 5;
                                        }                                        
                                    }
                                }

                                if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                {
                                    GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint);
                                    entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint);
                                    entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint);
                                    if (entityStartDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineEndPoint))
                                        {
                                            step = 3;
                                        }                                    
                                    }

                                    if (entityEndDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineStartPoint))
                                        {
                                            step = 5;
                                        }                                        
                                    }
                                }
                            }
                        }
                    }
                } // Gets Geo that connects first entity end point to second entity start point (offset 2)

                if (step == 3)
                {
                    System.Windows.Forms.MessageBox.Show("step 3");
                    foreach (var entity in chainEntity)
                    {
                        if (firstEntity == 1 && step == 3)
                        {
                            var thisEntity = Geometry.RetrieveEntity(templist10[0]);
                            if (thisEntity is ArcGeometry arc && step == 3)
                            {
                                GetEndPoints(arc, out arcStartPoint, out arcEndPoint);
                                if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                {
                                    GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint);
                                    entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint);
                                    entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint);
                                    if (entityStartDistance <= tolerance && step == 3)
                                    {
                                        UpdateEntityColorAndList10(entity, 11);
                                        step = 3;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcEndPoint))
                                        {
                                            step = 2;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 3)
                                    {
                                        UpdateEntityColorAndList10(entity, 11);
                                        step = 5;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcStartPoint))
                                        {
                                            step = 4;
                                        }
                                    }
                                }

                                if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                {
                                    GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint);
                                    entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint);
                                    entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint);
                                    if (entityStartDistance <= tolerance && step == 3)
                                    {
                                        UpdateEntityColorAndList10(entity, 11);
                                        step = 3;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineEndPoint))
                                        {
                                            step = 2;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 3)
                                    {
                                        UpdateEntityColorAndList10(entity, 11);
                                        step = 5;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineStartPoint))
                                        {
                                            step = 4;
                                        }
                                    }
                                }
                            }
                        }

                        if (firstEntity == 2 && step == 3)
                        {
                            var thisEntity = Geometry.RetrieveEntity(templist10[0]);
                            if (thisEntity is LineGeometry line && step == 3)
                            {
                                GetEndPoints(line, out lineStartPoint, out lineEndPoint);
                                if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                {
                                    GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint);
                                    entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint);
                                    entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint);
                                    if (entityStartDistance <= tolerance && step == 3)
                                    {
                                        UpdateEntityColorAndList10(entity, 11);
                                        step = 3;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcEndPoint))
                                        {
                                            step = 2;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 3)
                                    {
                                        UpdateEntityColorAndList10(entity, 11);
                                        step = 5;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcStartPoint))
                                        {
                                            step = 4;
                                        }
                                    }
                                }

                                if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                {
                                    GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint);
                                    entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint);
                                    entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint);
                                    if (entityStartDistance <= tolerance && step == 3)
                                    {
                                        UpdateEntityColorAndList10(entity, 11);
                                        step = 3;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineEndPoint))
                                        {
                                            step = 2;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 3)
                                    {
                                        UpdateEntityColorAndList10(entity, 11);
                                        step = 5;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineStartPoint))
                                        {
                                            step = 4;
                                        }
                                    }
                                }
                            }
                        }
                    }
                } // Gets Geo that connects first entity end point to second entity start point (offset 1)

                if (step == 4)
                {
                    System.Windows.Forms.MessageBox.Show("step 4");
                    foreach (var entity in chainEntity)
                    {
                        if (firstEntity == 1 && step == 2)
                        {
                            var thisEntity = Geometry.RetrieveEntity(templist10[0]);
                            if (thisEntity is ArcGeometry arc && step == 2)
                            {
                                GetEndPoints(arc, out arcStartPoint, out arcEndPoint);
                                if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                {
                                    GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint);
                                    entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint);
                                    entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint);
                                    if (entityStartDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcEndPoint))
                                        {
                                            step = 3;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcStartPoint))
                                        {
                                            step = 5;
                                        }
                                    }
                                }

                                if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                {
                                    GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint);
                                    entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint);
                                    entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint);
                                    if (entityStartDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineEndPoint))
                                        {
                                            step = 3;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 2;

                                        if (SearchTempList9(tempList9, nextLineStartPoint))
                                        {
                                            step = 5;
                                        }
                                    }
                                }
                            }
                        }

                        if (firstEntity == 2 && step == 2)
                        {
                            var thisEntity = Geometry.RetrieveEntity(templist10[0]);
                            if (thisEntity is LineGeometry line && step == 2)
                            {
                                GetEndPoints(line, out lineStartPoint, out lineEndPoint);
                                if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                {                                    
                                    GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint);
                                    entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint);
                                    entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint);
                                    if (entityStartDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 2;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcEndPoint))
                                        {
                                            step = 3;
                                        }
                                    }

                                    if (entityEndDistance <= tolerance && step == 2)
                                    {
                                        UpdateEntityColorAndList10(entity, 10);
                                        step = 4;
                                        firstEntity = 1;

                                        if (SearchTempList9(tempList9, nextArcStartPoint))
                                        {
                                            step = 5;
                                        }                                        
                                    }

                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2)
                                    {
                                        GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint);
                                                                                entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint);
                                        entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 2)
                                        {
                                            UpdateEntityColorAndList10(entity, 10);
                                            step = 2;
                                            firstEntity = 2;

                                            if (SearchTempList9(tempList9, nextLineEndPoint))
                                            {
                                                step = 3;
                                            }                                        
                                        }

                                        if (entityEndDistance <= tolerance && step == 2)
                                        {
                                            UpdateEntityColorAndList10(entity, 10);
                                            step = 4;
                                            firstEntity = 2;

                                            if (SearchTempList9(tempList9, nextLineStartPoint))
                                            {
                                                step = 5;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } // Gets Geo that connects first entity start point to second entity start point (offset 2)

                    if (step == 5)
                    {
                        System.Windows.Forms.MessageBox.Show("step 5");
                        foreach (var entity in chainEntity)
                        {
                            if (firstEntity == 1 && step == 3)
                            {
                                var thisEntity = Geometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is ArcGeometry arc && step == 3)
                                {
                                    GetEndPoints(arc, out arcStartPoint, out arcEndPoint);
                                    if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                    {
                                        GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint);
                                        entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint);
                                        entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3)
                                        {
                                            UpdateEntityColorAndList10(entity, 11);
                                            step = 3;
                                            firstEntity = 1;

                                            if (SearchTempList9(tempList9, nextArcEndPoint))
                                            {
                                                step = 2;
                                            }
                                        }

                                        if (entityEndDistance <= tolerance && step == 3)
                                        {
                                            UpdateEntityColorAndList10(entity, 11);
                                            step = 5;
                                            firstEntity = 1;

                                            if (SearchTempList9(tempList9, nextArcStartPoint))
                                            {
                                                step = 4;
                                            }
                                        }
                                    }

                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                    {
                                        GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint);
                                        entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint);
                                        entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3)
                                        {
                                            UpdateEntityColorAndList10(entity, 11);
                                            step = 3;
                                            firstEntity = 2;

                                            if (SearchTempList9(tempList9, nextLineEndPoint))
                                            {
                                                step = 2;
                                            }
                                        }

                                        if (entityEndDistance <= tolerance && step == 3)
                                        {
                                            UpdateEntityColorAndList10(entity, 11);
                                            step = 5;
                                            firstEntity = 2;

                                            if (SearchTempList9(tempList9, nextLineStartPoint))
                                            {
                                                step = 4;
                                            }
                                        }
                                    }
                                }
                            }

                            if (firstEntity == 2 && step == 3)
                            {
                                var thisEntity = Geometry.RetrieveEntity(templist10[0]);
                                if (thisEntity is LineGeometry line && step == 3)
                                {
                                    GetEndPoints(line, out lineStartPoint, out lineEndPoint);
                                    if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                    {
                                        GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint);
                                        entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint);
                                        entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3)
                                        {
                                            UpdateEntityColorAndList10(entity, 11);
                                            step = 3;
                                            firstEntity = 1;

                                            if (SearchTempList9(tempList9, nextArcEndPoint))
                                            {
                                                step = 2;
                                            }
                                        }

                                        if (entityEndDistance <= tolerance && step == 3)
                                        {
                                            entity.Color = 11;
                                            entity.Commit();
                                            templist10.Clear();
                                            templist10.Add(entity.GetEntityID());
                                            step = 5;
                                            firstEntity = 1;

                                            if (SearchTempList9(tempList9, nextArcStartPoint))
                                            {
                                                step = 4;
                                            }
                                            //foreach (var v in tempList9)
                                            //{
                                            //    var w = Geometry.RetrieveEntity(v);// Gets point based on GeoID
                                            //    if (w is PointGeometry point)
                                            //    {
                                            //        var ux = point.Data.x;// X location of point
                                            //        var uy = point.Data.y;// Y location of point
                                            //        Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                                            //        var entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint);
                                            //        if (entityPointDistance <= tolerance)
                                            //        {
                                            //            step = 4;
                                            //        }
                                            //    }
                                            //}
                                        }
                                    }

                                    if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3)
                                    {
                                        GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint);
                                        entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint);
                                        entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint);
                                        if (entityStartDistance <= tolerance && step == 3)
                                        {
                                            UpdateEntityColorAndList10(entity, 11);
                                            step = 3;
                                            firstEntity = 2;

                                            if (SearchTempList9(tempList9, nextLineEndPoint))
                                            {
                                                step = 2;
                                            }
                                        }

                                        if (entityEndDistance <= tolerance && step == 3)
                                        {
                                            UpdateEntityColorAndList10(entity, 11);
                                            step = 5;
                                            firstEntity = 2;

                                            if (SearchTempList9(tempList9, nextLineStartPoint))
                                            {
                                                step = 4;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } // Gets Geo that connects first entity start point to second entity start point (offset 1)
                }
            }
        }

        ///<summary> Search the list of entities for a matching point position </summary>
        ///
        ///<param name="entIdList"> The list of entity IDs to search </param>
        ///<param name="pt">        The point position to look for in the list </param>
        ///
        ///<returns> Thrue if a match was found, else false </returns>
        private bool SearchTempList9(List<int> entIdList, Point3D pt)
        {
            foreach (var entId in entIdList)
            {
                var geom = Geometry.RetrieveEntity(entId);
                if (geom is PointGeometry point)
                {
                    var ux = point.Data.x; // X location of point
                    var uy = point.Data.y; // Y location of point
                    var uPoint = new Point3D(ux, uy, 0.0); // Saves point location
                    var entityPointDistance = VectorManager.Distance(uPoint, pt);
                    if (entityPointDistance <= tolerance)
                    {
                        return true;
                    }
                }
            }

            return false;
        }

        ///<summary> Search the list of entities for a matching point position </summary>
        ///
        ///<param name="entity"> The arc ntity to match </param>
        ///<param name="pt">     The point position to look for in the list </param>
        ///
        ///<returns> Thrue if a match was found, else false </returns>
        private int SearchTempList9Arcs(Geometry entity, int step)
        {
            if (entity is ArcGeometry arc && step == 0)
            {
                var arcStartPoint = new Point3D(); // Arc start point
                var arcEndPoint = new Point3D();   // Arc end point
                GetEndPoints(arc, out arcStartPoint, out arcEndPoint);
                foreach (var v in tempList9)
                {
                    var w = Geometry.RetrieveEntity(v);// Gets point based on GeoID
                    if (w is PointGeometry point && step == 0)
                    {
                        var ux = point.Data.x;// X location of point
                        var uy = point.Data.y;// Y location of point
                        var uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                        var arcStartDistance = Math.Abs(VectorManager.Distance(uPoint, arcStartPoint));// Distance between entity start point and crossover point
                        var arcEndDistance = Math.Abs(VectorManager.Distance(uPoint, arcEndPoint));// Distance between entity end point and crossover point
                        if (arcStartDistance <= tolerance /*&& step == 0*/)
                        {
                            entity.Color = 10;// Changes color of entity to 10
                            entity.Commit();// Saves entity into Mastercam Database                   
                            templist10.Add(entity.GetEntityID());
                            step = 1;// Sets step to 1
                        }
                    }
                }            
            }

            return step;
        }

        ///<summary> Search the list of entities for a matching point position </summary>
        ///
        ///<param name="entity"> The line ntity to match </param>
        ///<param name="pt">     The point position to look for in the list </param>
        ///
        ///<returns> Thrue if a match was found, else false </returns>
        private int SearchTempList9Lines(Geometry entity, int step)
        {        
            if (entity is LineGeometry line && step == 0)
            {
               var lineStartPoint = new Point3D(); // Line start point
               var lineEndPoint = new Point3D();   // Line end point
                GetEndPoints(line, out lineStartPoint, out lineEndPoint);
                foreach (var v in tempList9)
                {
                    var w = Geometry.RetrieveEntity(v);// Gets point based on GeoID
                    if (w is PointGeometry point && step == 0)
                    {
                        var ux = point.Data.x;// X location of point
                        var uy = point.Data.y;// Y location of point
                        var uPoint = new Point3D(ux, uy, 0.0);// Saves point location
                        var lineStartDistance = Math.Abs(VectorManager.Distance(uPoint, lineStartPoint));// Distance between entity start point and crossover point
                        var lineEndDistance = Math.Abs(VectorManager.Distance(uPoint, lineEndPoint));// Distance between entity end point and crossover point
                        if (lineStartDistance <= tolerance && step == 0)
                        {
                            entity.Color = 10;// Changes color of entity to 10
                            entity.Commit();// Saves entity into Mastercam Database                            
                            templist10.Add(entity.GetEntityID());
                            step = 1;// Sets step to 1
                        }
                    }
                }
            }

            return step;
        }

        ///<summary> Get the start and end points of a line or arc entity. </summary>
        //
        /// <remarkis> The Z coordinate of the points is forced to be '0' </remarkis>
        ///
        ///<param name="geom">    The line or arc entity </param>
        ///<param name="startPt"> [out] The start point </param>
        ///<param name="endPt">   [out] The end point </param>
        private void GetEndPoints(Geometry geom, out Point3D startPoint, out Point3D endPoint)
        {
            if (geom is LineGeometry line)
            {
                startPoint = new Point3D(line.EndPoint1.x, line.EndPoint1.y, 0.0);
                endPoint = new Point3D(line.EndPoint2.x, line.EndPoint2.y, 0.0);
            }
            else if (geom is ArcGeometry arc)
            {
                startPoint = new Point3D(arc.EndPoint1.x, arc.EndPoint1.y, 0.0);
                endPoint = new Point3D(arc.EndPoint2.x, arc.EndPoint2.y, 0.0);                
            }
            else
            {
                // TODO: Let the user that we where given something other than a line or arc!
                startPoint = new Point3D();
                endPoint = new Point3D();
            }
        }

        private void UpdateEntityColorAndList10(Geometry entity, byte color)
        {
            entity.Color = color;
            entity.Commit();
            templist10.Clear();
            templist10.Add(entity.GetEntityID());
        }
       
    }
}

 

  • Thanks 1
Link to comment
Share on other sites

Roger,

That looks like using Data Classes and Functions. Definitely a more efficient way of doing things because of all my broken Syntax.

Your response did help me find the broken code I had.

The ultimate goal, if you look at the .mcam file I sent you, is to take level 75 and create level 200 and 300. (my current program creates the geometry on levels 500-503 so I can compare to the answers (level 200 and 300) provided).

Link to comment
Share on other sites
On 12/5/2022 at 10:48 AM, Roger Martin from CNC Software said:


3>    Why the templist9 and templist10 that contain the geometry entity IDs?
Seems it may be an unnecessary complication.

 

 

I completely agree. I just couldn't figure out the syntax.

                    var chainData = chainDetails.GetData(chain);
                    var chainEntityList = chainData.ChainEntities;
                    foreach (var t in chainEntityList){
                        var firstEntity = t.Key;
                        var secondEntity = ++t.Key;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...