- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been trying to test the following code.... and it fails when it gets to this "sr = ed.SelectAll(filter)". I think it is because I am opening a Document using the document manager. I've tested the SelectionSet code in another method that works with the Application.DocumentManager.MdiActiveDocument by first opening a drawing in AutoCAD that I know has blocks in it. It works fine, just seems to bomb out when I open a file using DOcumentManage. If I look at the file name for the MdiActiveDocument it isn't the one I opened. I have to have a file open already to be able to use NETLOAD and I suspect that because I issue the command for the code in that document that I need to some how tell the application that I want the newly opened file to be the active document. Just don't know how.
DocumentCollection acDocMgr = Application.DocumentManager;
Document targetDoc = acDocMgr.Open(f, false);
Database db = targetDoc.Database;
Editor ed = targetDoc.Editor;
TypedValue[] tvl = new TypedValue[] { new TypedValue((int)DxfCode.Start, "INSERT") };
SelectionFilter filter = new SelectionFilter(tvl);
PromptSelectionResult sr;
SelectionSet ss;
try
{
ObjectId[] idArray = null;
sr = ed.SelectAll(filter); // < Failes here with eNotApplicable
ss = sr.Value;
idArray = ss.GetObjectIds();
using (Transaction trans = db.TransactionManager.StartTransaction())
{
foreach (ObjectId id in idArray)
{
BlockReference blkRef = trans.GetObject(id, OpenMode.ForRead) as BlockReference;
Debug.Print(blkRef.Name.ToUpper());
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
}
targetDoc.CloseAndDiscard();
Regards,
Solved! Go to Solution.