/** * @brief Metodo que descompone una enitdad AUTOCAD en sub-entidades cuando es posible. Replica el comportamiento del comando * DESCOMPONER / EXPLODE de AutoCAD. Las unidades básicas que devuelve son puntos y lineas. Descompone recursivamente * las entidades hasta dejarlas representadas como puntos, lineas y arcos. * * @param ent Entidad que debe ser descompuesta * @param acBlkTbl Tabla de bloques de AutoCAD para buscar nuevos objetos y añadir nuevos objetos generados. * @param acBlkTblRec Tabla de registros de los bloques de AutoCAD para buscar nuevos objetos y añadir nuevos objetos generados. * @param t Transaccion abierta para manipular la tabla de bloques de AutoCAD. * * @return Devuelve una colección de entidades bajo la clase DBObjectCollection. **/ private static DBObjectCollection ObtenerPuntosyLineas(Entity ent, BlockTable acBlkTbl, BlockTableRecord acBlkTblRec, Transaction t) { DBObjectCollection retorno = new DBObjectCollection(); DBObjectCollection procesar = new DBObjectCollection(); ent.Explode(procesar); while (procesar.Count != 0) { Entity obj = (Entity)procesar[0]; acBlkTblRec.AppendEntity(obj); t.AddNewlyCreatedDBObject(obj, true); dwgf.objetosArtificiales.Add(obj.ObjectId); if (obj.ObjectId.ObjectClass.DxfName == "POINT" || obj.ObjectId.ObjectClass.DxfName == "LINE") { if (retorno.Contains(obj) == false) { retorno.Add(obj); } } if (obj.ObjectId.ObjectClass.DxfName == "ARC") { // Completar con el proceso para los arcos. if (retorno.Contains(obj) == false) { retorno.Add(obj); } } if (obj.ObjectId.ObjectClass.DxfName == "LWPOLYLINE") { DBObjectCollection aux = new DBObjectCollection(); obj.Explode(aux); foreach (DBObject aux2 in aux) { procesar.Add(aux2); } } procesar.Remove(obj); } return(retorno); }
//[CommandMethod("gi")] public static void GetIntersections() { var db = HostApplicationServices.WorkingDatabase; var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; using (var docLock = doc.LockDocument()) { using (var tr = db.TransactionManager.StartTransaction()) { try { var btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); var peo = new PromptEntityOptions("\nSelect a single polyline >>"); peo.SetRejectMessage("\nSelected object might be of type polyline only >>"); peo.AddAllowedClass(typeof(Polyline), false); PromptEntityResult res; res = ed.GetEntity(peo); if (res.Status != PromptStatus.OK) { return; } var ent = tr.GetObject(res.ObjectId, OpenMode.ForRead); if (ent == null) { return; } //Polyline poly = (Polyline)ent as Polyline; var curv = ent as Curve; var pcurves = new DBObjectCollection(); curv.Explode(pcurves); TypedValue[] values = { new TypedValue(0, "lwpolyline") //might be added layer name to select curve: //, new TypedValue(8, "mylayer") }; var filter = new SelectionFilter(values); var fence = new Point3dCollection(); var leng = curv.GetDistanceAtParameter(curv.EndParam) - curv.GetDistanceAtParameter(curv.StartParam); // number of divisions along polyline to create fence selection var step = leng / 256; // set number of steps to your suit var num = Convert.ToInt32(leng / step); var i = 0; for (i = 0; i < num; i++) { var pp = curv.GetPointAtDist(step * i); fence.Add(curv.GetClosestPointTo(pp, false)); } var selres = ed.SelectFence(fence, filter); if (selres.Status != PromptStatus.OK) { return; } var intpts = new Point3dCollection(); var qcurves = new DBObjectCollection(); foreach (SelectedObject selobj in selres.Value) { var obj = tr.GetObject(selobj.ObjectId, OpenMode.ForRead, false); if (selobj.ObjectId != curv.ObjectId) { var icurves = new DBObjectCollection(); var icurv = obj as Curve; icurv.Explode(icurves); foreach (DBObject dbo in icurves) { if (!qcurves.Contains(dbo)) { qcurves.Add(dbo); } } } } ed.WriteMessage("\n{0}", qcurves.Count); var j = 0; var polypts = new Point3dCollection(); for (i = 0; i < pcurves.Count; ++i) { for (j = 0; j < qcurves.Count; ++j) { var curve1 = pcurves[i] as Curve; var curve2 = qcurves[j] as Curve; var pts = new Point3dCollection(); curve1.IntersectWith(curve2, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero); foreach (Point3d pt in pts) { if (!polypts.Contains(pt)) { polypts.Add(pt); } } } } Application.SetSystemVariable("osmode", 0); // optional // for debug only Application.ShowAlertDialog(string.Format("\nNumber of Intersections: {0}", polypts.Count)); // test for visulization only foreach (Point3d inspt in polypts) { var circ = new Circle(inspt, Vector3d.ZAxis, 10 * db.Dimtxt); circ.ColorIndex = 1; btr.AppendEntity(circ); tr.AddNewlyCreatedDBObject(circ, true); } tr.Commit(); } catch (Exception ex) { ed.WriteMessage("\n{0}\n{1}", ex.Message, ex.StackTrace); } } } }
public void GetIntersectionsRiver() { Database db = HostApplicationServices.WorkingDatabase; Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Transaction tr = db.TransactionManager.StartTransaction(); #region For Word string filepath = "D:\\intersections_rivers.docx"; using (WordprocessingDocument docX = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document)) { try { // Add a main document part. MainDocumentPart mainPart = docX.AddMainDocumentPart(); StyleDefinitionsPart styleDefinitionsPart = mainPart.AddNewPart<StyleDefinitionsPart>(); Styles styles1 = new Styles(); DocDefaults docDefaults = new DocDefaults( new RunPropertiesDefault(new RunPropertiesBaseStyle(new RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" }, new FontSize() { Val = "24" }, new FontSizeComplexScript() { Val = "24" })), new ParagraphPropertiesDefault(new SpacingBetweenLines() { After = "0", Line = "240", LineRule = LineSpacingRuleValues.Auto })); styles1.AppendChild(docDefaults); styleDefinitionsPart.Styles = styles1; mainPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document(); DocumentFormat.OpenXml.Wordprocessing.Body body = mainPart.Document.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Body()); ParagraphProperties paragraphProperties1 = new ParagraphProperties( new Justification() { Val = JustificationValues.Center }, new ParagraphMarkRunProperties( new RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" }, new FontSize() { Val = "24" }, new FontSizeComplexScript() { Val = "24" } )); Paragraph para = body.AppendChild(new Paragraph()); para.AppendChild(paragraphProperties1); Run run = para.AppendChild(new Run()); RunProperties runProperties1 = new RunProperties( new Bold()); // String msg contains the text, "Hello, Word!" run.AppendChild(runProperties1); run.AppendChild(new Text("ПРИЛОЖЕНИЕ")); run.AppendChild(new Break()); run.AppendChild(new Text("Ведомость пересечений")); run.AppendChild(new Break()); var table = new DocumentFormat.OpenXml.Wordprocessing.Table(); // Create a TableProperties object and specify its border information. TableProperties tblProp = new TableProperties( new TableWidth() { Width = "9782", Type = TableWidthUnitValues.Dxa }, new TableIndentation() { Width = -318, Type = TableWidthUnitValues.Dxa }, new TableBorders( new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4, Space = 0 }, new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4, Space = 0 }, new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4, Space = 0 }, new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4, Space = 0 }, new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4, Space = 0 }, new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4, Space = 0 }), new DocumentFormat.OpenXml.Wordprocessing.TableStyle() { Val = "TableGrid" } ); // Append the TableProperties object to the empty table. table.AppendChild<TableProperties>(tblProp); // Add 3 columns to the table. TableGrid tg = new TableGrid(new GridColumn(), new GridColumn(), new GridColumn(), new GridColumn(), new GridColumn(), new GridColumn(), new GridColumn(), new GridColumn(), new GridColumn()); table.AppendChild(tg); TableRow tr1 = new TableRow( new TableRowProperties(new TableRowHeight() { Val = 430 }), new TableCell( new TableCellProperties( new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1709" }, new VerticalMerge() { Val = MergedCellValues.Restart }, new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }), new Paragraph(new ParagraphProperties(GetCenterJustify()), new Run(new Text("Наимен. водотока")))), //new TableCellProperties(new TableCellWidth() {Type = TableWidthUnitValues.Pct, Width = "500"}) new TableCell( new TableCellProperties( new GridSpan() { Val = 2 }, new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }, new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "3922" }), new Paragraph( new ParagraphProperties(new Justification() { Val = JustificationValues.Center }), new Run(new Text("Пикетное положение пересечения")))), new TableCell( new TableCellProperties( new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }), new Paragraph( new ParagraphProperties(new Justification() { Val = JustificationValues.Center }), new Run(new Text("Ширина водотока в межень")))), new TableCell( new TableCellProperties( new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1358" }, new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }, new VerticalMerge() { Val = MergedCellValues.Restart }), new Paragraph(new ParagraphProperties(GetCenterJustify()), new Run(new Text("Глуб. водотока")))), new TableCell( new TableCellProperties( new GridSpan() { Val = 3 }, new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }, new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2368" }), new Paragraph(new ParagraphProperties(GetCenterJustify()), new Run(new Text("Горизонт воды")))), new TableCell(new TableCellProperties( new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "425" }, new VerticalMerge() { Val = MergedCellValues.Restart }, new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }), new Paragraph(new ParagraphProperties(GetCenterJustify()), new Run(new Text("Прим.")))) ); table.AppendChild(tr1); TableRow tr2 = new TableRow( new TableRowProperties(new TableRowHeight() { Val = 419 }), new TableCell(new TableCellProperties(new VerticalMerge()), new Paragraph(new Run())), new TableCell( new TableCellProperties(new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }), new ParagraphProperties(new Justification() { Val = JustificationValues.Center }), new Paragraph(new Run(new Text("От")))), new TableCell( new TableCellProperties(new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }), new ParagraphProperties(new Justification() { Val = JustificationValues.Center }), new Paragraph(new Run(new Text("До")))), new TableCell( new TableCellProperties(new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }), new ParagraphProperties(new Justification() { Val = JustificationValues.Center }), new Paragraph(new Run(new Text("половодье")))), new TableCell(new TableCellProperties(new VerticalMerge()), new Paragraph(new Run())), new TableCell( new TableCellProperties( new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1260" }, new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }), new Paragraph(new ParagraphProperties(GetCenterJustify()), new Run(new Text("Дата съемки")))), new TableCell( new TableCellProperties( new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1108" }, new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }), new Paragraph(new ParagraphProperties(GetCenterJustify()), new Run(new Text("На день съемки")))), new TableCell( new TableCellProperties( new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1108" }, new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }), new Paragraph(new ParagraphProperties(GetCenterJustify()), new Run(new Text("Макс.")))), new TableCell(new TableCellProperties(new VerticalMerge()), new Paragraph(new Run()))); table.AppendChild(tr2); TableCellProperties tcp = new TableCellProperties(new GridSpan() { Val = 9 }); #endregion while (true) { //using (tr) //{ try { #region Поиск пересечений BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); PromptEntityOptions peo = new PromptEntityOptions("\nВыбери polyline >>"); peo.SetRejectMessage("\nМожно только polyline >>"); peo.AddAllowedClass(typeof(Polyline), false); PromptEntityResult res; res = ed.GetEntity(peo); if (res.Status != PromptStatus.OK) { break; } DBObject ent = (DBObject)tr.GetObject(res.ObjectId, OpenMode.ForRead); if (ent == null) return; PromptPointResult pPtRes; PromptPointOptions pPtOpts = new PromptPointOptions(""); // Prompt for the start point pPtOpts.Message = "\nВведи начало: "; pPtRes = doc.Editor.GetPoint(pPtOpts); PromptDoubleOptions getpik = new PromptDoubleOptions("\nВведи пикетаж (в формате числа, а не 0+00): "); PromptDoubleResult getpikRes = doc.Editor.GetDouble(getpik); //zoom /*PromptEntityResult per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) return;*/ // Extract its extents Extents3d ext; Transaction trans = db.TransactionManager.StartTransaction(); using (trans) { Entity enti = (Entity)trans.GetObject(res.ObjectId, OpenMode.ForRead); ext = enti.GeometricExtents; trans.Commit(); } ext.TransformBy(ed.CurrentUserCoordinateSystem.Inverse()); ZoomWin(ed, ext.MinPoint, ext.MaxPoint); // //Polyline poly = (Polyline)ent as Polyline; Curve curv = ent as Curve; DBObjectCollection pcurves = new DBObjectCollection(); curv.Explode(pcurves); TypedValue[] values = new TypedValue[] { new TypedValue(0, "lwpolyline") //might be added layer name to select curve: //, new TypedValue(8, "mylayer") }; SelectionFilter filter = new SelectionFilter(values); Point3dCollection fence = new Point3dCollection(); double leng = curv.GetDistanceAtParameter(curv.EndParam) - curv.GetDistanceAtParameter(curv.StartParam); // number of divisions along polyline to create fence selection double step = leng / 256;// set number of steps to your suit int num = Convert.ToInt32(leng / step); for (int i = 0; i < num; i++) { Point3d pp = curv.GetPointAtDist(step * i); fence.Add(curv.GetClosestPointTo(pp, false)); } PromptSelectionResult selres = ed.SelectFence(fence, filter); if (selres.Status != PromptStatus.OK) return; Point3dCollection intpts = new Point3dCollection(); DBObjectCollection qcurves = new DBObjectCollection(); //ed.WriteMessage("\nCheck"); foreach (SelectedObject selobj in selres.Value) { DBObject obj = tr.GetObject(selobj.ObjectId, OpenMode.ForRead, false) as DBObject; if (selobj.ObjectId != curv.ObjectId) { DBObjectCollection icurves = new DBObjectCollection(); Curve icurv = obj as Curve; icurv.Explode(icurves); foreach (DBObject dbo in icurves) { if (!qcurves.Contains(dbo)) qcurves.Add(dbo); } } } //ed.WriteMessage("\n{0}", qcurves.Count); int j = 0; Point3dCollection polypts = new Point3dCollection(); for (int i = 0; i < pcurves.Count; ++i) { for (j = 0; j < qcurves.Count; ++j) { Curve curve1 = pcurves[i] as Curve; Curve curve2 = qcurves[j] as Curve; Point3dCollection pts = new Point3dCollection(); curve1.IntersectWith(curve2, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero); foreach (Point3d pt in pts) { if (!polypts.Contains(pt)) polypts.Add(pt); } } } #endregion try { using (Transaction tran = db.TransactionManager.StartTransaction()) { Polyline pline = (Polyline)tran.GetObject(res.ObjectId, OpenMode.ForRead); table.AppendChild(new TableRow( new TableCell( new TableCellProperties( new GridSpan() { Val = 9 }), new Paragraph( new ParagraphProperties( new ParagraphMarkRunProperties(new Bold()), new Justification() { Val = JustificationValues.Center }), new Run(new RunProperties( new Bold()), new Text("ПК" + ((int)(getpikRes.Value)).ToString("F0") + "-ПК" + ((int)(100 * getpikRes.Value + pline.Length) / 100).ToString("F0") + "+" + ((100 * getpikRes.Value + pline.Length) % 100).ToString("F"))))))); } } catch { ed.WriteMessage("\nError."); } Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", 0);// optional // for debug only Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Format("\nНайдено пересечений: {0}", polypts.Count)); if (polypts.Count == 0) { try { using (Transaction tran = db.TransactionManager.StartTransaction()) { Polyline pline = (Polyline)tran.GetObject(res.ObjectId, OpenMode.ForRead); table.AppendChild(new TableRow( new TableCell( new TableCellProperties( new GridSpan() { Val = 9 }), new Paragraph( new ParagraphProperties( new Justification() { Val = JustificationValues.Center }), new Run(new Text("На данном участке трассы пересечения отсутствуют")))))); } } catch { ed.WriteMessage("\nError."); } } else { //List<double> pik = new List<double>(polypts.Count); double[] pik = new double[polypts.Count]; int numInter = 0; foreach (Point3d inspt in polypts) { double dist = 0; dist = 100 * getpikRes.Value; // test for visulization only /*Circle circ = new Circle(inspt, Vector3d.ZAxis, 10 * db.Dimtxt); circ.ColorIndex = 1; btr.AppendEntity(circ); tr.AddNewlyCreatedDBObject(circ, true);*/ Point3d curr = pPtRes.Value, next = pPtRes.Value; try { using (Transaction tran = db.TransactionManager.StartTransaction()) { Polyline pline = (Polyline)tran.GetObject(res.ObjectId, OpenMode.ForRead); if ((pPtRes.Value == pline.GetLineSegmentAt(0).StartPoint) || (pPtRes.Value == pline.GetLineSegmentAt(0).EndPoint)) for (int i = 0; i < pline.NumberOfVertices - 2; i++) { LineSegment3d l1 = pline.GetLineSegmentAt(i); LineSegment3d l2 = pline.GetLineSegmentAt(i + 1); double angle = GetPolylineShape(l1, l2, pline.Normal); if (angle > Math.PI) { if ((l1.StartPoint == l2.StartPoint) || (l1.StartPoint == l2.EndPoint)) next = l1.StartPoint; else if ((l1.EndPoint == l2.EndPoint) || (l1.EndPoint == l2.StartPoint)) next = l1.EndPoint; } else { if ((l1.StartPoint == l2.StartPoint) || (l1.StartPoint == l2.EndPoint)) next = l1.StartPoint; else if ((l1.EndPoint == l2.EndPoint) || (l1.EndPoint == l2.StartPoint)) next = l1.EndPoint; } if (Math.Abs(inspt.DistanceTo(curr) + inspt.DistanceTo(next) - curr.DistanceTo(next)) < 1) { dist += inspt.DistanceTo(curr); ed.WriteMessage(((int)dist / 100).ToString("F0") + "+" + (dist % 100).ToString("F") + "\n"); break; } else dist += curr.DistanceTo(next); curr = next; } else for (int i = pline.NumberOfVertices - 3; i >= 0; i--) { LineSegment3d l1 = pline.GetLineSegmentAt(i); LineSegment3d l2 = pline.GetLineSegmentAt(i + 1); double angle = GetPolylineShape(l1, l2, pline.Normal); if (angle > Math.PI) { if ((l1.StartPoint == l2.StartPoint) || (l1.StartPoint == l2.EndPoint)) next = l1.StartPoint; else if ((l1.EndPoint == l2.EndPoint) || (l1.EndPoint == l2.StartPoint)) next = l1.EndPoint; } else { if ((l1.StartPoint == l2.StartPoint) || (l1.StartPoint == l2.EndPoint)) next = l1.StartPoint; else if ((l1.EndPoint == l2.EndPoint) || (l1.EndPoint == l2.StartPoint)) next = l1.EndPoint; } if (Math.Abs(inspt.DistanceTo(curr) + inspt.DistanceTo(next) - curr.DistanceTo(next)) < 1) { dist += inspt.DistanceTo(curr); ed.WriteMessage(((int)dist / 100).ToString("F0") + "+" + (dist % 100).ToString("F") + "\n"); break; } else dist += curr.DistanceTo(next); curr = next; } } } catch { ed.WriteMessage("\nInvalid polyline."); } pik[numInter] = dist; numInter++; //ed.WriteMessage(" {0:0.00}\n", dist); } //pik.Sort(); Array.Sort(pik); for (int i = 0; i < polypts.Count; i++) { tr1 = new TableRow( new TableRowProperties(new TableRowHeight() { Val = 300 }), new TableCell(new Paragraph(new Run())), new TableCell( new TableCellProperties( new GridSpan() { Val = 2 }), new Paragraph( new ParagraphProperties( new Justification() { Val = JustificationValues.Center }), new Run(new Text(((int)pik[i] / 100).ToString("F0") + "+" + (pik[i] % 100).ToString("F"))))), new TableCell(new Paragraph(new Run())), new TableCell(new Paragraph(new Run())), new TableCell(new Paragraph(new Run())), new TableCell(new Paragraph(new Run())), new TableCell(new Paragraph(new Run())), new TableCell(new Paragraph(new Run())) ); table.AppendChild(tr1); } } } catch { ed.WriteMessage("\nError"); } //} } tr.Commit(); body.AppendChild(table); body.AppendChild( new SectionProperties( new PageMargin() { Top = 1134, Right = (UInt32Value)850U, Bottom = 1134, Left = (UInt32Value)1418U, Header = (UInt32Value)708U, Footer = (UInt32Value)708U, Gutter = (UInt32Value)0U })); ed.WriteMessage("\nДокумент сохранен в D:\\intersections_rivers.docx"); } catch { ed.WriteMessage("\nError."); } } }
public static bool GetFuJinPL(Entity Ent, double Dist, string LayerName, double Angle, ref DBObjectCollection DBC) { TypedValue[] array = new TypedValue[1]; Array array2 = array; TypedValue typedValue; typedValue..ctor(0, "LWPOLYLINE"); array2.SetValue(typedValue, 0); if (Operators.CompareString(LayerName, "", false) != 0) { array = (TypedValue[])Utils.CopyArray((Array)array, new TypedValue[2]); Array array3 = array; typedValue..ctor(8, LayerName); array3.SetValue(typedValue, 1); } Point3d maxPoint = Ent.GeometricExtents.MaxPoint; Point3d minPoint = Ent.GeometricExtents.MinPoint; Point3dCollection point3dCollection = new Point3dCollection(); Point3dCollection point3dCollection2 = point3dCollection; Point3d point3dAt; point3dAt..ctor(minPoint.X - Dist, minPoint.Y - Dist, 0.0); point3dCollection2.Add(point3dAt); Point3dCollection point3dCollection3 = point3dCollection; point3dAt..ctor(minPoint.X - Dist, maxPoint.Y + Dist, 0.0); point3dCollection3.Add(point3dAt); Point3dCollection point3dCollection4 = point3dCollection; point3dAt..ctor(maxPoint.X + Dist, maxPoint.Y + Dist, 0.0); point3dCollection4.Add(point3dAt); Point3dCollection point3dCollection5 = point3dCollection; point3dAt..ctor(maxPoint.X + Dist, minPoint.Y - Dist, 0.0); point3dCollection5.Add(point3dAt); DBObjectCollection dbobjectCollection = CAD.CrossingPolygon(point3dCollection, array); if (dbobjectCollection.Count >= 1) { try { foreach (object obj in dbobjectCollection) { Polyline polyline = (Polyline)obj; if (!DBC.Contains(polyline)) { point3dAt = polyline.GetPoint3dAt(1); point3dAt.GetVectorTo(polyline.GetPoint3dAt(2)).AngleOnPlane(new Plane()); Line line = new Line(polyline.GetPoint3dAt(1), polyline.GetPoint3dAt(2)); if (Math.Abs(line.Angle - Math.Abs(Angle)) < 0.01) { DBC.Add(polyline); TcBJFJ_frm.GetFuJinDBText(polyline, Dist, LayerName, Angle, ref DBC); } } } } finally { IEnumerator enumerator; if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } } } bool result; return(result); }
public static bool GetFuJinDBText(Entity Ent, double Dist, string LayerName, double Angle, ref DBObjectCollection DBCT) { TypedValue[] array = new TypedValue[1]; Array array2 = array; TypedValue typedValue; typedValue..ctor(0, "Text"); array2.SetValue(typedValue, 0); if (Operators.CompareString(LayerName, "", false) != 0) { array = (TypedValue[])Utils.CopyArray((Array)array, new TypedValue[2]); Array array3 = array; typedValue..ctor(8, LayerName); array3.SetValue(typedValue, 1); } Point3d maxPoint = Ent.GeometricExtents.MaxPoint; Point3d minPoint = Ent.GeometricExtents.MinPoint; Point3dCollection point3dCollection = new Point3dCollection(); Point3dCollection point3dCollection2 = point3dCollection; Point3d point3d; point3d..ctor(minPoint.X - Dist, minPoint.Y - Dist, 0.0); point3dCollection2.Add(point3d); Point3dCollection point3dCollection3 = point3dCollection; point3d..ctor(minPoint.X - Dist, maxPoint.Y + Dist, 0.0); point3dCollection3.Add(point3d); Point3dCollection point3dCollection4 = point3dCollection; point3d..ctor(maxPoint.X + Dist, maxPoint.Y + Dist, 0.0); point3dCollection4.Add(point3d); Point3dCollection point3dCollection5 = point3dCollection; point3d..ctor(maxPoint.X + Dist, minPoint.Y - Dist, 0.0); point3dCollection5.Add(point3d); DBObjectCollection dbobjectCollection = CAD.CrossingPolygon(point3dCollection, array); if (dbobjectCollection.Count >= 1) { try { foreach (object obj in dbobjectCollection) { DBText dbtext = (DBText)obj; if (!DBCT.Contains(dbtext)) { double num = dbtext.Rotation; if (num > 6.2831853071795862) { num -= 6.2831853071795862; } if (Math.Abs(num - Angle) < 0.01) { DBCT.Add(dbtext); TcBJFJ_frm.GetFuJinDBText(dbtext, Dist, LayerName, Angle, ref DBCT); } } } } finally { IEnumerator enumerator; if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } } } bool result; return(result); }
/** * @brief Metodo que descompone una enitdad AUTOCAD en sub-entidades cuando es posible. Replica el comportamiento del comando * DESCOMPONER / EXPLODE de AutoCAD. Las unidades básicas que devuelve son puntos y lineas. Descompone recursivamente * las entidades hasta dejarlas representadas como puntos, lineas y arcos. * * @param ent Entidad que debe ser descompuesta * @param acBlkTbl Tabla de bloques de AutoCAD para buscar nuevos objetos y añadir nuevos objetos generados. * @param acBlkTblRec Tabla de registros de los bloques de AutoCAD para buscar nuevos objetos y añadir nuevos objetos generados. * @param t Transaccion abierta para manipular la tabla de bloques de AutoCAD. * * @return Devuelve una colección de entidades bajo la clase DBObjectCollection. **/ private static DBObjectCollection ObtenerPuntosyLineas(Entity ent, BlockTable acBlkTbl, BlockTableRecord acBlkTblRec, Transaction t) { DBObjectCollection retorno = new DBObjectCollection(); DBObjectCollection procesar = new DBObjectCollection(); ent.Explode(procesar); while (procesar.Count != 0) { Entity obj = (Entity) procesar[0]; acBlkTblRec.AppendEntity(obj); t.AddNewlyCreatedDBObject(obj, true); dwgf.objetosArtificiales.Add(obj.ObjectId); if (obj.ObjectId.ObjectClass.DxfName == "POINT" || obj.ObjectId.ObjectClass.DxfName == "LINE") { if (retorno.Contains(obj) == false) { retorno.Add(obj); } } if (obj.ObjectId.ObjectClass.DxfName == "ARC") { // Completar con el proceso para los arcos. if (retorno.Contains(obj) == false) { retorno.Add(obj); } } if (obj.ObjectId.ObjectClass.DxfName == "LWPOLYLINE") { DBObjectCollection aux = new DBObjectCollection(); obj.Explode(aux); foreach (DBObject aux2 in aux) { procesar.Add(aux2); } } procesar.Remove(obj); } return retorno; }
public void TcGJDY() { Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument; Database database = mdiActiveDocument.Database; ObjectIdCollection objectIdCollection = new ObjectIdCollection(); DBObjectCollection dbobjectCollection = new DBObjectCollection(); TypedValue[] array = new TypedValue[1]; Array array2 = array; TypedValue typedValue; typedValue..ctor(0, "LWPOLYLINE"); array2.SetValue(typedValue, 0); SelectionFilter selectionFilter = new SelectionFilter(array); PromptSelectionResult selection = mdiActiveDocument.Editor.GetSelection(selectionFilter); Point3d entCenter; if (selection.Status == 5100) { using (Transaction transaction = database.TransactionManager.StartTransaction()) { SelectionSet value = selection.Value; double num = double.MinValue; Polyline polyline = null; try { foreach (object obj in value) { SelectedObject selectedObject = (SelectedObject)obj; Polyline polyline2 = (Polyline)transaction.GetObject(selectedObject.ObjectId, 1); if (!polyline2.Closed && polyline2.Area > num) { num = polyline2.Area; polyline = polyline2; entCenter = CAD.GetEntCenter(polyline2); } } } finally { IEnumerator enumerator; if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } } dbobjectCollection.Add(polyline); try { foreach (object obj2 in value) { SelectedObject selectedObject2 = (SelectedObject)obj2; Polyline polyline3 = (Polyline)transaction.GetObject(selectedObject2.ObjectId, 1); if (polyline3.GetStartWidthAt(0) != 0.0 && polyline3.Area > 10000.0 && !polyline3.Closed) { Polyline polyline4 = (Polyline)polyline3.Clone(); CAD.EntScale(polyline4, entCenter, 0.3); if (!dbobjectCollection.Contains(polyline3)) { double num2 = polyline3.GeometricExtents.MinPoint.GetVectorTo(polyline3.GeometricExtents.MaxPoint).AngleOnPlane(new Plane()); if (num2 > 0.78539816339744828) { CAD.EntMove(polyline4.ObjectId, entCenter, CAD.GetPointXY(entCenter, 50.0, 75.0)); } else { CAD.EntMove(polyline4.ObjectId, entCenter, CAD.GetPointXY(entCenter, 75.0, 50.0)); } } CAD.AddEnt(polyline4); objectIdCollection.Add(polyline4.ObjectId); } } } finally { IEnumerator enumerator2; if (enumerator2 is IDisposable) { (enumerator2 as IDisposable).Dispose(); } } transaction.Commit(); } } JigEntIDs1 jigEntIDs = new JigEntIDs1(); jigEntIDs.method_0(objectIdCollection, entCenter); if (Information.Err().Number > 0) { Interaction.MsgBox(Information.Err().Description, MsgBoxStyle.OkOnly, null); } }