public class Class1
{
MainWindow mw = new MainWindow();
Document curenntdoc;
[CommandMethod("ss")]
public void CreateFromTin()
{
curenntdoc = Application.DocumentManager.MdiActiveDocument;
mw.bworker.DoWork += work;
mw.bworker.RunWorkerAsync();
}
public void work(object sender, DoWorkEventArgs e)
{
Editor ed = curenntdoc.Editor;
using (Transaction ts = curenntdoc.Database.TransactionManager.StartTransaction())
{
Database db = curenntdoc.Database;
CivilDocument civil_doc = CivilApplication.ActiveDocument;
ObjectId surface_id1 = civil_doc.GetSurfaceIds()[1];
Autodesk.Civil.DatabaseServices.TinSurface tin_surface1 = surface_id1.GetObject(OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.TinSurface;
ObjectId newSurfid = TinSurface.Create(db, "Surf1");
TinSurface newtin = newSurfid.GetObject(OpenMode.ForWrite) as TinSurface;
newtin.CopyFrom(tin_surface1);
newtin.RaiseSurface(5);
ObjectId borderId = newtin.ExtractBorder(Autodesk.Civil.SurfaceExtractionSettingsType.Plan)[0];
Polyline3d border = borderId.GetObject(OpenMode.ForRead) as Polyline3d;
Point3dCollection vertexInPoly = new Point3dCollection();
foreach (ObjectId acObjIdVert in border)
{
PolylineVertex3d acPolVer3d;
acPolVer3d = ts.GetObject(acObjIdVert,
OpenMode.ForRead) as PolylineVertex3d;
vertexInPoly.Add(acPolVer3d.Position);
}
Point3dCollection offsetline = new Point3dCollection();
List<string> angle = new List<string>();
for (int i = 0; i < vertexInPoly.Count-1; i++)
{
int k = i - 1;
if (k < 0)
{
k = vertexInPoly.Count - 2;
}
int j = i + 1;
if (j > vertexInPoly.Count - 2)
{
j = 0;
}
Mpoint m = new Mpoint(vertexInPoly[k], vertexInPoly[i], vertexInPoly[j], 5);
//////////////////////////////////////////////
Thread.Sleep(1000);
mw.bworker.ReportProgress(1);
if (m.SharpAngle == false)//если угол больше 180 - строим дугу между перпендикулярами
{
offsetline.Add(m.OrthoPointFromEdge1);
foreach (Point3d item in m.PointInAngle)
{
offsetline.Add(item);
}
offsetline.Add(m.OrthoPointFromEdge2);
}
else if (m.SharpAngle == true)// если угол меньше 180 - строим одну точку(угол)
{
if (m.GetDist(vertexInPoly[k], vertexInPoly[j]) > 10)// если расстояние между двумя(крайними) точками меньше расстояния подобия*2 то не строим угловую точку
{
offsetline.Add(m.Intersect);
}
}
//////////////////////////////////////////////
string s = "угол " + i.ToString() + " " + m.Angle.ToString() + " " + m.SharpAngle.ToString() + " Кол-во точек для угла: " + m.CountPointInAngle.ToString();
angle.Add(s + "\n");
}
BlockTable acBlkTbl;
acBlkTbl = ts.GetObject(db.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = ts.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
Polyline3d newpoly = new Polyline3d();
newpoly.SetDatabaseDefaults();
newpoly.ColorIndex = 1;
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(newpoly);
ts.AddNewlyCreatedDBObject(newpoly, true);
for (int i = 0; i < offsetline.Count; i++)
{
newpoly.AppendVertex(new PolylineVertex3d(offsetline[i]));
}
newpoly.Closed = true;
foreach (string s in angle)
{
ed.WriteMessage(s);
}
foreach (Point3d p in vertexInPoly)
{
ed.WriteMessage(p.X.ToString() + " / " + p.Y.ToString());
}
ts.Commit();
}
}
}