public async Task <object> StartCAD(dynamic input) { try { GetAutoCAD(); } catch (COMException cx) { try { StartAutoCad(); } catch (Exception ex) { return(ex.Message); } } AcadModelSpace model = app.ActiveDocument.Database.ModelSpace; List <string> tmp = new List <string> { }; foreach (dynamic t in model) { tmp.Add(t.Layer); } dynamic rec = app.ActiveDocument.Database.ModelSpace.Count; return(tmp); }
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(); }
internal void FriendQuit() { if (mblnOpened) { mobjDictReadCodes = null; mobjDictReadValues = null; mobjAcadModelSpace = null; mobjAcadDatabase = null; mblnOpened = false; } }
public IList <LandFeatureline> GetLandFeaturelines(string xmlPath = "") { Utils.Log(string.Format("CivilDocument.GetLandFeaturelines started...", "")); if (string.IsNullOrEmpty(xmlPath)) { xmlPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "LandFeatureLinesReport.xml"); } bool result = this.SendCommand("-ExportLandFeatureLinesToXml\n"); IList <LandFeatureline> output = new List <LandFeatureline>(); if (result) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlPath); AcadDatabase db = this._document as AcadDatabase; AcadModelSpace ms = db.ModelSpace; foreach (AcadEntity e in ms) { if (e.EntityName.ToLower().Contains("featureline")) { AeccLandFeatureLine f = e as AeccLandFeatureLine; XmlElement fe = xmlDoc.GetElementsByTagName("FeatureLine").Cast <XmlElement>().First(x => x.Attributes["Name"].Value == f.Name); IList <Point> points = new List <Point>(); foreach (XmlElement p in fe.GetElementsByTagName("Point")) { double x = Convert.ToDouble(p.Attributes["X"].Value); double y = Convert.ToDouble(p.Attributes["Y"].Value); double z = Convert.ToDouble(p.Attributes["Z"].Value); points.Add(Point.ByCoordinates(x, y, z)); } PolyCurve pc = PolyCurve.ByPoints(points); string style = fe.Attributes["Style"].Value; output.Add(new LandFeatureline(f, pc, style)); } } Utils.Log(string.Format("CivilDocument.GetLandFeaturelines completed.", "")); } return(output); }
public void ListSection(ref int rlngIdx) { mobjAcadModelSpace = mobjAcadDatabase.ModelSpace; InternAddToDictLine(ref rlngIdx, 0, "SECTION"); mlngSecBeg = rlngIdx; InternAddToDictLine(ref rlngIdx, 2, "ENTITIES"); if (mobjAcadModelSpace != null) { InternListSection(ref rlngIdx); } mlngSecEnd = rlngIdx; InternAddToDictLine(ref rlngIdx, 0, "ENDSEC"); }
public static void Main(string[] args) { if (args.Length != 0) { arquivos = args; } else { SelectFiles(); } AcadApplication acApp = null; try { acApp = Marshal.GetActiveObject("AutoCAD.Application") as AcadApplication; } catch { MessageBox.Show("Não foi possível abrir o AutoCAD"); } foreach (var desenho in arquivos) { AcadDocument doc; try { doc = acApp.Documents.Open(desenho, false, string.Empty); AcadModelSpace modelSpace = doc.ModelSpace; } catch (Exception ex) { MessageBox.Show("Não foi possível abrir o desenho " + desenho + ex); break; } doc.SendCommand("ELL "); doc.PurgeAll(); doc.PurgeAll(); doc.PurgeAll(); acApp.ZoomExtents(); doc.Save(); doc.Close(); } }
public bool Read(ref string nrstrErrMsg) { nrstrErrMsg = null; mobjAcadModelSpace = mobjAcadDatabase.ModelSpace; checked { bool Read = default(bool); if (mobjAcadModelSpace == null) { nrstrErrMsg = "Kein Modellbereich definiert."; } else { mlngLastEntry = mlngSecBeg - 1; Read = InternReadSection(ref nrstrErrMsg); InternCheckIndex(mlngSecEnd + 2); } return(Read); } }
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 IList <LandFeatureline> GetLandFeaturelines(string xmlPath = "") { Utils.Log(string.Format("CivilDocument.GetLandFeaturelines started...", "")); if (string.IsNullOrEmpty(xmlPath)) { xmlPath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("TMP", EnvironmentVariableTarget.User), "LandFeatureLinesReport.xml"); } this.SendCommand("-ExportLandFeatureLinesToXml\n"); DateTime start = DateTime.Now; while (true) { if (System.IO.File.Exists(xmlPath)) { if (System.IO.File.GetLastWriteTime(xmlPath) > start) { start = System.IO.File.GetLastWriteTime(xmlPath); } else { break; } } } Utils.Log("XML acquired."); bool result = true; IList <LandFeatureline> output = new List <LandFeatureline>(); if (result) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlPath); AcadDatabase db = this._document as AcadDatabase; AcadModelSpace ms = db.ModelSpace; foreach (AcadEntity e in ms) { if (e.EntityName.ToLower().Contains("featureline")) { AeccLandFeatureLine f = e as AeccLandFeatureLine; XmlElement fe = xmlDoc.GetElementsByTagName("FeatureLine").Cast <XmlElement>().First(x => x.Attributes["Handle"].Value == f.Handle.ToString()); IList <Point> points = new List <Point>(); foreach (XmlElement p in fe.GetElementsByTagName("Point")) { double x = Convert.ToDouble(p.Attributes["X"].Value, CultureInfo.InvariantCulture); double y = Convert.ToDouble(p.Attributes["Y"].Value, CultureInfo.InvariantCulture); double z = Convert.ToDouble(p.Attributes["Z"].Value, CultureInfo.InvariantCulture); points.Add(Point.ByCoordinates(x, y, z)); } points = Point.PruneDuplicates(points); if (points.Count > 1) { PolyCurve pc = PolyCurve.ByPoints(points); string style = fe.Attributes["Style"].Value; output.Add(new LandFeatureline(f, pc, style)); } } } Utils.Log(string.Format("CivilDocument.GetLandFeaturelines completed.", "")); } return(output); }