明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1169|回复: 2

[基础] 求助,文字插入问题

[复制链接]
发表于 2014-3-29 20:36 | 显示全部楼层 |阅读模式
现在需要在一个三维的模型中插入文字说明,有些需要在侧视图中插入,有些需要在后视图中插入……。反正可能在任何一个视图里面,但程序做好后,在俯视图中可以正确插入,但在别的视图中就不行了,怎么插都在俯视图中,也就是WCS的XY平面。应该怎么解决呢,跪求高手指点。在线等
 楼主| 发表于 2014-3-29 23:06 | 显示全部楼层
真的没人知道吗???
 楼主| 发表于 2014-3-30 00:02 | 显示全部楼层
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autodesk.AutoCAD.ApplicationServices;
  6. using Autodesk.AutoCAD.DatabaseServices;
  7. using Autodesk.AutoCAD.Runtime;
  8. using Autodesk.AutoCAD.EditorInput;
  9. using Autodesk.AutoCAD.Geometry;

  10. namespace UCStext
  11. {
  12.     public class Class1
  13.     {
  14.         [CommandMethod("aa")]
  15.         public void aa()
  16.         {
  17.             Database db = HostApplicationServices.WorkingDatabase;
  18.             Document doc = Application.DocumentManager.MdiActiveDocument;
  19.             PromptPointOptions op = new PromptPointOptions("insert point:");
  20.             PromptPointResult opres = doc.Editor.GetPoint(op);
  21.             Point3d pt = opres.Value;
  22.             Matrix3d mt = doc.Editor.CurrentUserCoordinateSystem;
  23.             DBText ent = new DBText();
  24.             ent.TextString = " 我是中国人";
  25.             ent.Position = pt;
  26.             ent.TransformBy(mt);
  27.             using (Transaction trans = db.TransactionManager.StartTransaction())
  28.             {
  29.                 BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  30.                 BlockTableRecord btrec = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  31.                 btrec.AppendEntity(ent);
  32.                 trans.AddNewlyCreatedDBObject(ent, true);
  33.                 trans.Commit();
  34.             }
  35.         }
  36.     }
  37. }
终于解决了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-2 10:44 , Processed in 0.489169 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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