<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Get distance o a polyline based on block reference condition in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/get-distance-o-a-polyline-based-on-block-reference-condition/m-p/11489577#M11254</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello everyone&lt;/P&gt;&lt;P&gt;I need help to fiind a solution for a problem.The tast is this.I have a long polyline and 3d polyline wich interesect with this&amp;nbsp; long polyline. I need to calculate de distance along polyline but when a fiind a blockreference&amp;nbsp; at the start point or end point of polyline i need to reset the distance and start from there.Here is a picture of what i need&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sketch.png" style="width: 771px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1128576iE0A32946182506FC/image-size/large?v=v2&amp;amp;px=999" role="button" title="sketch.png" alt="sketch.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;First i set manualy a start distance + the distance along polyline.When i fiind a blockreference i reead a distance from attrebu and a pass it to the next distance a i start from that distance increment it until a fiind another blockreference and so on(Ex. i start at distnace 50 and increment distance +25 ,i arrive at the block reference i get the block value of 128 and the next value sould be km 128+ distance betwwen last 2 points)&lt;/P&gt;&lt;P&gt;Here is my cod so far&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;int k = 0;&lt;BR /&gt;ObjectId OID = dbu.PickObjectID("Pick 3d polyline &amp;gt;&amp;gt;&amp;gt; ");&lt;BR /&gt;Entity pEnt = dbu.GetAcadEntity(ThisDrawing, OID);&lt;BR /&gt;Polyline GPoly = pEnt as Polyline;&lt;BR /&gt;Extents3d bb = pEnt.GeometricExtents;&lt;BR /&gt;dbu.ZoomWin(AcadApp, AcEditor, bb.MinPoint, bb.MaxPoint);&lt;/P&gt;&lt;P&gt;// point3d col&lt;BR /&gt;Point3dCollection pCollPolygon = new Point3dCollection();&lt;BR /&gt;//get vertex poly&lt;BR /&gt;int vk = GPoly.NumberOfVertices;&lt;BR /&gt;Point3dCollection pColl = new Point3dCollection();&lt;BR /&gt;for (int v = 0; v &amp;lt; vk; v++)&lt;BR /&gt;{&lt;BR /&gt;Point3d currV = GPoly.GetPoint3dAt(v);&lt;BR /&gt;pColl.Add(currV);&lt;BR /&gt;}&lt;BR /&gt;//flag for blockreference&lt;BR /&gt;int flagBorna = 0;&lt;BR /&gt;int nextflagBorna = 0;&lt;BR /&gt;double Prev_distance = 0;&lt;BR /&gt;double total_distance = 0;&lt;BR /&gt;//grt date&lt;BR /&gt;String sepLayer = comboSepLayer.Text; //3d poly&lt;BR /&gt;if (sepLayer == string.Empty)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Invalid layer.", "Erorr", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double txtHeight = double.Parse(mtbHTxt.Text); // text high&lt;BR /&gt;if (txtHeight &amp;lt;= 0)&lt;BR /&gt;{&lt;BR /&gt;txtHeight = 1;&lt;BR /&gt;}&lt;BR /&gt;Double BornaKm = 0;&lt;BR /&gt;&lt;BR /&gt;Double StartKm = double.Parse(mtbStartKm.Text); //start pornire&lt;BR /&gt;//Double StartKm =&lt;BR /&gt;if (StartKm &amp;lt; 0)&lt;BR /&gt;{&lt;BR /&gt;StartKm = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double txtR = 0; //rotatiion text&lt;/P&gt;&lt;P&gt;Boolean decrement = cbDecrement.Checked; // decrement distante&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//selection 3d poly based on layer&lt;BR /&gt;TypedValue[] filterValue;&lt;BR /&gt;filterValue = new TypedValue[1];&lt;BR /&gt;filterValue.SetValue(new TypedValue(8, sepLayer), 0);&lt;BR /&gt;SelectionFilter filter = new SelectionFilter(filterValue);&lt;BR /&gt;PromptSelectionResult psr = AcEditor.SelectFence(pColl, filter);&lt;BR /&gt;if (psr.Status != PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Eroar,Invalid geometry", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;SelectionSet sst = psr.Value;&lt;BR /&gt;if (sst.Count &amp;lt; 1)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("invalid selection.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database acCurDb = acDoc.Database;&lt;BR /&gt;Editor ed = acDoc.Editor;&lt;BR /&gt;int change = 0;&lt;BR /&gt;int nextchange = 0;&lt;BR /&gt;using (Transaction acTrans = AcDatabase.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;foreach (SelectedObject acSSObj in sst)&lt;BR /&gt;{&lt;BR /&gt;Entity sEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) as Entity; //polilinie separator&lt;BR /&gt;//ed.WriteMessage(sEnt.ObjectId.ObjectClass.Name);&lt;BR /&gt;if (sEnt.ObjectId.ObjectClass.Name!="AcDb3dPolyline")&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Polyline is not 3d polylinie 3D.");&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;Polyline3d pl3DEnt = (Polyline3d)sEnt;&lt;BR /&gt;Polyline pl2DEnt = dbu.ConvertPoly3DTo2D(pl3DEnt);&lt;BR /&gt;Extents3d ee = pl2DEnt.GeometricExtents;&lt;BR /&gt;dbu.ZoomWin(AcadApp, AcEditor, ee.MinPoint, ee.MaxPoint);&lt;/P&gt;&lt;P&gt;Point2d sp = pl2DEnt.GetPoint2dAt(0); //punct start separator&lt;BR /&gt;Point2d ep = pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1); //punct endseparator&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//start point&lt;BR /&gt;Point3dCollection pCollPolygonstart = new Point3dCollection();&lt;BR /&gt;pCollPolygonstart = buildCircularSelectionArray(new Point3d(sp.X, sp.Y, 0), DanBUtility.searchDotTolerance);&lt;/P&gt;&lt;P&gt;// end point&lt;BR /&gt;Point3dCollection pCollPolygonend = new Point3dCollection();&lt;BR /&gt;pCollPolygonend = buildCircularSelectionArray(new Point3d(ep.X, ep.Y, 0), DanBUtility.searchDotTolerance);&lt;/P&gt;&lt;P&gt;//selection&lt;BR /&gt;TypedValue[] BornaValue;&lt;BR /&gt;BornaValue = new TypedValue[1];&lt;BR /&gt;BornaValue[0] = new TypedValue(0, "INSERT");&lt;BR /&gt;SelectionFilter filterBorna = new SelectionFilter(BornaValue);&lt;BR /&gt;PromptSelectionResult psrtxtstart = AcEditor.SelectCrossingPolygon(pCollPolygonstart, filterBorna);&lt;BR /&gt;if (psrtxtstart.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet ssttxtBorna = psrtxtstart.Value;&lt;BR /&gt;// ed.WriteMessage("Total :"+ ssttxtBorna.Count.ToString());&lt;BR /&gt;foreach (SelectedObject acSSObjTxt in ssttxtBorna)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;&lt;BR /&gt;for (int arId = 0; arId &amp;lt; borna.AttributeCollection.Count - 1; arId++)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);&lt;BR /&gt;&lt;BR /&gt;if (ar.Tag == "4601")&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;string stkm = ar.TextString;&lt;BR /&gt;stkm = stkm.ToUpper().Replace("KM", "");&lt;BR /&gt;stkm = stkm.Replace(" ", "");&lt;BR /&gt;BornaKm = Convert.ToInt32(stkm);&lt;BR /&gt;&lt;BR /&gt;flagBorna = 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;PromptSelectionResult psrtxtend = AcEditor.SelectCrossingPolygon(pCollPolygonend, filterBorna);&lt;BR /&gt;if (psrtxtend.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet ssttxtBorna = psrtxtend.Value;&lt;BR /&gt;&lt;BR /&gt;foreach (SelectedObject acSSObjTxt in ssttxtBorna)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;&lt;BR /&gt;for (int arId = 0; arId &amp;lt; borna.AttributeCollection.Count - 1; arId++)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);&lt;/P&gt;&lt;P&gt;if (ar.Tag == "4601")&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;string stkm = ar.TextString;&lt;BR /&gt;stkm = stkm.ToUpper().Replace("KM", "");&lt;BR /&gt;stkm = stkm.Replace(" ", "");&lt;BR /&gt;BornaKm = Convert.ToInt32(stkm);&lt;BR /&gt;flagBorna = 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;//if blockreference is missing&lt;BR /&gt;if(psrtxtstart.Status != PromptStatus.OK &amp;amp;&amp;amp; psrtxtend.Status != PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;flagBorna = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3d spip = new Point3d(sp.X, sp.Y, 0);&lt;BR /&gt;Double ang = dbu.GetAngle2d(pl2DEnt.GetPoint2dAt(0), pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1)); //citire unghi general al separatorului&lt;BR /&gt;if (ang &amp;lt;= Math.PI)//rotatie text&lt;BR /&gt;{&lt;BR /&gt;txtR = ang - Math.PI / 2; //rotatie text inainte de PI&lt;BR /&gt;spip = new Point3d(sp.X, sp.Y, 0);&lt;BR /&gt;}&lt;BR /&gt;else if (ang &amp;gt; Math.PI)&lt;BR /&gt;{&lt;BR /&gt;txtR = ang + Math.PI / 2; //rotatie text dupa PI&lt;BR /&gt;spip = new Point3d(ep.X, ep.Y, 0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3dCollection ipColl = new Point3dCollection();&lt;BR /&gt;pEnt.IntersectWith(pl2DEnt, Intersect.OnBothOperands, ipColl, IntPtr.Zero, IntPtr.Zero); //intersectare&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Double DistInPunct = 0;&lt;BR /&gt;if (flagBorna != nextflagBorna)&lt;BR /&gt;{&lt;BR /&gt;//reset the value&lt;BR /&gt;StartKm = BornaKm;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double DistAppend = 0;&lt;BR /&gt;//for ieah point in intersection&lt;BR /&gt;foreach (Point3d ip in ipColl)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Point3d ptOnCurve = GPoly.GetClosestPointTo(ip, true);&lt;BR /&gt;nt db = new DBPoint();&lt;BR /&gt;db.Position = new Point3d(ptOnCurve.X, ptOnCurve.Y, 0);&lt;BR /&gt;&lt;BR /&gt;DistInPunct = Math.Round(GPoly.GetDistAtPoint(ptOnCurve), 2);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DistAppend = Math.Round(StartKm + DistInPunct, 0);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if (decrement == true)&lt;BR /&gt;{&lt;BR /&gt;DistAppend = Math.Round(StartKm - DistInPunct, 0);&lt;BR /&gt;}&lt;BR /&gt;//caculate the remain disntance&lt;BR /&gt;total_distance = DistAppend - Prev_distance ;&lt;BR /&gt;&lt;BR /&gt;//Prev_distance = DistAppend;&lt;BR /&gt;Double DistReduced = DistAppend / 1000;&lt;BR /&gt;double DistRounded = Math.Round(DistReduced, 3);&lt;BR /&gt;string sDist = DistReduced.ToString();&lt;/P&gt;&lt;P&gt;if (metri.Length &amp;lt; 3)&lt;BR /&gt;{&lt;BR /&gt;if (metri.Length == 2) { metri = metri + "0"; }&lt;BR /&gt;else if (metri.Length == 1) { metri = metri + "00"; }&lt;BR /&gt;else if (metri.Length == 0) { metri = metri + "000"; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;string tDist = "";&lt;BR /&gt;&lt;BR /&gt;// if flag value change=======&amp;gt;here is the problem after blockreference i need to reset the distance and increment it again&lt;BR /&gt;if (flagBorna != nextflagBorna)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;tDist = "KM " + StartKm.ToString() + "+" + total_distance.ToString();&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;tDist= "KM " + StartKm.ToString() + "+" + DistAppend.ToString();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (flagBorna == 0)&lt;BR /&gt;{&lt;BR /&gt;//creating text&lt;BR /&gt;DBText txtDist = DanBUtility.CreateAcadText(tDist, spip, txtHeight, sepLayer, txtR, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);&lt;BR /&gt;&lt;BR /&gt;txtDist.Layer = "KM";&lt;/P&gt;&lt;P&gt;if (txtDist != null) { k = k + 1; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//next&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;ipColl.Dispose();&lt;BR /&gt;sEnt.Dispose();&lt;BR /&gt;pl3DEnt.Dispose();&lt;BR /&gt;pl2DEnt.Dispose();&lt;BR /&gt;GC.Collect();&lt;BR /&gt;//next sperarator&lt;BR /&gt;nextflagBorna = flagBorna;&lt;BR /&gt;Prev_distance = DistAppend;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;acTrans.Commit();&lt;BR /&gt;acTrans.Dispose();&lt;BR /&gt;}&lt;BR /&gt;pEnt.Dispose();&lt;BR /&gt;GPoly.Dispose();&lt;BR /&gt;GC.Collect();&lt;/P&gt;&lt;P&gt;MessageBox.Show("Done" + k + " object text.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Information);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show(ex.ToString());&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;int k = 0;&lt;BR /&gt;ObjectId OID = dbu.PickObjectID("Pick 3d polyline &amp;gt;&amp;gt;&amp;gt; ");&lt;BR /&gt;Entity pEnt = dbu.GetAcadEntity(ThisDrawing, OID);&lt;BR /&gt;Polyline GPoly = pEnt as Polyline;&lt;BR /&gt;Extents3d bb = pEnt.GeometricExtents;&lt;BR /&gt;dbu.ZoomWin(AcadApp, AcEditor, bb.MinPoint, bb.MaxPoint);&lt;/P&gt;&lt;P&gt;// point3d col&lt;BR /&gt;Point3dCollection pCollPolygon = new Point3dCollection();&lt;BR /&gt;//get vertex poly&lt;BR /&gt;int vk = GPoly.NumberOfVertices;&lt;BR /&gt;Point3dCollection pColl = new Point3dCollection();&lt;BR /&gt;for (int v = 0; v &amp;lt; vk; v++)&lt;BR /&gt;{&lt;BR /&gt;Point3d currV = GPoly.GetPoint3dAt(v);&lt;BR /&gt;pColl.Add(currV);&lt;BR /&gt;}&lt;BR /&gt;//flag for blockreference&lt;BR /&gt;int flagBorna = 0;&lt;BR /&gt;int nextflagBorna = 0;&lt;BR /&gt;double Prev_distance = 0;&lt;BR /&gt;double total_distance = 0;&lt;BR /&gt;//grt date&lt;BR /&gt;String sepLayer = comboSepLayer.Text; //3d poly&lt;BR /&gt;if (sepLayer == string.Empty)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Invalid layer.", "Erorr", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double txtHeight = double.Parse(mtbHTxt.Text); // text high&lt;BR /&gt;if (txtHeight &amp;lt;= 0)&lt;BR /&gt;{&lt;BR /&gt;txtHeight = 1;&lt;BR /&gt;}&lt;BR /&gt;Double BornaKm = 0;&lt;BR /&gt;&lt;BR /&gt;Double StartKm = double.Parse(mtbStartKm.Text); //start pornire&lt;BR /&gt;//Double StartKm =&lt;BR /&gt;if (StartKm &amp;lt; 0)&lt;BR /&gt;{&lt;BR /&gt;StartKm = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double txtR = 0; //rotatiion text&lt;/P&gt;&lt;P&gt;Boolean decrement = cbDecrement.Checked; // decrement distante&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//selection 3d poly based on layer&lt;BR /&gt;TypedValue[] filterValue;&lt;BR /&gt;filterValue = new TypedValue[1];&lt;BR /&gt;filterValue.SetValue(new TypedValue(8, sepLayer), 0);&lt;BR /&gt;SelectionFilter filter = new SelectionFilter(filterValue);&lt;BR /&gt;PromptSelectionResult psr = AcEditor.SelectFence(pColl, filter);&lt;BR /&gt;if (psr.Status != PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Eroar,Invalid geometry", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;SelectionSet sst = psr.Value;&lt;BR /&gt;if (sst.Count &amp;lt; 1)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("invalid selection.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database acCurDb = acDoc.Database;&lt;BR /&gt;Editor ed = acDoc.Editor;&lt;BR /&gt;int change = 0;&lt;BR /&gt;int nextchange = 0;&lt;BR /&gt;using (Transaction acTrans = AcDatabase.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;foreach (SelectedObject acSSObj in sst)&lt;BR /&gt;{&lt;BR /&gt;Entity sEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) as Entity; //polilinie separator&lt;BR /&gt;//ed.WriteMessage(sEnt.ObjectId.ObjectClass.Name);&lt;BR /&gt;if (sEnt.ObjectId.ObjectClass.Name!="AcDb3dPolyline")&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Polyline is not 3d polylinie 3D.");&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;Polyline3d pl3DEnt = (Polyline3d)sEnt;&lt;BR /&gt;Polyline pl2DEnt = dbu.ConvertPoly3DTo2D(pl3DEnt);&lt;BR /&gt;Extents3d ee = pl2DEnt.GeometricExtents;&lt;BR /&gt;dbu.ZoomWin(AcadApp, AcEditor, ee.MinPoint, ee.MaxPoint);&lt;/P&gt;&lt;P&gt;Point2d sp = pl2DEnt.GetPoint2dAt(0); //punct start separator&lt;BR /&gt;Point2d ep = pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1); //punct endseparator&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//start point&lt;BR /&gt;Point3dCollection pCollPolygonstart = new Point3dCollection();&lt;BR /&gt;pCollPolygonstart = buildCircularSelectionArray(new Point3d(sp.X, sp.Y, 0), DanBUtility.searchDotTolerance);&lt;/P&gt;&lt;P&gt;// end point&lt;BR /&gt;Point3dCollection pCollPolygonend = new Point3dCollection();&lt;BR /&gt;pCollPolygonend = buildCircularSelectionArray(new Point3d(ep.X, ep.Y, 0), DanBUtility.searchDotTolerance);&lt;/P&gt;&lt;P&gt;//selection&lt;BR /&gt;TypedValue[] BornaValue;&lt;BR /&gt;BornaValue = new TypedValue[1];&lt;BR /&gt;BornaValue[0] = new TypedValue(0, "INSERT");&lt;BR /&gt;SelectionFilter filterBorna = new SelectionFilter(BornaValue);&lt;BR /&gt;PromptSelectionResult psrtxtstart = AcEditor.SelectCrossingPolygon(pCollPolygonstart, filterBorna);&lt;BR /&gt;if (psrtxtstart.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet ssttxtBorna = psrtxtstart.Value;&lt;BR /&gt;// ed.WriteMessage("Total :"+ ssttxtBorna.Count.ToString());&lt;BR /&gt;foreach (SelectedObject acSSObjTxt in ssttxtBorna)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;&lt;BR /&gt;for (int arId = 0; arId &amp;lt; borna.AttributeCollection.Count - 1; arId++)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);&lt;BR /&gt;&lt;BR /&gt;if (ar.Tag == "4601")&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;string stkm = ar.TextString;&lt;BR /&gt;stkm = stkm.ToUpper().Replace("KM", "");&lt;BR /&gt;stkm = stkm.Replace(" ", "");&lt;BR /&gt;BornaKm = Convert.ToInt32(stkm);&lt;BR /&gt;&lt;BR /&gt;flagBorna = 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;PromptSelectionResult psrtxtend = AcEditor.SelectCrossingPolygon(pCollPolygonend, filterBorna);&lt;BR /&gt;if (psrtxtend.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet ssttxtBorna = psrtxtend.Value;&lt;BR /&gt;&lt;BR /&gt;foreach (SelectedObject acSSObjTxt in ssttxtBorna)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;&lt;BR /&gt;for (int arId = 0; arId &amp;lt; borna.AttributeCollection.Count - 1; arId++)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);&lt;/P&gt;&lt;P&gt;if (ar.Tag == "4601")&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;string stkm = ar.TextString;&lt;BR /&gt;stkm = stkm.ToUpper().Replace("KM", "");&lt;BR /&gt;stkm = stkm.Replace(" ", "");&lt;BR /&gt;BornaKm = Convert.ToInt32(stkm);&lt;BR /&gt;flagBorna = 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;//if blockreference is missing&lt;BR /&gt;if(psrtxtstart.Status != PromptStatus.OK &amp;amp;&amp;amp; psrtxtend.Status != PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;flagBorna = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3d spip = new Point3d(sp.X, sp.Y, 0);&lt;BR /&gt;Double ang = dbu.GetAngle2d(pl2DEnt.GetPoint2dAt(0), pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1)); //citire unghi general al separatorului&lt;BR /&gt;if (ang &amp;lt;= Math.PI)//rotatie text&lt;BR /&gt;{&lt;BR /&gt;txtR = ang - Math.PI / 2; //rotatie text inainte de PI&lt;BR /&gt;spip = new Point3d(sp.X, sp.Y, 0);&lt;BR /&gt;}&lt;BR /&gt;else if (ang &amp;gt; Math.PI)&lt;BR /&gt;{&lt;BR /&gt;txtR = ang + Math.PI / 2; //rotatie text dupa PI&lt;BR /&gt;spip = new Point3d(ep.X, ep.Y, 0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3dCollection ipColl = new Point3dCollection();&lt;BR /&gt;pEnt.IntersectWith(pl2DEnt, Intersect.OnBothOperands, ipColl, IntPtr.Zero, IntPtr.Zero); //intersectare&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Double DistInPunct = 0;&lt;BR /&gt;if (flagBorna != nextflagBorna)&lt;BR /&gt;{&lt;BR /&gt;//reset the value&lt;BR /&gt;StartKm = BornaKm;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double DistAppend = 0;&lt;BR /&gt;//for ieah point in intersection&lt;BR /&gt;foreach (Point3d ip in ipColl)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Point3d ptOnCurve = GPoly.GetClosestPointTo(ip, true);&lt;BR /&gt;nt db = new DBPoint();&lt;BR /&gt;db.Position = new Point3d(ptOnCurve.X, ptOnCurve.Y, 0);&lt;BR /&gt;&lt;BR /&gt;DistInPunct = Math.Round(GPoly.GetDistAtPoint(ptOnCurve), 2);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DistAppend = Math.Round(StartKm + DistInPunct, 0);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if (decrement == true)&lt;BR /&gt;{&lt;BR /&gt;DistAppend = Math.Round(StartKm - DistInPunct, 0);&lt;BR /&gt;}&lt;BR /&gt;//caculate the remain disntance&lt;BR /&gt;total_distance = DistAppend - Prev_distance ;&lt;BR /&gt;&lt;BR /&gt;//Prev_distance = DistAppend;&lt;BR /&gt;Double DistReduced = DistAppend / 1000;&lt;BR /&gt;double DistRounded = Math.Round(DistReduced, 3);&lt;BR /&gt;string sDist = DistReduced.ToString();&lt;/P&gt;&lt;P&gt;if (metri.Length &amp;lt; 3)&lt;BR /&gt;{&lt;BR /&gt;if (metri.Length == 2) { metri = metri + "0"; }&lt;BR /&gt;else if (metri.Length == 1) { metri = metri + "00"; }&lt;BR /&gt;else if (metri.Length == 0) { metri = metri + "000"; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;string tDist = "";&lt;BR /&gt;&lt;BR /&gt;// if flag value change=======&amp;gt;here is the problem after blockreference i need to reset the distance and increment it again&lt;BR /&gt;if (flagBorna != nextflagBorna)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;tDist = "KM " + StartKm.ToString() + "+" + total_distance.ToString();&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;tDist= "KM " + StartKm.ToString() + "+" + DistAppend.ToString();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (flagBorna == 0)&lt;BR /&gt;{&lt;BR /&gt;//creating text&lt;BR /&gt;DBText txtDist = DanBUtility.CreateAcadText(tDist, spip, txtHeight, sepLayer, txtR, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);&lt;BR /&gt;&lt;BR /&gt;txtDist.Layer = "KM";&lt;/P&gt;&lt;P&gt;if (txtDist != null) { k = k + 1; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//next&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;ipColl.Dispose();&lt;BR /&gt;sEnt.Dispose();&lt;BR /&gt;pl3DEnt.Dispose();&lt;BR /&gt;pl2DEnt.Dispose();&lt;BR /&gt;GC.Collect();&lt;BR /&gt;//next sperarator&lt;BR /&gt;nextflagBorna = flagBorna;&lt;BR /&gt;Prev_distance = DistAppend;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;acTrans.Commit();&lt;BR /&gt;acTrans.Dispose();&lt;BR /&gt;}&lt;BR /&gt;pEnt.Dispose();&lt;BR /&gt;GPoly.Dispose();&lt;BR /&gt;GC.Collect();&lt;/P&gt;&lt;P&gt;MessageBox.Show("Done" + k + " object text.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Information);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show(ex.ToString());&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Thanck for your help&lt;/P&gt;</description>
    <pubDate>Tue, 18 Oct 2022 05:53:07 GMT</pubDate>
    <dc:creator>imagination_s</dc:creator>
    <dc:date>2022-10-18T05:53:07Z</dc:date>
    <item>
      <title>Get distance o a polyline based on block reference condition</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-distance-o-a-polyline-based-on-block-reference-condition/m-p/11489577#M11254</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello everyone&lt;/P&gt;&lt;P&gt;I need help to fiind a solution for a problem.The tast is this.I have a long polyline and 3d polyline wich interesect with this&amp;nbsp; long polyline. I need to calculate de distance along polyline but when a fiind a blockreference&amp;nbsp; at the start point or end point of polyline i need to reset the distance and start from there.Here is a picture of what i need&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sketch.png" style="width: 771px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1128576iE0A32946182506FC/image-size/large?v=v2&amp;amp;px=999" role="button" title="sketch.png" alt="sketch.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;First i set manualy a start distance + the distance along polyline.When i fiind a blockreference i reead a distance from attrebu and a pass it to the next distance a i start from that distance increment it until a fiind another blockreference and so on(Ex. i start at distnace 50 and increment distance +25 ,i arrive at the block reference i get the block value of 128 and the next value sould be km 128+ distance betwwen last 2 points)&lt;/P&gt;&lt;P&gt;Here is my cod so far&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;int k = 0;&lt;BR /&gt;ObjectId OID = dbu.PickObjectID("Pick 3d polyline &amp;gt;&amp;gt;&amp;gt; ");&lt;BR /&gt;Entity pEnt = dbu.GetAcadEntity(ThisDrawing, OID);&lt;BR /&gt;Polyline GPoly = pEnt as Polyline;&lt;BR /&gt;Extents3d bb = pEnt.GeometricExtents;&lt;BR /&gt;dbu.ZoomWin(AcadApp, AcEditor, bb.MinPoint, bb.MaxPoint);&lt;/P&gt;&lt;P&gt;// point3d col&lt;BR /&gt;Point3dCollection pCollPolygon = new Point3dCollection();&lt;BR /&gt;//get vertex poly&lt;BR /&gt;int vk = GPoly.NumberOfVertices;&lt;BR /&gt;Point3dCollection pColl = new Point3dCollection();&lt;BR /&gt;for (int v = 0; v &amp;lt; vk; v++)&lt;BR /&gt;{&lt;BR /&gt;Point3d currV = GPoly.GetPoint3dAt(v);&lt;BR /&gt;pColl.Add(currV);&lt;BR /&gt;}&lt;BR /&gt;//flag for blockreference&lt;BR /&gt;int flagBorna = 0;&lt;BR /&gt;int nextflagBorna = 0;&lt;BR /&gt;double Prev_distance = 0;&lt;BR /&gt;double total_distance = 0;&lt;BR /&gt;//grt date&lt;BR /&gt;String sepLayer = comboSepLayer.Text; //3d poly&lt;BR /&gt;if (sepLayer == string.Empty)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Invalid layer.", "Erorr", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double txtHeight = double.Parse(mtbHTxt.Text); // text high&lt;BR /&gt;if (txtHeight &amp;lt;= 0)&lt;BR /&gt;{&lt;BR /&gt;txtHeight = 1;&lt;BR /&gt;}&lt;BR /&gt;Double BornaKm = 0;&lt;BR /&gt;&lt;BR /&gt;Double StartKm = double.Parse(mtbStartKm.Text); //start pornire&lt;BR /&gt;//Double StartKm =&lt;BR /&gt;if (StartKm &amp;lt; 0)&lt;BR /&gt;{&lt;BR /&gt;StartKm = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double txtR = 0; //rotatiion text&lt;/P&gt;&lt;P&gt;Boolean decrement = cbDecrement.Checked; // decrement distante&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//selection 3d poly based on layer&lt;BR /&gt;TypedValue[] filterValue;&lt;BR /&gt;filterValue = new TypedValue[1];&lt;BR /&gt;filterValue.SetValue(new TypedValue(8, sepLayer), 0);&lt;BR /&gt;SelectionFilter filter = new SelectionFilter(filterValue);&lt;BR /&gt;PromptSelectionResult psr = AcEditor.SelectFence(pColl, filter);&lt;BR /&gt;if (psr.Status != PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Eroar,Invalid geometry", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;SelectionSet sst = psr.Value;&lt;BR /&gt;if (sst.Count &amp;lt; 1)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("invalid selection.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database acCurDb = acDoc.Database;&lt;BR /&gt;Editor ed = acDoc.Editor;&lt;BR /&gt;int change = 0;&lt;BR /&gt;int nextchange = 0;&lt;BR /&gt;using (Transaction acTrans = AcDatabase.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;foreach (SelectedObject acSSObj in sst)&lt;BR /&gt;{&lt;BR /&gt;Entity sEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) as Entity; //polilinie separator&lt;BR /&gt;//ed.WriteMessage(sEnt.ObjectId.ObjectClass.Name);&lt;BR /&gt;if (sEnt.ObjectId.ObjectClass.Name!="AcDb3dPolyline")&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Polyline is not 3d polylinie 3D.");&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;Polyline3d pl3DEnt = (Polyline3d)sEnt;&lt;BR /&gt;Polyline pl2DEnt = dbu.ConvertPoly3DTo2D(pl3DEnt);&lt;BR /&gt;Extents3d ee = pl2DEnt.GeometricExtents;&lt;BR /&gt;dbu.ZoomWin(AcadApp, AcEditor, ee.MinPoint, ee.MaxPoint);&lt;/P&gt;&lt;P&gt;Point2d sp = pl2DEnt.GetPoint2dAt(0); //punct start separator&lt;BR /&gt;Point2d ep = pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1); //punct endseparator&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//start point&lt;BR /&gt;Point3dCollection pCollPolygonstart = new Point3dCollection();&lt;BR /&gt;pCollPolygonstart = buildCircularSelectionArray(new Point3d(sp.X, sp.Y, 0), DanBUtility.searchDotTolerance);&lt;/P&gt;&lt;P&gt;// end point&lt;BR /&gt;Point3dCollection pCollPolygonend = new Point3dCollection();&lt;BR /&gt;pCollPolygonend = buildCircularSelectionArray(new Point3d(ep.X, ep.Y, 0), DanBUtility.searchDotTolerance);&lt;/P&gt;&lt;P&gt;//selection&lt;BR /&gt;TypedValue[] BornaValue;&lt;BR /&gt;BornaValue = new TypedValue[1];&lt;BR /&gt;BornaValue[0] = new TypedValue(0, "INSERT");&lt;BR /&gt;SelectionFilter filterBorna = new SelectionFilter(BornaValue);&lt;BR /&gt;PromptSelectionResult psrtxtstart = AcEditor.SelectCrossingPolygon(pCollPolygonstart, filterBorna);&lt;BR /&gt;if (psrtxtstart.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet ssttxtBorna = psrtxtstart.Value;&lt;BR /&gt;// ed.WriteMessage("Total :"+ ssttxtBorna.Count.ToString());&lt;BR /&gt;foreach (SelectedObject acSSObjTxt in ssttxtBorna)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;&lt;BR /&gt;for (int arId = 0; arId &amp;lt; borna.AttributeCollection.Count - 1; arId++)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);&lt;BR /&gt;&lt;BR /&gt;if (ar.Tag == "4601")&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;string stkm = ar.TextString;&lt;BR /&gt;stkm = stkm.ToUpper().Replace("KM", "");&lt;BR /&gt;stkm = stkm.Replace(" ", "");&lt;BR /&gt;BornaKm = Convert.ToInt32(stkm);&lt;BR /&gt;&lt;BR /&gt;flagBorna = 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;PromptSelectionResult psrtxtend = AcEditor.SelectCrossingPolygon(pCollPolygonend, filterBorna);&lt;BR /&gt;if (psrtxtend.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet ssttxtBorna = psrtxtend.Value;&lt;BR /&gt;&lt;BR /&gt;foreach (SelectedObject acSSObjTxt in ssttxtBorna)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;&lt;BR /&gt;for (int arId = 0; arId &amp;lt; borna.AttributeCollection.Count - 1; arId++)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);&lt;/P&gt;&lt;P&gt;if (ar.Tag == "4601")&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;string stkm = ar.TextString;&lt;BR /&gt;stkm = stkm.ToUpper().Replace("KM", "");&lt;BR /&gt;stkm = stkm.Replace(" ", "");&lt;BR /&gt;BornaKm = Convert.ToInt32(stkm);&lt;BR /&gt;flagBorna = 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;//if blockreference is missing&lt;BR /&gt;if(psrtxtstart.Status != PromptStatus.OK &amp;amp;&amp;amp; psrtxtend.Status != PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;flagBorna = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3d spip = new Point3d(sp.X, sp.Y, 0);&lt;BR /&gt;Double ang = dbu.GetAngle2d(pl2DEnt.GetPoint2dAt(0), pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1)); //citire unghi general al separatorului&lt;BR /&gt;if (ang &amp;lt;= Math.PI)//rotatie text&lt;BR /&gt;{&lt;BR /&gt;txtR = ang - Math.PI / 2; //rotatie text inainte de PI&lt;BR /&gt;spip = new Point3d(sp.X, sp.Y, 0);&lt;BR /&gt;}&lt;BR /&gt;else if (ang &amp;gt; Math.PI)&lt;BR /&gt;{&lt;BR /&gt;txtR = ang + Math.PI / 2; //rotatie text dupa PI&lt;BR /&gt;spip = new Point3d(ep.X, ep.Y, 0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3dCollection ipColl = new Point3dCollection();&lt;BR /&gt;pEnt.IntersectWith(pl2DEnt, Intersect.OnBothOperands, ipColl, IntPtr.Zero, IntPtr.Zero); //intersectare&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Double DistInPunct = 0;&lt;BR /&gt;if (flagBorna != nextflagBorna)&lt;BR /&gt;{&lt;BR /&gt;//reset the value&lt;BR /&gt;StartKm = BornaKm;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double DistAppend = 0;&lt;BR /&gt;//for ieah point in intersection&lt;BR /&gt;foreach (Point3d ip in ipColl)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Point3d ptOnCurve = GPoly.GetClosestPointTo(ip, true);&lt;BR /&gt;nt db = new DBPoint();&lt;BR /&gt;db.Position = new Point3d(ptOnCurve.X, ptOnCurve.Y, 0);&lt;BR /&gt;&lt;BR /&gt;DistInPunct = Math.Round(GPoly.GetDistAtPoint(ptOnCurve), 2);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DistAppend = Math.Round(StartKm + DistInPunct, 0);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if (decrement == true)&lt;BR /&gt;{&lt;BR /&gt;DistAppend = Math.Round(StartKm - DistInPunct, 0);&lt;BR /&gt;}&lt;BR /&gt;//caculate the remain disntance&lt;BR /&gt;total_distance = DistAppend - Prev_distance ;&lt;BR /&gt;&lt;BR /&gt;//Prev_distance = DistAppend;&lt;BR /&gt;Double DistReduced = DistAppend / 1000;&lt;BR /&gt;double DistRounded = Math.Round(DistReduced, 3);&lt;BR /&gt;string sDist = DistReduced.ToString();&lt;/P&gt;&lt;P&gt;if (metri.Length &amp;lt; 3)&lt;BR /&gt;{&lt;BR /&gt;if (metri.Length == 2) { metri = metri + "0"; }&lt;BR /&gt;else if (metri.Length == 1) { metri = metri + "00"; }&lt;BR /&gt;else if (metri.Length == 0) { metri = metri + "000"; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;string tDist = "";&lt;BR /&gt;&lt;BR /&gt;// if flag value change=======&amp;gt;here is the problem after blockreference i need to reset the distance and increment it again&lt;BR /&gt;if (flagBorna != nextflagBorna)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;tDist = "KM " + StartKm.ToString() + "+" + total_distance.ToString();&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;tDist= "KM " + StartKm.ToString() + "+" + DistAppend.ToString();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (flagBorna == 0)&lt;BR /&gt;{&lt;BR /&gt;//creating text&lt;BR /&gt;DBText txtDist = DanBUtility.CreateAcadText(tDist, spip, txtHeight, sepLayer, txtR, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);&lt;BR /&gt;&lt;BR /&gt;txtDist.Layer = "KM";&lt;/P&gt;&lt;P&gt;if (txtDist != null) { k = k + 1; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//next&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;ipColl.Dispose();&lt;BR /&gt;sEnt.Dispose();&lt;BR /&gt;pl3DEnt.Dispose();&lt;BR /&gt;pl2DEnt.Dispose();&lt;BR /&gt;GC.Collect();&lt;BR /&gt;//next sperarator&lt;BR /&gt;nextflagBorna = flagBorna;&lt;BR /&gt;Prev_distance = DistAppend;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;acTrans.Commit();&lt;BR /&gt;acTrans.Dispose();&lt;BR /&gt;}&lt;BR /&gt;pEnt.Dispose();&lt;BR /&gt;GPoly.Dispose();&lt;BR /&gt;GC.Collect();&lt;/P&gt;&lt;P&gt;MessageBox.Show("Done" + k + " object text.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Information);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show(ex.ToString());&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;int k = 0;&lt;BR /&gt;ObjectId OID = dbu.PickObjectID("Pick 3d polyline &amp;gt;&amp;gt;&amp;gt; ");&lt;BR /&gt;Entity pEnt = dbu.GetAcadEntity(ThisDrawing, OID);&lt;BR /&gt;Polyline GPoly = pEnt as Polyline;&lt;BR /&gt;Extents3d bb = pEnt.GeometricExtents;&lt;BR /&gt;dbu.ZoomWin(AcadApp, AcEditor, bb.MinPoint, bb.MaxPoint);&lt;/P&gt;&lt;P&gt;// point3d col&lt;BR /&gt;Point3dCollection pCollPolygon = new Point3dCollection();&lt;BR /&gt;//get vertex poly&lt;BR /&gt;int vk = GPoly.NumberOfVertices;&lt;BR /&gt;Point3dCollection pColl = new Point3dCollection();&lt;BR /&gt;for (int v = 0; v &amp;lt; vk; v++)&lt;BR /&gt;{&lt;BR /&gt;Point3d currV = GPoly.GetPoint3dAt(v);&lt;BR /&gt;pColl.Add(currV);&lt;BR /&gt;}&lt;BR /&gt;//flag for blockreference&lt;BR /&gt;int flagBorna = 0;&lt;BR /&gt;int nextflagBorna = 0;&lt;BR /&gt;double Prev_distance = 0;&lt;BR /&gt;double total_distance = 0;&lt;BR /&gt;//grt date&lt;BR /&gt;String sepLayer = comboSepLayer.Text; //3d poly&lt;BR /&gt;if (sepLayer == string.Empty)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Invalid layer.", "Erorr", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double txtHeight = double.Parse(mtbHTxt.Text); // text high&lt;BR /&gt;if (txtHeight &amp;lt;= 0)&lt;BR /&gt;{&lt;BR /&gt;txtHeight = 1;&lt;BR /&gt;}&lt;BR /&gt;Double BornaKm = 0;&lt;BR /&gt;&lt;BR /&gt;Double StartKm = double.Parse(mtbStartKm.Text); //start pornire&lt;BR /&gt;//Double StartKm =&lt;BR /&gt;if (StartKm &amp;lt; 0)&lt;BR /&gt;{&lt;BR /&gt;StartKm = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double txtR = 0; //rotatiion text&lt;/P&gt;&lt;P&gt;Boolean decrement = cbDecrement.Checked; // decrement distante&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//selection 3d poly based on layer&lt;BR /&gt;TypedValue[] filterValue;&lt;BR /&gt;filterValue = new TypedValue[1];&lt;BR /&gt;filterValue.SetValue(new TypedValue(8, sepLayer), 0);&lt;BR /&gt;SelectionFilter filter = new SelectionFilter(filterValue);&lt;BR /&gt;PromptSelectionResult psr = AcEditor.SelectFence(pColl, filter);&lt;BR /&gt;if (psr.Status != PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Eroar,Invalid geometry", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;SelectionSet sst = psr.Value;&lt;BR /&gt;if (sst.Count &amp;lt; 1)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("invalid selection.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database acCurDb = acDoc.Database;&lt;BR /&gt;Editor ed = acDoc.Editor;&lt;BR /&gt;int change = 0;&lt;BR /&gt;int nextchange = 0;&lt;BR /&gt;using (Transaction acTrans = AcDatabase.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;foreach (SelectedObject acSSObj in sst)&lt;BR /&gt;{&lt;BR /&gt;Entity sEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) as Entity; //polilinie separator&lt;BR /&gt;//ed.WriteMessage(sEnt.ObjectId.ObjectClass.Name);&lt;BR /&gt;if (sEnt.ObjectId.ObjectClass.Name!="AcDb3dPolyline")&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Polyline is not 3d polylinie 3D.");&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;Polyline3d pl3DEnt = (Polyline3d)sEnt;&lt;BR /&gt;Polyline pl2DEnt = dbu.ConvertPoly3DTo2D(pl3DEnt);&lt;BR /&gt;Extents3d ee = pl2DEnt.GeometricExtents;&lt;BR /&gt;dbu.ZoomWin(AcadApp, AcEditor, ee.MinPoint, ee.MaxPoint);&lt;/P&gt;&lt;P&gt;Point2d sp = pl2DEnt.GetPoint2dAt(0); //punct start separator&lt;BR /&gt;Point2d ep = pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1); //punct endseparator&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//start point&lt;BR /&gt;Point3dCollection pCollPolygonstart = new Point3dCollection();&lt;BR /&gt;pCollPolygonstart = buildCircularSelectionArray(new Point3d(sp.X, sp.Y, 0), DanBUtility.searchDotTolerance);&lt;/P&gt;&lt;P&gt;// end point&lt;BR /&gt;Point3dCollection pCollPolygonend = new Point3dCollection();&lt;BR /&gt;pCollPolygonend = buildCircularSelectionArray(new Point3d(ep.X, ep.Y, 0), DanBUtility.searchDotTolerance);&lt;/P&gt;&lt;P&gt;//selection&lt;BR /&gt;TypedValue[] BornaValue;&lt;BR /&gt;BornaValue = new TypedValue[1];&lt;BR /&gt;BornaValue[0] = new TypedValue(0, "INSERT");&lt;BR /&gt;SelectionFilter filterBorna = new SelectionFilter(BornaValue);&lt;BR /&gt;PromptSelectionResult psrtxtstart = AcEditor.SelectCrossingPolygon(pCollPolygonstart, filterBorna);&lt;BR /&gt;if (psrtxtstart.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet ssttxtBorna = psrtxtstart.Value;&lt;BR /&gt;// ed.WriteMessage("Total :"+ ssttxtBorna.Count.ToString());&lt;BR /&gt;foreach (SelectedObject acSSObjTxt in ssttxtBorna)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;&lt;BR /&gt;for (int arId = 0; arId &amp;lt; borna.AttributeCollection.Count - 1; arId++)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);&lt;BR /&gt;&lt;BR /&gt;if (ar.Tag == "4601")&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;string stkm = ar.TextString;&lt;BR /&gt;stkm = stkm.ToUpper().Replace("KM", "");&lt;BR /&gt;stkm = stkm.Replace(" ", "");&lt;BR /&gt;BornaKm = Convert.ToInt32(stkm);&lt;BR /&gt;&lt;BR /&gt;flagBorna = 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;PromptSelectionResult psrtxtend = AcEditor.SelectCrossingPolygon(pCollPolygonend, filterBorna);&lt;BR /&gt;if (psrtxtend.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet ssttxtBorna = psrtxtend.Value;&lt;BR /&gt;&lt;BR /&gt;foreach (SelectedObject acSSObjTxt in ssttxtBorna)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;&lt;BR /&gt;for (int arId = 0; arId &amp;lt; borna.AttributeCollection.Count - 1; arId++)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);&lt;/P&gt;&lt;P&gt;if (ar.Tag == "4601")&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;string stkm = ar.TextString;&lt;BR /&gt;stkm = stkm.ToUpper().Replace("KM", "");&lt;BR /&gt;stkm = stkm.Replace(" ", "");&lt;BR /&gt;BornaKm = Convert.ToInt32(stkm);&lt;BR /&gt;flagBorna = 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;//if blockreference is missing&lt;BR /&gt;if(psrtxtstart.Status != PromptStatus.OK &amp;amp;&amp;amp; psrtxtend.Status != PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;flagBorna = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3d spip = new Point3d(sp.X, sp.Y, 0);&lt;BR /&gt;Double ang = dbu.GetAngle2d(pl2DEnt.GetPoint2dAt(0), pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1)); //citire unghi general al separatorului&lt;BR /&gt;if (ang &amp;lt;= Math.PI)//rotatie text&lt;BR /&gt;{&lt;BR /&gt;txtR = ang - Math.PI / 2; //rotatie text inainte de PI&lt;BR /&gt;spip = new Point3d(sp.X, sp.Y, 0);&lt;BR /&gt;}&lt;BR /&gt;else if (ang &amp;gt; Math.PI)&lt;BR /&gt;{&lt;BR /&gt;txtR = ang + Math.PI / 2; //rotatie text dupa PI&lt;BR /&gt;spip = new Point3d(ep.X, ep.Y, 0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3dCollection ipColl = new Point3dCollection();&lt;BR /&gt;pEnt.IntersectWith(pl2DEnt, Intersect.OnBothOperands, ipColl, IntPtr.Zero, IntPtr.Zero); //intersectare&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Double DistInPunct = 0;&lt;BR /&gt;if (flagBorna != nextflagBorna)&lt;BR /&gt;{&lt;BR /&gt;//reset the value&lt;BR /&gt;StartKm = BornaKm;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double DistAppend = 0;&lt;BR /&gt;//for ieah point in intersection&lt;BR /&gt;foreach (Point3d ip in ipColl)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Point3d ptOnCurve = GPoly.GetClosestPointTo(ip, true);&lt;BR /&gt;nt db = new DBPoint();&lt;BR /&gt;db.Position = new Point3d(ptOnCurve.X, ptOnCurve.Y, 0);&lt;BR /&gt;&lt;BR /&gt;DistInPunct = Math.Round(GPoly.GetDistAtPoint(ptOnCurve), 2);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DistAppend = Math.Round(StartKm + DistInPunct, 0);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if (decrement == true)&lt;BR /&gt;{&lt;BR /&gt;DistAppend = Math.Round(StartKm - DistInPunct, 0);&lt;BR /&gt;}&lt;BR /&gt;//caculate the remain disntance&lt;BR /&gt;total_distance = DistAppend - Prev_distance ;&lt;BR /&gt;&lt;BR /&gt;//Prev_distance = DistAppend;&lt;BR /&gt;Double DistReduced = DistAppend / 1000;&lt;BR /&gt;double DistRounded = Math.Round(DistReduced, 3);&lt;BR /&gt;string sDist = DistReduced.ToString();&lt;/P&gt;&lt;P&gt;if (metri.Length &amp;lt; 3)&lt;BR /&gt;{&lt;BR /&gt;if (metri.Length == 2) { metri = metri + "0"; }&lt;BR /&gt;else if (metri.Length == 1) { metri = metri + "00"; }&lt;BR /&gt;else if (metri.Length == 0) { metri = metri + "000"; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;string tDist = "";&lt;BR /&gt;&lt;BR /&gt;// if flag value change=======&amp;gt;here is the problem after blockreference i need to reset the distance and increment it again&lt;BR /&gt;if (flagBorna != nextflagBorna)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;tDist = "KM " + StartKm.ToString() + "+" + total_distance.ToString();&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;tDist= "KM " + StartKm.ToString() + "+" + DistAppend.ToString();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (flagBorna == 0)&lt;BR /&gt;{&lt;BR /&gt;//creating text&lt;BR /&gt;DBText txtDist = DanBUtility.CreateAcadText(tDist, spip, txtHeight, sepLayer, txtR, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);&lt;BR /&gt;&lt;BR /&gt;txtDist.Layer = "KM";&lt;/P&gt;&lt;P&gt;if (txtDist != null) { k = k + 1; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//next&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;ipColl.Dispose();&lt;BR /&gt;sEnt.Dispose();&lt;BR /&gt;pl3DEnt.Dispose();&lt;BR /&gt;pl2DEnt.Dispose();&lt;BR /&gt;GC.Collect();&lt;BR /&gt;//next sperarator&lt;BR /&gt;nextflagBorna = flagBorna;&lt;BR /&gt;Prev_distance = DistAppend;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;acTrans.Commit();&lt;BR /&gt;acTrans.Dispose();&lt;BR /&gt;}&lt;BR /&gt;pEnt.Dispose();&lt;BR /&gt;GPoly.Dispose();&lt;BR /&gt;GC.Collect();&lt;/P&gt;&lt;P&gt;MessageBox.Show("Done" + k + " object text.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Information);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show(ex.ToString());&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Thanck for your help&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 05:53:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-distance-o-a-polyline-based-on-block-reference-condition/m-p/11489577#M11254</guid>
      <dc:creator>imagination_s</dc:creator>
      <dc:date>2022-10-18T05:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Get distance o a polyline based on block reference condition</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-distance-o-a-polyline-based-on-block-reference-condition/m-p/11490201#M11255</link>
      <description>&lt;P&gt;&lt;BR /&gt;I think i found a soluion i Added 2 point for each distance betwwen colection of point on the poliline.And then add the distance until it found a blockreference&lt;BR /&gt;.The a reset the total distance back to 0 and start all over until next blockreference.If enyone have a better solution.Please let me know&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;// Point3dCollection allpoints = new Point3dCollection();&lt;BR /&gt;//Point3dCollection newpcol = new Point3dCollection();&lt;BR /&gt;//getting geometries&lt;BR /&gt;this.Hide(); //ascundere form&lt;BR /&gt;int k = 0;&lt;BR /&gt;ObjectId OID = dbu.PickObjectID("Pic start polyline &amp;gt;&amp;gt;&amp;gt; ");&lt;BR /&gt;Entity pEnt = dbu.GetAcadEntity(ThisDrawing, OID);&lt;BR /&gt;Polyline GPoly = pEnt as Polyline;&lt;BR /&gt;Extents3d bb = pEnt.GeometricExtents;&lt;BR /&gt;dbu.ZoomWin(AcadApp, AcEditor, bb.MinPoint, bb.MaxPoint);&lt;BR /&gt;this.Show(); //afisare form&lt;/P&gt;&lt;P&gt;// polygon as point3d&lt;BR /&gt;Point3dCollection pCollPolygon = new Point3dCollection();&lt;BR /&gt;//colect vertex&lt;BR /&gt;int vk = GPoly.NumberOfVertices;&lt;BR /&gt;Point3dCollection pColl = new Point3dCollection();&lt;BR /&gt;for (int v = 0; v &amp;lt; vk; v++)&lt;BR /&gt;{&lt;BR /&gt;Point3d currV = GPoly.GetPoint3dAt(v);&lt;BR /&gt;pColl.Add(currV);&lt;BR /&gt;}&lt;BR /&gt;Point3d p1=(GPoly.GetPoint3dAt(0));&lt;BR /&gt;Point3d p2=new Point3d(0,0,0);&lt;BR /&gt;//flag&lt;BR /&gt;int flagBorna = 0;&lt;BR /&gt;int nextflagBorna = 0;&lt;BR /&gt;&lt;BR /&gt;//get data&lt;BR /&gt;String sepLayer = comboSepLayer.Text; //3d poly&lt;BR /&gt;if (sepLayer == string.Empty)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Invalid 3d poly layer..", "Erorr", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double txtHeight = double.Parse(mtbHTxt.Text);&lt;BR /&gt;if (txtHeight &amp;lt;= 0)&lt;BR /&gt;{&lt;BR /&gt;txtHeight = 1;&lt;BR /&gt;}&lt;BR /&gt;Double BornaKm = 0;&lt;BR /&gt;&lt;BR /&gt;Double StartKm = double.Parse(mtbStartKm.Text);&lt;BR /&gt;//Double StartKm =&lt;BR /&gt;if (StartKm &amp;lt; 0)&lt;BR /&gt;{&lt;BR /&gt;StartKm = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Double txtR = 0; //rotatie text&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//selectie&lt;BR /&gt;TypedValue[] filterValue;&lt;BR /&gt;filterValue = new TypedValue[1];&lt;BR /&gt;filterValue.SetValue(new TypedValue(8, sepLayer), 0);&lt;BR /&gt;SelectionFilter filter = new SelectionFilter(filterValue);&lt;BR /&gt;PromptSelectionResult psr = AcEditor.SelectFence(pColl, filter);&lt;BR /&gt;if (psr.Status != PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Eroare la selectie. Probabil geometrii invalide.", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;SelectionSet sst = psr.Value;&lt;BR /&gt;if (sst.Count &amp;lt; 1)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Selectie vida.", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database acCurDb = acDoc.Database;&lt;BR /&gt;Editor ed = acDoc.Editor;&lt;BR /&gt;int change = 0;&lt;BR /&gt;int nextchange = 0;&lt;BR /&gt;//StreamWriter write = new StreamWriter();&lt;BR /&gt;double Total = 0;&lt;BR /&gt;using (Transaction acTrans = AcDatabase.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;foreach (SelectedObject acSSObj in sst)&lt;BR /&gt;{&lt;BR /&gt;Entity sEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) as Entity; //polilinie separator&lt;BR /&gt;//ed.WriteMessage(sEnt.ObjectId.ObjectClass.Name);&lt;BR /&gt;if (sEnt.ObjectId.ObjectClass.Name!="AcDb3dPolyline")&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Polilinia Separator nu este de tip polylinie 3D.Ma opresc..");&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;Polyline3d pl3DEnt = (Polyline3d)sEnt;&lt;BR /&gt;Polyline pl2DEnt = dbu.ConvertPoly3DTo2D(pl3DEnt);&lt;BR /&gt;Extents3d ee = pl2DEnt.GeometricExtents;&lt;BR /&gt;dbu.ZoomWin(AcadApp, AcEditor, ee.MinPoint, ee.MaxPoint);&lt;/P&gt;&lt;P&gt;Point2d sp = pl2DEnt.GetPoint2dAt(0); //punct start separator&lt;BR /&gt;Point2d ep = pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1); //punct endseparator&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//pentru punctul de start&lt;BR /&gt;Point3dCollection pCollPolygonstart = new Point3dCollection();&lt;BR /&gt;pCollPolygonstart = buildCircularSelectionArray(new Point3d(sp.X, sp.Y, 0), DanBUtility.searchDotTolerance);&lt;/P&gt;&lt;P&gt;//pentru punctul de end&lt;BR /&gt;Point3dCollection pCollPolygonend = new Point3dCollection();&lt;BR /&gt;pCollPolygonend = buildCircularSelectionArray(new Point3d(ep.X, ep.Y, 0), DanBUtility.searchDotTolerance);&lt;/P&gt;&lt;P&gt;//selectie&lt;BR /&gt;TypedValue[] BornaValue;&lt;BR /&gt;BornaValue = new TypedValue[1];&lt;BR /&gt;BornaValue[0] = new TypedValue(0, "INSERT");&lt;BR /&gt;SelectionFilter filterBorna = new SelectionFilter(BornaValue);&lt;BR /&gt;PromptSelectionResult psrtxtstart = AcEditor.SelectCrossingPolygon(pCollPolygonstart, filterBorna);&lt;BR /&gt;if (psrtxtstart.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet ssttxtBorna = psrtxtstart.Value;&lt;BR /&gt;&lt;BR /&gt;foreach (SelectedObject acSSObjTxt in ssttxtBorna)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;&lt;BR /&gt;for (int arId = 0; arId &amp;lt; borna.AttributeCollection.Count - 1; arId++)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);&lt;BR /&gt;&lt;BR /&gt;if (ar.Tag == "4601")&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;string stkm = ar.TextString;&lt;BR /&gt;stkm = stkm.ToUpper().Replace("KM", "");&lt;BR /&gt;stkm = stkm.Replace(" ", "");&lt;BR /&gt;BornaKm = Convert.ToInt32(stkm);&lt;BR /&gt;//ed.WriteMessage("Punctul de start "+StartKm + Environment.NewLine);&lt;BR /&gt;flagBorna = 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;PromptSelectionResult psrtxtend = AcEditor.SelectCrossingPolygon(pCollPolygonend, filterBorna);&lt;BR /&gt;if (psrtxtend.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;SelectionSet ssttxtBorna = psrtxtend.Value;&lt;BR /&gt;&lt;BR /&gt;foreach (SelectedObject acSSObjTxt in ssttxtBorna)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;&lt;BR /&gt;for (int arId = 0; arId &amp;lt; borna.AttributeCollection.Count - 1; arId++)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);&lt;/P&gt;&lt;P&gt;if (ar.Tag == "4601")&lt;BR /&gt;{&lt;BR /&gt;// MessageBox.Show(ar.TextString);&lt;BR /&gt;string stkm = ar.TextString;&lt;BR /&gt;stkm = stkm.ToUpper().Replace("KM", "");&lt;BR /&gt;stkm = stkm.Replace(" ", "");&lt;BR /&gt;BornaKm = Convert.ToInt32(stkm);&lt;BR /&gt;&lt;BR /&gt;flagBorna = 1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;if(psrtxtstart.Status != PromptStatus.OK &amp;amp;&amp;amp; psrtxtend.Status != PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;flagBorna = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3d spip = new Point3d(sp.X, sp.Y, 0);&lt;BR /&gt;Double ang = dbu.GetAngle2d(pl2DEnt.GetPoint2dAt(0), pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1)); //&lt;BR /&gt;if (ang &amp;lt;= Math.PI)//rotatie text&lt;BR /&gt;{&lt;BR /&gt;txtR = ang - Math.PI / 2; //rotatie text inainte de PI&lt;BR /&gt;spip = new Point3d(sp.X, sp.Y, 0);&lt;BR /&gt;}&lt;BR /&gt;else if (ang &amp;gt; Math.PI)&lt;BR /&gt;{&lt;BR /&gt;txtR = ang + Math.PI / 2; //rotatie text dupa PI&lt;BR /&gt;spip = new Point3d(ep.X, ep.Y, 0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3dCollection ipColl = new Point3dCollection();&lt;BR /&gt;pEnt.IntersectWith(pl2DEnt, Intersect.OnBothOperands, ipColl, IntPtr.Zero, IntPtr.Zero); //intersectare&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Double DistInPunct = 0;&lt;BR /&gt;if (flagBorna != nextflagBorna)&lt;BR /&gt;{&lt;BR /&gt;//ed.WriteMessage("KM :" + total_distance + Environment.NewLine);&lt;BR /&gt;//DistAppend = Math.Round(StartKm+ DistInPunct, 0);&lt;BR /&gt;//DistAppend = Math.Round(StartKm + DistInPunct, 0);&lt;BR /&gt;StartKm = BornaKm;&lt;BR /&gt;//reset distance&lt;BR /&gt;Total = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Point3d ptOnCurve = GPoly.GetClosestPointTo(ipColl[0], true);&lt;BR /&gt;&lt;BR /&gt;DBPoint db = new DBPoint();&lt;BR /&gt;db.Position = new Point3d(ptOnCurve.X, ptOnCurve.Y, 0);&lt;BR /&gt;p2 = new Point3d(db.Position.X, db.Position.Y, 0);&lt;BR /&gt;double distance = Math.Round(p1.DistanceTo(p2));&lt;BR /&gt;Total = Total + distance;&lt;BR /&gt;if (flagBorna == 0)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;DBText txtDist = DanBUtility.CreateAcadText("KM " + StartKm.ToString() + "+"+ Total.ToString(), spip, txtHeight, sepLayer, txtR, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);&lt;BR /&gt;&lt;BR /&gt;txtDist.Layer = "KM";&lt;BR /&gt;if (txtDist != null) { k = k + 1; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;ipColl.Dispose();&lt;BR /&gt;sEnt.Dispose();&lt;BR /&gt;pl3DEnt.Dispose();&lt;BR /&gt;pl2DEnt.Dispose();&lt;BR /&gt;GC.Collect();&lt;BR /&gt;//next sperarator&lt;BR /&gt;nextflagBorna = flagBorna;&lt;BR /&gt;&lt;BR /&gt;p1 = p2;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;acTrans.Commit();&lt;BR /&gt;acTrans.Dispose();&lt;BR /&gt;}&lt;BR /&gt;pEnt.Dispose();&lt;BR /&gt;GPoly.Dispose();&lt;BR /&gt;GC.Collect();&lt;/P&gt;&lt;P&gt;MessageBox.Show("Done. Generated " + k + " object text.", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Information);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show(ex.ToString());&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 11:27:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-distance-o-a-polyline-based-on-block-reference-condition/m-p/11490201#M11255</guid>
      <dc:creator>imagination_s</dc:creator>
      <dc:date>2022-10-18T11:27:11Z</dc:date>
    </item>
  </channel>
</rss>

