Got the selection working. This was what I wanted to do:
public void selectBlock2(string blockName)
{
Database db = HostApplicationServices.WorkingDatabase;
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
TypedValue[] tvs = new TypedValue[] {
new TypedValue(0, "INSERT"),
new TypedValue(2, blockName)
};
SelectionFilter sf = new SelectionFilter(tvs);
PromptSelectionResult psr = ed.SelectAll(sf);
if (psr.Status == PromptStatus.OK)
{
ed.SetImpliedSelection(psr.Value.GetObjectIds());
}
}
But the block-explosion is still not working. I tried it like this:
public void explodeBlock(string blockName)
{
Editor ed = doc.Editor;
using (tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false, true);
if (bt.Has(blockName)) {
ObjectId btrid = bt[blockName];
if (!btrid.IsEffectivelyErased) {
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrid, OpenMode.ForRead, false, true);
ObjectIdCollection brefIds = btr.GetBlockReferenceIds(true, false);
foreach (ObjectId objid in brefIds) {
BlockReference br = (BlockReference)tr.GetObject(objid, OpenMode.ForWrite);
br.ExplodeToOwnerSpace();
}
}
}
}
}
The last function I should implement is a Copy/Paste-Block function. For paste there should be a cursor to set the insertpoint for the block (like the usual insert in AutoCAD). How complex would this be?
Greets
Klaus