我正在尝试使用我的C#.NET插件在AutoCAD中绘制一个表格,其中包含基于用户填写的.NET表单的信息。我用来尝试此操作的代码基于this page。根据我的计划修改它,代码如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace WindowsDoors.NET
{
class OpeningDataTable : Table
{
private int rowCount = 0;
private static Document doc = Application.DocumentManager.MdiActiveDocument; //Current drawing
private static Database db = doc.Database; //subclass of Document,
private static Editor ed = doc.Editor; //Editor object to ask user where table goes, subclass of Document
public OpeningDataTable(bool isWindow)
{
PromptPointResult pr = ed.GetPoint("\nEnter table insertion point: ");
if (pr.Status == PromptStatus.OK)
{
//Setting information about the table
TableStyle = db.Tablestyle;
SetSize(2, 5);
SetRowHeight(3);
SetColumnWidth(15);
Position = pr.Value;
//Creating titles to add
String[] columnTitles = new String[5];
columnTitles[0] = "Mark";
columnTitles[1] = "Width";
columnTitles[2] = "Height";
columnTitles[3] = "Header\nMaterial";
columnTitles[4] = "Packers\n(Each Side)";
//Adding titles to table
addRow(columnTitles);
}
}
public void addRow(String[] data)
{
// Use a nested loop to format each cell
for (int i = 0; i < data.Length; i++)
{
ParseOption s = new ParseOption();
Cells[rowCount, i].TextHeight = 1;
Cells[rowCount, i].SetValue(data[i], s);
}
GenerateLayout();
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(this);
tr.AddNewlyCreatedDBObject(this, true);
tr.Commit();
}
}
}
}
此问题出现在此行的底部附近
(BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
它说BlockTableRecord没有扩展ModelSpace,即使我采用了我列出的示例。我需要知道是否有办法解决这个问题,或者是否有其他问题被替换。
答案 0 :(得分:1)
我明白了。因为我正在扩展具有字段BlockTableRecord的Table类,所以我必须更具体
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[Autodesk.AutoCAD.DatabaseServices.BlockTableRecord.ModelSpace], OpenMode.ForWrite);