明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1913|回复: 1

新手:请教使用C#编程如何获取CAD图纸中的线条信息

[复制链接]
发表于 2008-4-10 11:21:00 | 显示全部楼层 |阅读模式

使用C#编程,如何获取CAD图纸中每种线条的颜色及粗细信息,并且可以使用程序来设置每种颜色线条的粗细?

或者有没有相应的API提供,谢谢!

发表于 2008-4-28 10:32:00 | 显示全部楼层

答案是

获取块表对象,遍历 如果是LINE对象就取出。

DocumentLock doc=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            #region  开始事务
            {
                BlockTable bt = (BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
                foreach (ObjectId id in btr)
                #region  遍历图元
                {
                    Autodesk.AutoCAD.DatabaseServices.Entity entity = (Autodesk.AutoCAD.DatabaseServices.Entity)trans.GetObject(id, OpenMode.ForRead);
                    if (entity is Line)
                    {
                        Line line = (Line)entity;
                        //this.listBox1.Items.Clear();
                        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());
                        //MessageBox.Show("找到线:开始点X:" +line.StartPoint.X.ToString()+" Y:"+line.StartPoint.Y.ToString()+"结束点X:"+line.EndPoint.X.ToString()+" Y:"+line.EndPoint.Y.ToString());
                    }
                    else
                    {
                        if (entity is DBText)
                        {
                            DBText dbt = (DBText)entity;
                            this.listBox1.Items.Add("找到文本:" + dbt.Id.ToString() + ":开始点X:" + dbt.Position.X.ToString() + "  Y:" + dbt.Position.Y.ToString());
                        }
                        MessageBox.Show("抱歉没有找到任何东西!!");
                    }
                }
                #endregion
            }
            #endregion

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 15:00 , Processed in 0.177199 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表