明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2061|回复: 4

为什么注记文字加不上?这段代码不对吗?

[复制链接]
发表于 2009-8-17 14:16:00 | 显示全部楼层 |阅读模式
        private void MakeAcDbText(AttributeReference obj, BlockReference objBLK)
        {
            Autodesk.AutoCAD.DatabaseServices.Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            Autodesk.AutoCAD.DatabaseServices.Transaction ta = tm.StartTransaction();
            try
            {
                BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, false);
                Autodesk.AutoCAD.DatabaseServices.DBText newText = new DBText();
                newText.TextString = obj.TextString;
                newText.TextStyle = obj.TextStyle;
                newText.Position = obj.Position;
                btr.AppendEntity((Entity)newText);
                tm.AddNewlyCreatedDBObject((Entity)newText, true);
                ta.Commit();
            }
            catch
            {
                FileStream fs = new FileStream("提示.txt", FileMode.Append);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(objBLK.BlockName.ToString());
                sw.WriteLine(objBLK.Name.ToString());
                sw.WriteLine(objBLK.Layer.ToString());
                sw.Close();
                fs.Close();
            }
            finally
            {
                ta.Dispose();
            }
        }

发表于 2009-8-17 15:08:00 | 显示全部楼层
自动桌子的代码,有看[url=http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html]http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html[/url]
么?
同一内容最好不要重开贴:)
  1. using Autodesk.AutoCAD.Runtime;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.Geometry;
  5.   
  6. [CommandMethod("CreateText")]
  7. public static void CreateText()
  8. {
  9.   // Get the current document and database
  10.   Document acDoc = Application.DocumentManager.MdiActiveDocument;
  11.   Database acCurDb = acDoc.Database;
  12.   
  13.   // Start a transaction
  14.   using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  15.   {
  16.       // Open the Block table for read
  17.       BlockTable acBlkTbl;
  18.       acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
  19.                                    OpenMode.ForRead) as BlockTable;
  20.   
  21.       // Open the Block table record Model space for write
  22.       BlockTableRecord acBlkTblRec;
  23.       acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
  24.                                       OpenMode.ForWrite) as BlockTableRecord;
  25.   
  26.       // Create a single-line text object
  27.       DBText acText = new DBText();
  28.       acText.SetDatabaseDefaults();
  29.       acText.Position = new Point3d(2, 2, 0);
  30.       acText.Height = 0.5;
  31.       acText.TextString = "Hello, World.";
  32.   
  33.       acBlkTblRec.AppendEntity(acText);
  34.       acTrans.AddNewlyCreatedDBObject(acText, true);
  35.   
  36.       // Save the changes and dispose of the transaction
  37.       acTrans.Commit();
  38.   }
  39. }
 楼主| 发表于 2009-8-18 08:48:00 | 显示全部楼层
搞定,不过一些细节还没弄清楚,比如对齐方式、什么时候要给AlignmentPoint等等,还是谢谢几位
发表于 2009-8-18 11:24:00 | 显示全部楼层

默认的左对齐设置Postion

其余的设置AlignmentPoint

具体的要仔细调试下

AlignmentPoint通常在设置对齐方式后设置

 楼主| 发表于 2009-8-19 13:32:00 | 显示全部楼层
谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-29 09:58 , Processed in 0.184813 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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