diff --git a/AcadToSMath/AcadToSMath.cs b/AcadToSMath/AcadToSMath.cs index 158b5e4..64e0dd1 100644 --- a/AcadToSMath/AcadToSMath.cs +++ b/AcadToSMath/AcadToSMath.cs @@ -29,7 +29,7 @@ namespace AcadToSMath { new TermInfo("GetAcPlines", TermType.Function, "(1:слой, 2:масштаб единиц чертежа, 3:замкнуть полилинии) - " + - "Получает вершины полилиний из ативного документа AutoCAD, возвращает массив с координатами вершин полилиний.", + "Получает вершины полилиний из активного документа AutoCAD, возвращает массив с координатами вершин полилиний.", FunctionSections.Files, true, new ArgumentInfo(ArgumentSections.String, true), new ArgumentInfo(ArgumentSections.RealNumber, true), @@ -37,7 +37,28 @@ namespace AcadToSMath new TermInfo("GetAcCircles", TermType.Function, "(1:слой, 2:масштаб единиц чертежа) - " + - "Получает вершины полилиний из ативного документа AutoCAD, возвращает массив с координатами вершин полилиний.", + "Получает координаты центров, площади и диамерты окружностей из активного документа AutoCAD, возвращает массив с данными окружностей.", + FunctionSections.Files, true, + new ArgumentInfo(ArgumentSections.String, true), + new ArgumentInfo(ArgumentSections.RealNumber, true)), + + new TermInfo("GetAcTextes", TermType.Function, + "(1:слой, 2:масштаб единиц чертежа) - " + + "Получает координаты точек вставки и содержимое однострочных текстов из активного документа AutoCAD, возвращает массив с данными текста.", + FunctionSections.Files, true, + new ArgumentInfo(ArgumentSections.String, true), + new ArgumentInfo(ArgumentSections.RealNumber, true)), + + new TermInfo("GetAcPoints", TermType.Function, + "(1:слой, 2:масштаб единиц чертежа) - " + + "Получает координаты точек из активного документа AutoCAD, возвращает массив с координатами точек.", + FunctionSections.Files, true, + new ArgumentInfo(ArgumentSections.String, true), + new ArgumentInfo(ArgumentSections.RealNumber, true)), + + new TermInfo("GetAcLines", TermType.Function, + "(1:слой, 2:масштаб единиц чертежа) - " + + "Получает координаты точек отрезков и их длину из активного документа AutoCAD, возвращает массив с данными отрезков.", FunctionSections.Files, true, new ArgumentInfo(ArgumentSections.String, true), new ArgumentInfo(ArgumentSections.RealNumber, true)), @@ -259,6 +280,262 @@ namespace AcadToSMath } } } + + //GetAcPoints + if (value.Type == TermType.Function && value.Text == "GetAcPoints") + { + List answer = new List(); + + string lay = "#"; + double scale = 1; + if (TermsConverter.DecodeText(value.Items[0].Text).Trim('"') != "#") lay = TermsConverter.DecodeText(value.Items[0].Text).Trim('"'); + if (TermsConverter.DecodeText(value.Items[1].Text).Trim('"') != "#") scale = Utilites.Entry2Double(value.Items[1], context); + + + const string progID = "AutoCAD.Application"; + AcadApplication acApp = null; + + try + { + acApp = (AcadApplication)Marshal.GetActiveObject(progID); + } + catch + { + answer.AddRange(TermsConverter.ToTerms("\"AutoCAD не запущен\"")); + + result = Entry.Create(answer.ToArray()); + return true; + } + if (acApp != null) + { + // By the time this is reached AutoCAD is fully + // functional and can be interacted with through code + acApp.Visible = true; + AcadModelSpace ms = null; + try + { + ms = acApp.ActiveDocument.ModelSpace; + List points = new List(); + if (lay == "#") + { + for (int i = 0; i < ms.Count; i++) + { + if (ms.Item(i).ObjectName == "AcDbPoint") points.Add(ms.Item(i) as AcadPoint); + } + } + else + { + for (int i = 0; i < ms.Count; i++) + { + if (ms.Item(i).ObjectName == "AcDbPoint" && ms.Item(i).Layer == lay) points.Add(ms.Item(i) as AcadPoint); + } + } + if (points.Count == 0) + { + answer.AddRange(TermsConverter.ToTerms("\"Документ не содержит ни одной точки на заданном слое\"")); + result = Entry.Create(answer.ToArray()); + return true; + } + else + { + int pc = points.Count; + for (int i = 0; i < pc; i++) + { + AcadPoint p = points[i]; + double[]cen= (double[])p.Coordinates; + answer.AddRange(new TNumber(cen[0] * scale).obj.ToTerms()); + answer.AddRange(new TNumber(cen[1] * scale).obj.ToTerms()); + answer.AddRange(new TNumber(cen[2] * scale).obj.ToTerms()); + } + answer.AddRange(TermsConverter.ToTerms(pc.ToString())); + answer.AddRange(TermsConverter.ToTerms(3.ToString())); + answer.Add(new Term(Functions.Mat, TermType.Function, 2 + pc * 3)); + + result = Entry.Create(answer.ToArray()); + return true; + } + } + catch + { + answer.AddRange(TermsConverter.ToTerms("\"Нет ни одного открытого документа AutoCAD\"")); + + result = Entry.Create(answer.ToArray()); + return true; + } + } + } + + //GetAcTextes + if (value.Type == TermType.Function && value.Text == "GetAcTextes") + { + List answer = new List(); + + string lay = "#"; + double scale = 1; + if (TermsConverter.DecodeText(value.Items[0].Text).Trim('"') != "#") lay = TermsConverter.DecodeText(value.Items[0].Text).Trim('"'); + if (TermsConverter.DecodeText(value.Items[1].Text).Trim('"') != "#") scale = Utilites.Entry2Double(value.Items[1], context); + + + const string progID = "AutoCAD.Application"; + AcadApplication acApp = null; + + try + { + acApp = (AcadApplication)Marshal.GetActiveObject(progID); + } + catch + { + answer.AddRange(TermsConverter.ToTerms("\"AutoCAD не запущен\"")); + + result = Entry.Create(answer.ToArray()); + return true; + } + if (acApp != null) + { + // By the time this is reached AutoCAD is fully + // functional and can be interacted with through code + acApp.Visible = true; + AcadModelSpace ms = null; + try + { + ms = acApp.ActiveDocument.ModelSpace; + List points = new List(); + if (lay == "#") + { + for (int i = 0; i < ms.Count; i++) + { + if (ms.Item(i).ObjectName == "AcDbText") points.Add(ms.Item(i) as AcadText); + } + } + else + { + for (int i = 0; i < ms.Count; i++) + { + if (ms.Item(i).ObjectName == "AcDbText" && ms.Item(i).Layer == lay) points.Add(ms.Item(i) as AcadText); + } + } + if (points.Count == 0) + { + answer.AddRange(TermsConverter.ToTerms("\"Документ не содержит ни одного текста на заданном слое\"")); + result = Entry.Create(answer.ToArray()); + return true; + } + else + { + int pc = points.Count; + for (int i = 0; i < pc; i++) + { + AcadText p = points[i]; + double[]cen= (double[])p.InsertionPoint; + answer.AddRange(new TNumber(cen[0] * scale).obj.ToTerms()); + answer.AddRange(new TNumber(cen[1] * scale).obj.ToTerms()); + answer.AddRange(TermsConverter.ToTerms("\"" + p.TextString + "\"")); + } + answer.AddRange(TermsConverter.ToTerms(pc.ToString())); + answer.AddRange(TermsConverter.ToTerms(3.ToString())); + answer.Add(new Term(Functions.Mat, TermType.Function, 2 + pc * 3)); + + result = Entry.Create(answer.ToArray()); + return true; + } + } + catch + { + answer.AddRange(TermsConverter.ToTerms("\"Нет ни одного открытого документа AutoCAD\"")); + + result = Entry.Create(answer.ToArray()); + return true; + } + } + } + + //GetAcLines + if (value.Type == TermType.Function && value.Text == "GetAcLines") + { + List answer = new List(); + + string lay = "#"; + double scale = 1; + if (TermsConverter.DecodeText(value.Items[0].Text).Trim('"') != "#") lay = TermsConverter.DecodeText(value.Items[0].Text).Trim('"'); + if (TermsConverter.DecodeText(value.Items[1].Text).Trim('"') != "#") scale = Utilites.Entry2Double(value.Items[1], context); + + + const string progID = "AutoCAD.Application"; + AcadApplication acApp = null; + + try + { + acApp = (AcadApplication)Marshal.GetActiveObject(progID); + } + catch + { + answer.AddRange(TermsConverter.ToTerms("\"AutoCAD не запущен\"")); + + result = Entry.Create(answer.ToArray()); + return true; + } + if (acApp != null) + { + // By the time this is reached AutoCAD is fully + // functional and can be interacted with through code + acApp.Visible = true; + AcadModelSpace ms = null; + try + { + ms = acApp.ActiveDocument.ModelSpace; + List points = new List(); + if (lay == "#") + { + for (int i = 0; i < ms.Count; i++) + { + if (ms.Item(i).ObjectName == "AcDbLine") points.Add(ms.Item(i) as AcadLine); + } + } + else + { + for (int i = 0; i < ms.Count; i++) + { + if (ms.Item(i).ObjectName == "AcDbLine" && ms.Item(i).Layer == lay) points.Add(ms.Item(i) as AcadLine); + } + } + if (points.Count == 0) + { + answer.AddRange(TermsConverter.ToTerms("\"Документ не содержит ни одного отрезка на заданном слое\"")); + result = Entry.Create(answer.ToArray()); + return true; + } + else + { + int pc = points.Count; + for (int i = 0; i < pc; i++) + { + AcadLine p = points[i]; + double[]sp= (double[])p.StartPoint; + double[]ep= (double[])p.EndPoint; + double len = p.Length; + answer.AddRange(new TNumber(sp[0] * scale).obj.ToTerms()); + answer.AddRange(new TNumber(sp[1] * scale).obj.ToTerms()); + answer.AddRange(new TNumber(ep[0] * scale).obj.ToTerms()); + answer.AddRange(new TNumber(ep[1] * scale).obj.ToTerms()); + answer.AddRange(new TNumber(len * scale).obj.ToTerms()); + } + answer.AddRange(TermsConverter.ToTerms(pc.ToString())); + answer.AddRange(TermsConverter.ToTerms(5.ToString())); + answer.Add(new Term(Functions.Mat, TermType.Function, 2 + pc * 5)); + + result = Entry.Create(answer.ToArray()); + return true; + } + } + catch + { + answer.AddRange(TermsConverter.ToTerms("\"Нет ни одного открытого документа AutoCAD\"")); + + result = Entry.Create(answer.ToArray()); + return true; + } + } + } result = null;