代码:
public partial class BlockLookingForm : Form {
public Document docu; Database DB;
BlockTable blockTable;
public BlockLookingForm(Document docu, Database DB, BlockTable blockTable) {
InitializeComponent(); this.docu = docu; this.DB = DB;
this.blockTable = blockTable; }
private void btnLooking_Click(object sender, EventArgs e) {Database database = docu.Database; try
{using (Transaction trans =
database.TransactionManager.StartTransaction()) {
blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord blockTableRecord =
trans.GetObject(blockTable[txtBlockName.Text.Trim()], OpenMode.ForRead) as BlockTableRecord;
int Count = 0;
foreach (ObjectId id in blockTableRecord)
{Entity entity = trans.GetObject(id, OpenMode.ForRead, false) as Entity;
if (entity is AttributeDefinition) {
txtAttri.Text = \有\; }
Count++; }
txtEntity.Text = Count.ToString();
Bitmap bitmap = blockTableRecord.PreviewIcon; if (bitmap != null) {
System.Drawing.Image image = System.Drawing.Image.FromHbitmap(bitmap.GetHbitmap()); pictureBox1.Image = image; pictureBox1.Refresh(); }
trans.Commit(); } }
catch (Exception ex) {
MessageBox.Show(\有错误\+ex.Message); }
5.3、在创建块表命令方法中添加下面的代码:
CreateBlockIcon createBlockIcon = new CreateBlockIcon(blockName);
5.4、然后在命令方法中显示块表查看器
四、实验总结
通过实验,使我更加懂得了自己动手的重要性,在课堂上虽然听懂了老师讲的内容,但在实际编程过程中还是会出现许多的问题,只有通过自己亲身去实践,这样才是真正的学到了属于自己的东西。