
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,experts
I have a question,It's about "Block Properties Table",I want to use a Block Properties Table to manage a Dynamic
Block.
I have defiened a Dynamic Block a and its Block Properties Table in Autocad2010,this is the screenshot of the
Block Properties Table(a1:d1=100,d2=200;a2:d1=100,d2=400;a3:d1=100,d2=600.)
Now I want to insert the Dynamic Block using .NET API.after I input a command,the block of a2(d1=100,d2=400)
is inserted.
I have the code about it from Help,but the code is not complete,Can you help me finish the code which can achieve my goal?
Thank you very much!
this is the Dynamic Block
this is the the screenshot of the Block Properties Table
the result:
the code about it from Help:
[CommandMethod("readBlockTable")]
static public void CmdReadBlockTable()
{
Editor ed = Application.DocumentManager.
MdiActiveDocument.Editor;
// select a block reference
PromptEntityOptions peo = new PromptEntityOptions(
"Select a dynamic block reference: ");
peo.SetRejectMessage("Only block reference");
peo.AddAllowedClass(typeof(BlockReference), false);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK) return;
ObjectId blockRefId = per.ObjectId;
// get the database and start a transaction
Database db = Application.DocumentManager.
MdiActiveDocument.Database;
using (Transaction trans = db.
TransactionManager.StartTransaction())
{
// open the dynamic block reference
BlockReference blockRef = trans.GetObject(
blockRefId, OpenMode.ForRead) as BlockReference;
if (!blockRef.IsDynamicBlock) return;
// get the dynamic block table definition
BlockTableRecord blockDef = trans.GetObject(
blockRef.DynamicBlockTableRecord,
OpenMode.ForRead) as BlockTableRecord;
// open the extension dictionary
if (blockDef.ExtensionDictionary.IsNull) return;
DBDictionary extDic = trans.GetObject(
blockDef.ExtensionDictionary, OpenMode.ForRead)
as DBDictionary;
// open the ENHANCEDBLOCK dictionary
Autodesk.AutoCAD.Internal.DatabaseServices.EvalGraph graph =
trans.GetObject(extDic.GetAt("ACAD_ENHANCEDBLOCK"),
OpenMode.ForRead) as EvalGraph;
int[] nodeIds = graph.GetAllNodes();
foreach (uint nodeId in nodeIds)
{
// open the node ID
DBObject node = graph.GetNode(nodeId,
OpenMode.ForRead, trans);
// check is if the correct type
if (!(node is BlockPropertiesTable)) continue;
// convert the object
BlockPropertiesTable table =
node as BlockPropertiesTable;
// ok, we have the data, let's show it...
// get the number of columns
int columns = table.Columns.Count;
int currentRow = 0;
foreach (
BlockPropertiesTableRow row
in table.Rows)
{
currentRow++;
}
}
}
}
Solved! Go to Solution.