Get distance o a polyline based on block reference condition

Get distance o a polyline based on block reference condition

imagination_s
Advocate Advocate
341 Views
1 Reply
Message 1 of 2

Get distance o a polyline based on block reference condition

imagination_s
Advocate
Advocate

 

Hello everyone

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  long polyline. I need to calculate de distance along polyline but when a fiind a blockreference  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

sketch.png

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)

Here is my cod so far

try
{


int k = 0;
ObjectId OID = dbu.PickObjectID("Pick 3d polyline >>> ");
Entity pEnt = dbu.GetAcadEntity(ThisDrawing, OID);
Polyline GPoly = pEnt as Polyline;
Extents3d bb = pEnt.GeometricExtents;
dbu.ZoomWin(AcadApp, AcEditor, bb.MinPoint, bb.MaxPoint);

// point3d col
Point3dCollection pCollPolygon = new Point3dCollection();
//get vertex poly
int vk = GPoly.NumberOfVertices;
Point3dCollection pColl = new Point3dCollection();
for (int v = 0; v < vk; v++)
{
Point3d currV = GPoly.GetPoint3dAt(v);
pColl.Add(currV);
}
//flag for blockreference
int flagBorna = 0;
int nextflagBorna = 0;
double Prev_distance = 0;
double total_distance = 0;
//grt date
String sepLayer = comboSepLayer.Text; //3d poly
if (sepLayer == string.Empty)
{
MessageBox.Show("Invalid layer.", "Erorr", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}

Double txtHeight = double.Parse(mtbHTxt.Text); // text high
if (txtHeight <= 0)
{
txtHeight = 1;
}
Double BornaKm = 0;

Double StartKm = double.Parse(mtbStartKm.Text); //start pornire
//Double StartKm =
if (StartKm < 0)
{
StartKm = 0;
}

Double txtR = 0; //rotatiion text

Boolean decrement = cbDecrement.Checked; // decrement distante

 

//selection 3d poly based on layer
TypedValue[] filterValue;
filterValue = new TypedValue[1];
filterValue.SetValue(new TypedValue(8, sepLayer), 0);
SelectionFilter filter = new SelectionFilter(filterValue);
PromptSelectionResult psr = AcEditor.SelectFence(pColl, filter);
if (psr.Status != PromptStatus.OK)
{
MessageBox.Show("Eroar,Invalid geometry", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}

SelectionSet sst = psr.Value;
if (sst.Count < 1)
{
MessageBox.Show("invalid selection.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = acDoc.Editor;
int change = 0;
int nextchange = 0;
using (Transaction acTrans = AcDatabase.TransactionManager.StartTransaction())
{
foreach (SelectedObject acSSObj in sst)
{
Entity sEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) as Entity; //polilinie separator
//ed.WriteMessage(sEnt.ObjectId.ObjectClass.Name);
if (sEnt.ObjectId.ObjectClass.Name!="AcDb3dPolyline")
{
MessageBox.Show("Polyline is not 3d polylinie 3D.");
return;
}
Polyline3d pl3DEnt = (Polyline3d)sEnt;
Polyline pl2DEnt = dbu.ConvertPoly3DTo2D(pl3DEnt);
Extents3d ee = pl2DEnt.GeometricExtents;
dbu.ZoomWin(AcadApp, AcEditor, ee.MinPoint, ee.MaxPoint);

Point2d sp = pl2DEnt.GetPoint2dAt(0); //punct start separator
Point2d ep = pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1); //punct endseparator


//start point
Point3dCollection pCollPolygonstart = new Point3dCollection();
pCollPolygonstart = buildCircularSelectionArray(new Point3d(sp.X, sp.Y, 0), DanBUtility.searchDotTolerance);

// end point
Point3dCollection pCollPolygonend = new Point3dCollection();
pCollPolygonend = buildCircularSelectionArray(new Point3d(ep.X, ep.Y, 0), DanBUtility.searchDotTolerance);

//selection
TypedValue[] BornaValue;
BornaValue = new TypedValue[1];
BornaValue[0] = new TypedValue(0, "INSERT");
SelectionFilter filterBorna = new SelectionFilter(BornaValue);
PromptSelectionResult psrtxtstart = AcEditor.SelectCrossingPolygon(pCollPolygonstart, filterBorna);
if (psrtxtstart.Status == PromptStatus.OK)
{
SelectionSet ssttxtBorna = psrtxtstart.Value;
// ed.WriteMessage("Total :"+ ssttxtBorna.Count.ToString());
foreach (SelectedObject acSSObjTxt in ssttxtBorna)
{



BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;
for (int arId = 0; arId < borna.AttributeCollection.Count - 1; arId++)
{
AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);

if (ar.Tag == "4601")
{

string stkm = ar.TextString;
stkm = stkm.ToUpper().Replace("KM", "");
stkm = stkm.Replace(" ", "");
BornaKm = Convert.ToInt32(stkm);

flagBorna = 1;
}
}
}


}

PromptSelectionResult psrtxtend = AcEditor.SelectCrossingPolygon(pCollPolygonend, filterBorna);
if (psrtxtend.Status == PromptStatus.OK)
{
SelectionSet ssttxtBorna = psrtxtend.Value;

foreach (SelectedObject acSSObjTxt in ssttxtBorna)
{

 

BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;
for (int arId = 0; arId < borna.AttributeCollection.Count - 1; arId++)
{
AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);

if (ar.Tag == "4601")
{

string stkm = ar.TextString;
stkm = stkm.ToUpper().Replace("KM", "");
stkm = stkm.Replace(" ", "");
BornaKm = Convert.ToInt32(stkm);
flagBorna = 1;
}
}
}

}
//if blockreference is missing
if(psrtxtstart.Status != PromptStatus.OK && psrtxtend.Status != PromptStatus.OK)
{
flagBorna = 0;
}


Point3d spip = new Point3d(sp.X, sp.Y, 0);
Double ang = dbu.GetAngle2d(pl2DEnt.GetPoint2dAt(0), pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1)); //citire unghi general al separatorului
if (ang <= Math.PI)//rotatie text
{
txtR = ang - Math.PI / 2; //rotatie text inainte de PI
spip = new Point3d(sp.X, sp.Y, 0);
}
else if (ang > Math.PI)
{
txtR = ang + Math.PI / 2; //rotatie text dupa PI
spip = new Point3d(ep.X, ep.Y, 0);
}


Point3dCollection ipColl = new Point3dCollection();
pEnt.IntersectWith(pl2DEnt, Intersect.OnBothOperands, ipColl, IntPtr.Zero, IntPtr.Zero); //intersectare



Double DistInPunct = 0;
if (flagBorna != nextflagBorna)
{
//reset the value
StartKm = BornaKm;
}

Double DistAppend = 0;
//for ieah point in intersection
foreach (Point3d ip in ipColl)
{


Point3d ptOnCurve = GPoly.GetClosestPointTo(ip, true);
nt db = new DBPoint();
db.Position = new Point3d(ptOnCurve.X, ptOnCurve.Y, 0);

DistInPunct = Math.Round(GPoly.GetDistAtPoint(ptOnCurve), 2);


DistAppend = Math.Round(StartKm + DistInPunct, 0);


if (decrement == true)
{
DistAppend = Math.Round(StartKm - DistInPunct, 0);
}
//caculate the remain disntance
total_distance = DistAppend - Prev_distance ;

//Prev_distance = DistAppend;
Double DistReduced = DistAppend / 1000;
double DistRounded = Math.Round(DistReduced, 3);
string sDist = DistReduced.ToString();

if (metri.Length < 3)
{
if (metri.Length == 2) { metri = metri + "0"; }
else if (metri.Length == 1) { metri = metri + "00"; }
else if (metri.Length == 0) { metri = metri + "000"; }
}

string tDist = "";

// if flag value change=======>here is the problem after blockreference i need to reset the distance and increment it again
if (flagBorna != nextflagBorna)

{
tDist = "KM " + StartKm.ToString() + "+" + total_distance.ToString();

}
else
{
tDist= "KM " + StartKm.ToString() + "+" + DistAppend.ToString();
}

if (flagBorna == 0)
{
//creating text
DBText txtDist = DanBUtility.CreateAcadText(tDist, spip, txtHeight, sepLayer, txtR, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);

txtDist.Layer = "KM";

if (txtDist != null) { k = k + 1; }
}

//next

}

ipColl.Dispose();
sEnt.Dispose();
pl3DEnt.Dispose();
pl2DEnt.Dispose();
GC.Collect();
//next sperarator
nextflagBorna = flagBorna;
Prev_distance = DistAppend;

}

acTrans.Commit();
acTrans.Dispose();
}
pEnt.Dispose();
GPoly.Dispose();
GC.Collect();

MessageBox.Show("Done" + k + " object text.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());

}

try
{


int k = 0;
ObjectId OID = dbu.PickObjectID("Pick 3d polyline >>> ");
Entity pEnt = dbu.GetAcadEntity(ThisDrawing, OID);
Polyline GPoly = pEnt as Polyline;
Extents3d bb = pEnt.GeometricExtents;
dbu.ZoomWin(AcadApp, AcEditor, bb.MinPoint, bb.MaxPoint);

// point3d col
Point3dCollection pCollPolygon = new Point3dCollection();
//get vertex poly
int vk = GPoly.NumberOfVertices;
Point3dCollection pColl = new Point3dCollection();
for (int v = 0; v < vk; v++)
{
Point3d currV = GPoly.GetPoint3dAt(v);
pColl.Add(currV);
}
//flag for blockreference
int flagBorna = 0;
int nextflagBorna = 0;
double Prev_distance = 0;
double total_distance = 0;
//grt date
String sepLayer = comboSepLayer.Text; //3d poly
if (sepLayer == string.Empty)
{
MessageBox.Show("Invalid layer.", "Erorr", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}

Double txtHeight = double.Parse(mtbHTxt.Text); // text high
if (txtHeight <= 0)
{
txtHeight = 1;
}
Double BornaKm = 0;

Double StartKm = double.Parse(mtbStartKm.Text); //start pornire
//Double StartKm =
if (StartKm < 0)
{
StartKm = 0;
}

Double txtR = 0; //rotatiion text

Boolean decrement = cbDecrement.Checked; // decrement distante

 

//selection 3d poly based on layer
TypedValue[] filterValue;
filterValue = new TypedValue[1];
filterValue.SetValue(new TypedValue(8, sepLayer), 0);
SelectionFilter filter = new SelectionFilter(filterValue);
PromptSelectionResult psr = AcEditor.SelectFence(pColl, filter);
if (psr.Status != PromptStatus.OK)
{
MessageBox.Show("Eroar,Invalid geometry", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}

SelectionSet sst = psr.Value;
if (sst.Count < 1)
{
MessageBox.Show("invalid selection.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = acDoc.Editor;
int change = 0;
int nextchange = 0;
using (Transaction acTrans = AcDatabase.TransactionManager.StartTransaction())
{
foreach (SelectedObject acSSObj in sst)
{
Entity sEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) as Entity; //polilinie separator
//ed.WriteMessage(sEnt.ObjectId.ObjectClass.Name);
if (sEnt.ObjectId.ObjectClass.Name!="AcDb3dPolyline")
{
MessageBox.Show("Polyline is not 3d polylinie 3D.");
return;
}
Polyline3d pl3DEnt = (Polyline3d)sEnt;
Polyline pl2DEnt = dbu.ConvertPoly3DTo2D(pl3DEnt);
Extents3d ee = pl2DEnt.GeometricExtents;
dbu.ZoomWin(AcadApp, AcEditor, ee.MinPoint, ee.MaxPoint);

Point2d sp = pl2DEnt.GetPoint2dAt(0); //punct start separator
Point2d ep = pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1); //punct endseparator


//start point
Point3dCollection pCollPolygonstart = new Point3dCollection();
pCollPolygonstart = buildCircularSelectionArray(new Point3d(sp.X, sp.Y, 0), DanBUtility.searchDotTolerance);

// end point
Point3dCollection pCollPolygonend = new Point3dCollection();
pCollPolygonend = buildCircularSelectionArray(new Point3d(ep.X, ep.Y, 0), DanBUtility.searchDotTolerance);

//selection
TypedValue[] BornaValue;
BornaValue = new TypedValue[1];
BornaValue[0] = new TypedValue(0, "INSERT");
SelectionFilter filterBorna = new SelectionFilter(BornaValue);
PromptSelectionResult psrtxtstart = AcEditor.SelectCrossingPolygon(pCollPolygonstart, filterBorna);
if (psrtxtstart.Status == PromptStatus.OK)
{
SelectionSet ssttxtBorna = psrtxtstart.Value;
// ed.WriteMessage("Total :"+ ssttxtBorna.Count.ToString());
foreach (SelectedObject acSSObjTxt in ssttxtBorna)
{



BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;
for (int arId = 0; arId < borna.AttributeCollection.Count - 1; arId++)
{
AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);

if (ar.Tag == "4601")
{

string stkm = ar.TextString;
stkm = stkm.ToUpper().Replace("KM", "");
stkm = stkm.Replace(" ", "");
BornaKm = Convert.ToInt32(stkm);

flagBorna = 1;
}
}
}


}

PromptSelectionResult psrtxtend = AcEditor.SelectCrossingPolygon(pCollPolygonend, filterBorna);
if (psrtxtend.Status == PromptStatus.OK)
{
SelectionSet ssttxtBorna = psrtxtend.Value;

foreach (SelectedObject acSSObjTxt in ssttxtBorna)
{

 

BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;
for (int arId = 0; arId < borna.AttributeCollection.Count - 1; arId++)
{
AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);

if (ar.Tag == "4601")
{

string stkm = ar.TextString;
stkm = stkm.ToUpper().Replace("KM", "");
stkm = stkm.Replace(" ", "");
BornaKm = Convert.ToInt32(stkm);
flagBorna = 1;
}
}
}

}
//if blockreference is missing
if(psrtxtstart.Status != PromptStatus.OK && psrtxtend.Status != PromptStatus.OK)
{
flagBorna = 0;
}


Point3d spip = new Point3d(sp.X, sp.Y, 0);
Double ang = dbu.GetAngle2d(pl2DEnt.GetPoint2dAt(0), pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1)); //citire unghi general al separatorului
if (ang <= Math.PI)//rotatie text
{
txtR = ang - Math.PI / 2; //rotatie text inainte de PI
spip = new Point3d(sp.X, sp.Y, 0);
}
else if (ang > Math.PI)
{
txtR = ang + Math.PI / 2; //rotatie text dupa PI
spip = new Point3d(ep.X, ep.Y, 0);
}


Point3dCollection ipColl = new Point3dCollection();
pEnt.IntersectWith(pl2DEnt, Intersect.OnBothOperands, ipColl, IntPtr.Zero, IntPtr.Zero); //intersectare



Double DistInPunct = 0;
if (flagBorna != nextflagBorna)
{
//reset the value
StartKm = BornaKm;
}

Double DistAppend = 0;
//for ieah point in intersection
foreach (Point3d ip in ipColl)
{


Point3d ptOnCurve = GPoly.GetClosestPointTo(ip, true);
nt db = new DBPoint();
db.Position = new Point3d(ptOnCurve.X, ptOnCurve.Y, 0);

DistInPunct = Math.Round(GPoly.GetDistAtPoint(ptOnCurve), 2);


DistAppend = Math.Round(StartKm + DistInPunct, 0);


if (decrement == true)
{
DistAppend = Math.Round(StartKm - DistInPunct, 0);
}
//caculate the remain disntance
total_distance = DistAppend - Prev_distance ;

//Prev_distance = DistAppend;
Double DistReduced = DistAppend / 1000;
double DistRounded = Math.Round(DistReduced, 3);
string sDist = DistReduced.ToString();

if (metri.Length < 3)
{
if (metri.Length == 2) { metri = metri + "0"; }
else if (metri.Length == 1) { metri = metri + "00"; }
else if (metri.Length == 0) { metri = metri + "000"; }
}

string tDist = "";

// if flag value change=======>here is the problem after blockreference i need to reset the distance and increment it again
if (flagBorna != nextflagBorna)

{
tDist = "KM " + StartKm.ToString() + "+" + total_distance.ToString();

}
else
{
tDist= "KM " + StartKm.ToString() + "+" + DistAppend.ToString();
}

if (flagBorna == 0)
{
//creating text
DBText txtDist = DanBUtility.CreateAcadText(tDist, spip, txtHeight, sepLayer, txtR, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);

txtDist.Layer = "KM";

if (txtDist != null) { k = k + 1; }
}

//next

}

ipColl.Dispose();
sEnt.Dispose();
pl3DEnt.Dispose();
pl2DEnt.Dispose();
GC.Collect();
//next sperarator
nextflagBorna = flagBorna;
Prev_distance = DistAppend;

}

acTrans.Commit();
acTrans.Dispose();
}
pEnt.Dispose();
GPoly.Dispose();
GC.Collect();

MessageBox.Show("Done" + k + " object text.", "Info processing", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());

}

Thanck for your help

0 Likes
Accepted solutions (1)
342 Views
1 Reply
Reply (1)
Message 2 of 2

imagination_s
Advocate
Advocate
Accepted solution


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
.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
try
{
// Point3dCollection allpoints = new Point3dCollection();
//Point3dCollection newpcol = new Point3dCollection();
//getting geometries
this.Hide(); //ascundere form
int k = 0;
ObjectId OID = dbu.PickObjectID("Pic start polyline >>> ");
Entity pEnt = dbu.GetAcadEntity(ThisDrawing, OID);
Polyline GPoly = pEnt as Polyline;
Extents3d bb = pEnt.GeometricExtents;
dbu.ZoomWin(AcadApp, AcEditor, bb.MinPoint, bb.MaxPoint);
this.Show(); //afisare form

// polygon as point3d
Point3dCollection pCollPolygon = new Point3dCollection();
//colect vertex
int vk = GPoly.NumberOfVertices;
Point3dCollection pColl = new Point3dCollection();
for (int v = 0; v < vk; v++)
{
Point3d currV = GPoly.GetPoint3dAt(v);
pColl.Add(currV);
}
Point3d p1=(GPoly.GetPoint3dAt(0));
Point3d p2=new Point3d(0,0,0);
//flag
int flagBorna = 0;
int nextflagBorna = 0;

//get data
String sepLayer = comboSepLayer.Text; //3d poly
if (sepLayer == string.Empty)
{
MessageBox.Show("Invalid 3d poly layer..", "Erorr", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}

Double txtHeight = double.Parse(mtbHTxt.Text);
if (txtHeight <= 0)
{
txtHeight = 1;
}
Double BornaKm = 0;

Double StartKm = double.Parse(mtbStartKm.Text);
//Double StartKm =
if (StartKm < 0)
{
StartKm = 0;
}

Double txtR = 0; //rotatie text

 

 

//selectie
TypedValue[] filterValue;
filterValue = new TypedValue[1];
filterValue.SetValue(new TypedValue(8, sepLayer), 0);
SelectionFilter filter = new SelectionFilter(filterValue);
PromptSelectionResult psr = AcEditor.SelectFence(pColl, filter);
if (psr.Status != PromptStatus.OK)
{
MessageBox.Show("Eroare la selectie. Probabil geometrii invalide.", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}

SelectionSet sst = psr.Value;
if (sst.Count < 1)
{
MessageBox.Show("Selectie vida.", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = acDoc.Editor;
int change = 0;
int nextchange = 0;
//StreamWriter write = new StreamWriter();
double Total = 0;
using (Transaction acTrans = AcDatabase.TransactionManager.StartTransaction())
{
foreach (SelectedObject acSSObj in sst)
{
Entity sEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) as Entity; //polilinie separator
//ed.WriteMessage(sEnt.ObjectId.ObjectClass.Name);
if (sEnt.ObjectId.ObjectClass.Name!="AcDb3dPolyline")
{
MessageBox.Show("Polilinia Separator nu este de tip polylinie 3D.Ma opresc..");
return;
}
Polyline3d pl3DEnt = (Polyline3d)sEnt;
Polyline pl2DEnt = dbu.ConvertPoly3DTo2D(pl3DEnt);
Extents3d ee = pl2DEnt.GeometricExtents;
dbu.ZoomWin(AcadApp, AcEditor, ee.MinPoint, ee.MaxPoint);

Point2d sp = pl2DEnt.GetPoint2dAt(0); //punct start separator
Point2d ep = pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1); //punct endseparator


//pentru punctul de start
Point3dCollection pCollPolygonstart = new Point3dCollection();
pCollPolygonstart = buildCircularSelectionArray(new Point3d(sp.X, sp.Y, 0), DanBUtility.searchDotTolerance);

//pentru punctul de end
Point3dCollection pCollPolygonend = new Point3dCollection();
pCollPolygonend = buildCircularSelectionArray(new Point3d(ep.X, ep.Y, 0), DanBUtility.searchDotTolerance);

//selectie
TypedValue[] BornaValue;
BornaValue = new TypedValue[1];
BornaValue[0] = new TypedValue(0, "INSERT");
SelectionFilter filterBorna = new SelectionFilter(BornaValue);
PromptSelectionResult psrtxtstart = AcEditor.SelectCrossingPolygon(pCollPolygonstart, filterBorna);
if (psrtxtstart.Status == PromptStatus.OK)
{
SelectionSet ssttxtBorna = psrtxtstart.Value;

foreach (SelectedObject acSSObjTxt in ssttxtBorna)
{

BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;
for (int arId = 0; arId < borna.AttributeCollection.Count - 1; arId++)
{
AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);

if (ar.Tag == "4601")
{

string stkm = ar.TextString;
stkm = stkm.ToUpper().Replace("KM", "");
stkm = stkm.Replace(" ", "");
BornaKm = Convert.ToInt32(stkm);
//ed.WriteMessage("Punctul de start "+StartKm + Environment.NewLine);
flagBorna = 1;
}
}
}


}

PromptSelectionResult psrtxtend = AcEditor.SelectCrossingPolygon(pCollPolygonend, filterBorna);
if (psrtxtend.Status == PromptStatus.OK)
{
SelectionSet ssttxtBorna = psrtxtend.Value;

foreach (SelectedObject acSSObjTxt in ssttxtBorna)
{

 

BlockReference borna = acTrans.GetObject(acSSObjTxt.ObjectId, OpenMode.ForRead) as BlockReference;
for (int arId = 0; arId < borna.AttributeCollection.Count - 1; arId++)
{
AttributeReference ar = (AttributeReference)acTrans.GetObject(borna.AttributeCollection[arId], OpenMode.ForRead);

if (ar.Tag == "4601")
{
// MessageBox.Show(ar.TextString);
string stkm = ar.TextString;
stkm = stkm.ToUpper().Replace("KM", "");
stkm = stkm.Replace(" ", "");
BornaKm = Convert.ToInt32(stkm);

flagBorna = 1;
}
}
}

}
if(psrtxtstart.Status != PromptStatus.OK && psrtxtend.Status != PromptStatus.OK)
{
flagBorna = 0;
}


Point3d spip = new Point3d(sp.X, sp.Y, 0);
Double ang = dbu.GetAngle2d(pl2DEnt.GetPoint2dAt(0), pl2DEnt.GetPoint2dAt(pl2DEnt.NumberOfVertices - 1)); //
if (ang <= Math.PI)//rotatie text
{
txtR = ang - Math.PI / 2; //rotatie text inainte de PI
spip = new Point3d(sp.X, sp.Y, 0);
}
else if (ang > Math.PI)
{
txtR = ang + Math.PI / 2; //rotatie text dupa PI
spip = new Point3d(ep.X, ep.Y, 0);
}


Point3dCollection ipColl = new Point3dCollection();
pEnt.IntersectWith(pl2DEnt, Intersect.OnBothOperands, ipColl, IntPtr.Zero, IntPtr.Zero); //intersectare



Double DistInPunct = 0;
if (flagBorna != nextflagBorna)
{
//ed.WriteMessage("KM :" + total_distance + Environment.NewLine);
//DistAppend = Math.Round(StartKm+ DistInPunct, 0);
//DistAppend = Math.Round(StartKm + DistInPunct, 0);
StartKm = BornaKm;
//reset distance
Total = 0;
}


Point3d ptOnCurve = GPoly.GetClosestPointTo(ipColl[0], true);

DBPoint db = new DBPoint();
db.Position = new Point3d(ptOnCurve.X, ptOnCurve.Y, 0);
p2 = new Point3d(db.Position.X, db.Position.Y, 0);
double distance = Math.Round(p1.DistanceTo(p2));
Total = Total + distance;
if (flagBorna == 0)
{

DBText txtDist = DanBUtility.CreateAcadText("KM " + StartKm.ToString() + "+"+ Total.ToString(), spip, txtHeight, sepLayer, txtR, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);

txtDist.Layer = "KM";
if (txtDist != null) { k = k + 1; }

}

ipColl.Dispose();
sEnt.Dispose();
pl3DEnt.Dispose();
pl2DEnt.Dispose();
GC.Collect();
//next sperarator
nextflagBorna = flagBorna;

p1 = p2;
}

acTrans.Commit();
acTrans.Dispose();
}
pEnt.Dispose();
GPoly.Dispose();
GC.Collect();

MessageBox.Show("Done. Generated " + k + " object text.", "Info procesare", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());

}

0 Likes