数据写入autoCAD
怎样把dataGridView数据以表格的形式写入autoCAD,望高手不吝赐教!望能提供点代码供小弟学习,谢谢! 你是想写实体Table呢还是数据字典? 是实体Table 本帖最后由 chmenf087 于 2013-4-2 12:50 编辑using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace TableCreation
{
public class Commands
{
static public void CreateTable()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointResult pr =
ed.GetPoint("\nEnter table insertion point: ");
if (pr.Status == PromptStatus.OK)
{
Table tb = new Table();
tb.TableStyle = db.Tablestyle;
tb.NumRows = 5;
tb.NumColumns = 3;
tb.SetRowHeight(3);
tb.SetColumnWidth(15);
tb.Position = pr.Value;
// Create a 2-dimensional array
// of our table contents
string[,] str = new string;
str = "Part No.";
str = "Name ";
str = "Material ";
str = "1876-1";
str = "Flange";
str = "Perspex";
str = "0985-4";
str = "Bolt";
str = "Steel";
str = "3476-K";
str = "Tile";
str = "Ceramic";
str = "8734-3";
str = "Kean";
str = "Mostly water";
// Use a nested loop to add and format each cell
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
tb.SetTextHeight(i, j, 1);
tb.SetTextString(i, j, str);
tb.SetAlignment(i, j, CellAlignment.MiddleCenter);
}
}
tb.GenerateLayout();
Transaction tr =
doc.TransactionManager.StartTransaction();
using (tr)
{
BlockTable bt =
(BlockTable)tr.GetObject(
doc.Database.BlockTableId,
OpenMode.ForRead
);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
bt,
OpenMode.ForWrite
);
btr.AppendEntity(tb);
tr.AddNewlyCreatedDBObject(tb, true);
tr.Commit();
}
}
}
}
}稍加修改就可以了(遍历一下DatagrideView)
这些本版内都有的(我只是复制粘贴而已) chmenf087 发表于 2013-4-2 12:49 static/image/common/back.gif
稍加修改就可以了(遍历一下DatagrideView)
这些本版内都有的(我只是复制粘贴而已)
谢了
页:
[1]