/// <summary> Выбор примитивов на экране </summary> /// <param name="autoCADPrimitivesName"> Имя приметива </param> /// <returns> Список приметивов </returns> public static List <AcadEntity> OnScreen(string autoCADPrimitivesName) { var acadDocument = DocumentLocator.GetAcadDocument(); // Установка пространства модели acadDocument.ActiveSpace = AcActiveSpace.acModelSpace; AcadSelectionSet selectionSet = acadDocument.SelectionSets.Add(DateTime.Now.Millisecond.ToString()); Int16[] filterCode = new Int16[] { 0 }; object[] filterValue = new object[] { autoCADPrimitivesName }; selectionSet.SelectOnScreen(filterCode, filterValue); var listOfEntities = new List <AcadEntity>(); Debug.WriteLine($"Из AutoCADa заполучено ${selectionSet.Count} объектов"); foreach (AcadEntity entity in selectionSet) { listOfEntities.Add(entity); } selectionSet.Delete(); return(listOfEntities); }
public static void Test() { AcadApplication AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.22"); AcadDocument doc = AcadApp.ActiveDocument; AcadModelSpace ms = doc.ModelSpace; AcadSelectionSets SelSets = doc.SelectionSets; //SelSets. AcadSelectionSet sles = SelSets.Add("Ssd"); sles.SelectOnScreen(); Console.WriteLine("{0}", sles.Count); List <AcadLWPolyline> curList = new List <AcadLWPolyline>(); foreach (var item in sles) { try { AcadLWPolyline PL = (AcadLWPolyline)item; if (PL.Closed) { curList.Add(PL); } } catch (Exception) { continue; } // Console.WriteLine("Length={0}", L.Length); } sles.Delete(); }
/// <summary> /// Agregar nueva selección al documento actual. /// </summary> /// <param name="SelectionS">Selección a agregar.</param> public static object AddSelection(string SelectionS) { AcadSelectionSet Selection = null; if (AcadDoc != null) { DeleteESelec(SelectionS); AcadDoc.PurgeAll(); Selection = AcadDoc.SelectionSets.Add(SelectionS); Selection.SelectOnScreen(); } return(Selection); }
public static void GetSelection(out AcadSelectionSet curSelection) { AcadApplication AcadApp = null; AcadDocument doc = null; AcadSelectionSets SelSets = null; curSelection = null; try { Console.WriteLine("正在连接CAD2018...成功"); AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.22"); doc = AcadApp.ActiveDocument; SelSets = doc.SelectionSets; Console.WriteLine("选择内容..."); } catch (Exception) { Console.WriteLine("无法连接AutoCAD..."); return; } try { curSelection = SelSets.Add("NewSelection"); } catch (Exception) { var item = from AcadSelectionSet a in SelSets where a.Name == "NewSelection" select a; curSelection = item.First(); } finally { curSelection.Clear(); } curSelection.SelectOnScreen(); Console.WriteLine("共选择{0}个对象。", curSelection.Count); }
public static void Test() { AcadApplication AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.19"); AcadDocument doc = AcadApp.ActiveDocument; AcadModelSpace ms = doc.ModelSpace; AcadSelectionSets SelSets = doc.SelectionSets; //SelSets. Console.WriteLine("请Tony选择中心线."); AcadSelectionSet cl = SelSets.Add(new Random().Next(1000, 9999).ToString()); cl.Clear(); cl.SelectOnScreen(); Console.WriteLine("中心线选择完成."); Console.WriteLine("请Tony选择预应力筋."); AcadSelectionSet preBars = SelSets.Add(new Random().Next(1000, 9999).ToString()); preBars.Clear(); preBars.SelectOnScreen(); Console.WriteLine("预应力钢筋选择完成,共计{0}根.", preBars.Count); Console.WriteLine("请Tony选择方向线."); AcadSelectionSet dirL = SelSets.Add(new Random().Next(1000, 9999).ToString()); dirL.Clear(); dirL.SelectOnScreen(); List <AcadLine> NewDirLSet = new List <AcadLine>(); foreach (var item in dirL) { AcadLine DirLine = (AcadLine)item; NewDirLSet.Add(DirLine); } NewDirLSet.Sort((x, y) => x.GetMidX().CompareTo(y.GetMidX())); Console.WriteLine("预应力钢筋选择完成,共计{0}根.", dirL.Count); AcadLWPolyline CLine = (AcadLWPolyline)cl.Item(0); FileStream fs = new FileStream("D:\\TonyReadMe.csv", FileMode.Create); StreamWriter sw = new StreamWriter(fs); foreach (var bar in preBars) { sw.Flush(); sw.Write("\n{0},", bar.ToString()); //Console.WriteLine(bar.ToString()); AcadLWPolyline PL = (AcadLWPolyline)bar; foreach (var item in NewDirLSet) { double[] p1, p2; double dist; try { AcadLine DirLine = item; p1 = DirLine.IntersectWith(CLine, AcExtendOption.acExtendThisEntity); p2 = DirLine.IntersectWith(PL, AcExtendOption.acExtendThisEntity); if (p1.Count() == 0 || p2.Count() == 0) { continue; } dist = Math.Pow((p1[0] - p2[0]), 2) + Math.Pow((p1[1] - p2[1]), 2) + Math.Pow((p1[2] - p2[2]), 2); dist = Math.Sqrt(dist); int fx = p1[1] < p2[1] ? 1 : -1; //Console.Write("{0:F0},",dist); sw.Write("{0:F0},", fx * dist * 1000.0); } catch (Exception) { throw; } } // Console.WriteLine("Length={0}", L.Length); } cl.Delete(); preBars.Delete(); dirL.Delete(); sw.Close(); fs.Close(); }
public void GetSection() { AcadApplication AcadApp = null; AcadDocument doc = null; AcadSelectionSets SelSets = null; AcadSelectionSet curSelection = null; InnerLines.Clear(); try { #if R22 Console.WriteLine("正在连接CAD2018...成功"); AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.22"); #elif R20 Console.WriteLine("正在连接CAD2016...成功"); AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.20"); #elif R19 Console.WriteLine("正在连接CAD2014...成功"); AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.19"); #elif R18 Console.WriteLine("正在连接CAD2010...成功"); AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.18"); #endif doc = AcadApp.ActiveDocument; SelSets = doc.SelectionSets; Console.WriteLine("选择截面..."); } catch (Exception) { Console.WriteLine("无法连接AutoCAD..."); return; } try { curSelection = SelSets.Add("GetPLs"); } catch (Exception) { var item = from AcadSelectionSet a in SelSets where a.Name == "GetPLs" select a; curSelection = item.First(); } finally { curSelection.Clear(); } curSelection.SelectOnScreen(); Console.WriteLine("共选择{0}个对象。", curSelection.Count); Globals.LogBox.AppendText(string.Format("共选择{0}个对象。", curSelection.Count)); var PLs = from AcadEntity a in curSelection where a.EntityType == 24 select a as AcadLWPolyline; var Acs = from AcadLWPolyline a in PLs select a.Area; double AcMax = Acs.Max(); foreach (AcadLWPolyline item in PLs) { if (item.Area == AcMax) { OuterLine = item.Polygen2D(); } else { InnerLines.Add(item.Polygen2D()); } } var bars = from AcadEntity a in curSelection where a.EntityType == 8 select a as AcadCircle; foreach (AcadCircle item in bars) { ComRebars.Add(item.Circle2D()); } Console.WriteLine("共拾取1个外边界,{0}个内边界,{1}根钢筋...", InnerLines.Count, ComRebars.Count); Xstrip = GetStrip(ref OuterLine, ref InnerLines, true); Ystrip = GetStrip(ref OuterLine, ref InnerLines, false); xs = (from a in Xstrip select a[0]).ToList(); ys = (from a in Ystrip select a[0]).ToList(); dx = xs[1] - xs[0]; dy = ys.ElementAt(1) - ys.ElementAt(0); Axs = (from a in Xstrip select a[1] * dx).ToList(); Ays = (from a in Ystrip select a[1] * dy).ToList(); }