新手:请教使用C#编程如何获取CAD图纸中的线条信息
<p>使用C#编程,如何获取CAD图纸中每种线条的颜色及粗细信息,并且可以使用程序来设置每种颜色线条的粗细?</p><p>或者有没有相应的API提供,谢谢!</p>答案是
<p>获取块表对象,遍历 如果是LINE对象就取出。</p><p>DocumentLock doc=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();<br/> Database db = HostApplicationServices.WorkingDatabase;<br/> using (Transaction trans = db.TransactionManager.StartTransaction())<br/> #region 开始事务<br/> {<br/> BlockTable bt = (BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead);<br/> BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForRead);<br/> foreach (ObjectId id in btr)<br/> #region 遍历图元<br/> {<br/> Autodesk.AutoCAD.DatabaseServices.Entity entity = (Autodesk.AutoCAD.DatabaseServices.Entity)trans.GetObject(id, OpenMode.ForRead);<br/> if (entity is Line)<br/> {<br/> Line line = (Line)entity;<br/> //this.listBox1.Items.Clear();<br/> this.listBox1.Items.Add("找到线" + line.Id.ToString() + ":开始点X:" + line.StartPoint.X.ToString() + " Y:" + line.StartPoint.Y.ToString() + "结束点X:" + line.EndPoint.X.ToString() + " Y:" + line.EndPoint.Y.ToString());<br/> //MessageBox.Show("找到线:开始点X:" +line.StartPoint.X.ToString()+" Y:"+line.StartPoint.Y.ToString()+"结束点X:"+line.EndPoint.X.ToString()+" Y:"+line.EndPoint.Y.ToString());<br/> }<br/> else<br/> {<br/> if (entity is DBText)<br/> {<br/> DBText dbt = (DBText)entity;<br/> this.listBox1.Items.Add("找到文本:" + dbt.Id.ToString() + ":开始点X:" + dbt.Position.X.ToString() + " Y:" + dbt.Position.Y.ToString());<br/> }<br/> MessageBox.Show("抱歉没有找到任何东西!!");<br/> }<br/> }<br/> #endregion<br/> }<br/> #endregion</p>
页:
[1]