为什么注记文字加不上?这段代码不对吗?
private void MakeAcDbText(AttributeReference obj, BlockReference objBLK)<br/> {<br/> Autodesk.AutoCAD.DatabaseServices.Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;<br/> Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;<br/> Autodesk.AutoCAD.DatabaseServices.Transaction ta = tm.StartTransaction();<br/> try<br/> {<br/> BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, false);<br/> BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, false);<br/> Autodesk.AutoCAD.DatabaseServices.DBText newText = new DBText();<br/> newText.TextString = obj.TextString;<br/> newText.TextStyle = obj.TextStyle;<br/> newText.Position = obj.Position;<br/> btr.AppendEntity((Entity)newText);<br/> tm.AddNewlyCreatedDBObject((Entity)newText, true);<br/> ta.Commit();<br/> }<br/> catch<br/> {<br/> FileStream fs = new FileStream("提示.txt", FileMode.Append);<br/> StreamWriter sw = new StreamWriter(fs);<br/> sw.WriteLine(objBLK.BlockName.ToString());<br/> sw.WriteLine(objBLK.Name.ToString());<br/> sw.WriteLine(objBLK.Layer.ToString());<br/> sw.Close();<br/> fs.Close();<br/> }<br/> finally<br/> {<br/> ta.Dispose();<br/> }<br/> }<br/><br/> 自动桌子的代码,有看http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html么?
同一内容最好不要重开贴:)
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
public static void CreateText()
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl,
OpenMode.ForWrite) as BlockTableRecord;
// Create a single-line text object
DBText acText = new DBText();
acText.SetDatabaseDefaults();
acText.Position = new Point3d(2, 2, 0);
acText.Height = 0.5;
acText.TextString = "Hello, World.";
acBlkTblRec.AppendEntity(acText);
acTrans.AddNewlyCreatedDBObject(acText, true);
// Save the changes and dispose of the transaction
acTrans.Commit();
}
} 搞定,不过一些细节还没弄清楚,比如对齐方式、什么时候要给AlignmentPoint等等,还是谢谢几位 <p>默认的左对齐设置Postion</p><p>其余的设置AlignmentPoint</p><p>具体的要仔细调试下</p><p>AlignmentPoint通常在设置对齐方式后设置</p> 谢谢
页:
[1]