iCAx开思工具箱
标题:
读取带属性块的属性??
[打印本页]
作者:
zy19860604
时间:
2011-10-21 08:59
标题:
读取带属性块的属性??
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
namespace MyApplication
{
class DumpAttributes
{
[CommandMethod("LISTATT")]
public void ListAttributes()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
try
{
TypedValue[] filList = new TypedValue[1];
filList[0] = new TypedValue((int)DxfCode.Start, "Insert");
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionOptions opts = new PromptSelectionOptions();
opts.MessageForAdding = "Select block references:";
PromptSelectionResult res = ed.GetSelection(opts, filter);
if (res.Status != PromptStatus.OK)
{
return;
}
SelectionSet selSet = res.Value;
ObjectId[] idArray = selSet.GetObjectIds();
foreach (ObjectId blkId in idArray)
{
BlockReference blkRef = (BlockReference)trans.GetObject(blkId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead);
ed.WriteMessage("\nBlock:" + btr.Name);
btr.Dispose();
AttributeCollection attCol = blkRef.AttributeCollection;
foreach (ObjectId attId in attCol)
{
AttributeReference attRef = (AttributeReference)trans.GetObject(attId, OpenMode.ForRead);
string str = ("\n Attribute Tag:" + attRef.Tag + "\n Attribute String" + attRef.TextString);
ed.WriteMessage(str);
trans.Commit();
}
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage(ex.Message);
}
finally
{
trans.Dispose();
}
}
}
}
AttributeCollection attCol = blkRef.AttributeCollection;
对象的当前状态使该操作无效。为什麽??
欢迎光临 iCAx开思工具箱 (https://t.icax.org/)
Powered by Discuz! X3.3