乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 19|回复: 0

在修改一条直线的线型类型,修改后,还是一条直线,求高手帮忙看看

[复制链接]

6

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
33
发表于 2014-2-28 12:04:00 | 显示全部楼层 |阅读模式
下列代码是想实现 先删除一条直线再画一条包含文本的复杂线型 的直线,可是代码执行后还是一条直线没有显示包含文本的复杂AutoCAD线型  ,求高手看看
private void btn_addlinetype_Click(object sender, EventArgs e)
        {
            try
            {
                if (txt_LineContent.Text != "")
                {
                    MessageBox.Show("请在AutoCAD2010 中选择要修改的线段,选择完成后请单击---鼠标右键---返回界面", "选择线段", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.WindowState = FormWindowState.Minimized;//  goto跳回语句
                    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
                    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                    Database db = doc.Database;
                    DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
                    using (Transaction trans = doc.TransactionManager.StartTransaction())
                    {
                    Loop: PromptSelectionResult psr = ed.GetSelection();
                        if (psr.Status == PromptStatus.OK)
                        {
                            if (MessageBox.Show("是否确定选择线段?是 表示确定,否 表示重新选择!", "选择提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                            {
                                goto Loop;//goto跳回到选择点
                            }
                            if (psr.Value.Count == 1)
                            {
                                foreach (ObjectId GetSelectId in psr.Value.GetObjectIds())
                                {
                                    Entity ent = trans.GetObject(GetSelectId, OpenMode.ForWrite) as Entity;
                                    string TypeName = ent.GetType().Name.ToString();
                                    if (TypeName == "Line")
                                    {
                                        Line ln = ent as Line;
                                        StartPoint = ln.StartPoint;
                                        EndPoint = ln.EndPoint;
                                        ent.Erase();
                                        ed.UpdateScreen();
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("不能选择多条线段或者不选,只能选择一条,请重新选择", "选择线段", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                ed.UpdateScreen();
                                goto Loop;//goto跳回到选择点
                            }
                        }
                        trans.Commit();
                        ed.UpdateScreen();
                        //ObjectId ltId = m_LoadLineTypeName(ed, "ZIGZAG");
                        CreateComplexLinetype(doc, ed);
                        this.Show();
                    }
                    docLock.Dispose();
                }
                else
                {
                    MessageBox.Show("线型内容不能为空,请输入内容!", "输入线型内容", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txt_LineContent.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        Point3d StartPoint=new Point3d();
        Point3d EndPoint = new Point3d();
        public void CreateComplexLinetype(Document doc, Editor ed)
        {
            try
            {
                Database db = doc.Database;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    // 我们使用文本样式表来访问"Standard"文本样式,用于文本部分
                    TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                    // 获取线型表
                    LinetypeTable lt = (LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForWrite, true);
                    // 创建新的线型表记录...
                    LinetypeTableRecord ltr = new LinetypeTableRecord();
                    // ... 设置线型表记录的属性
                    ltr.Name = "COLD_WATER_SUPPLY";
                    ltr.AsciiDescription =
                      "Cold water supply ---- RS ---- RS ---- RS ----";
                    ltr.PatternLength = 0.9;
                    ltr.NumDashes = 3;
                    // 短划线 #1
                    ltr.SetDashLengthAt(0, 0.5);
                    // 短划线 #2
                    ltr.SetDashLengthAt(1, -0.2);
                    ltr.SetShapeStyleAt(1, tt["Standard"]);
                    ltr.SetShapeNumberAt(1, 0);
                    ltr.SetShapeOffsetAt(1, new Vector2d(-0.1, -0.05));
                    ltr.SetShapeScaleAt(1, 0.1);
                    ltr.SetShapeIsUcsOrientedAt(1, false);
                    ltr.SetShapeRotationAt(1, 0);
                    ltr.SetTextAt(1, "RS");
                    // 短划线 #3
                    ltr.SetDashLengthAt(2, -0.2);
                    // 把新线型添加到线型表
                    ObjectId ltId = lt.Add(ltr);
                    tr.AddNewlyCreatedDBObject(ltr, true);
                    // 使用这个线型创建一条测试直线
                    BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                    Line line = new Line(StartPoint,EndPoint);
                    line.SetDatabaseDefaults(db);
                    line.LinetypeId = ltId;
                    btr.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    tr.Commit();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 23:40 , Processed in 0.359872 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表