.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

.Net eNotApplicable

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
1123 Views, 2 Replies

.Net eNotApplicable

 

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,

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: Anonymous

You need to set CommandFlags.Session in the CommandMethod attribute, where the code is started, so that the newly opened document would become MdiActiveDocument. Then you need to lock the document when starting a Transition to access DB residing entities.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
Anonymous
in reply to: norman.yuan

Thank you, the Session flag worked perfectly. I did add a "using" statement to lock the document,  enclosing the transaction within it.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


AutoCAD Beta