Article | 70002686 |
Type | HowTo |
Product | Engine |
Version | 11 |
Date Added | 5/9/2025 12:00:00 AM |
Fixed | 11.4.3 (5/9/2025 12:00:00 AM) |
Submitted by | Rafael de Freitas |
Summary
Solution
The following code will ask the user to draw a fence polyline , then the intersected figures are being selected with the order the user intersected them using the distance between the intersection on the figure and the start of the polyline.
Check the comments on the code for clarification
//following code is working in view top plan world string ltype = doc.ActiveLineType.Name; //Keep the current ActiveLinetype to restore it afterwards doc.ActiveLineType = doc.LineTypes.DPIDash; //Chenge the Linetype to show the user that the lines he will pick are for selection , we can also change the activecolor if we want vdPolyline fence = doc.CommandAction.getUserPolyline(); //Ask the user to draw a polyline for the fence selection doc.ActiveLineType = doc.LineTypes.FindName(Name); //restore the ActiveLinetype of the Document. if (fence == null || fence.VertexList.Count < 2) return; gPoints pts = fence.GetSamplePoints(0, 0); gPoints ptsview = pts.GetTransformCopy(doc.World2ViewMatrix); //Get the points the user draw in View Coordinate System vdSelection set = new vdSelection(); set.SetUnRegisterDocument(doc); bool suc = set.Select(RenderSelect.SelectingMode.Fence, ptsview); //Run a fence selection with the points the user picked. if (!suc || set.Count == 0) return; if(set.Count > 1) { double[] keys = new double[set.Count]; //Here we will keep the distance from the starting point of the fence polyline to the intersection point for each intersected figure. for (int i = 0; i < set.Count; i++) { gPoints intpts = new gPoints(); if(!fence.IntersectWith(set[i], VdConstInters.VdIntOnBothOperands, intpts)) keys[i] = 0; else keys[i] = fence.getParamAtPoint(intpts[0]); //getParamAtPoint gives us the distance from the start of the polyline } //sort the selected entities depend on their distance from the start of fence polyline //set the tooltip for each selected entity depend on the position inside the array after the sort vdFigure[] figs = set.ToArray(); Array.Sort(keys, figs); //Sort the Selection according to the distance of the intersection points from the start of the polyline. for (int i = 0; i < figs.Length; i++) { figs[i].ToolTip = i.ToString(); //Just add a tooltip to each selected figure to debug the selection order. } }