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

Command("Erase".. not behaving when run through ExecuteInCommandContextAsync

1 REPLY 1
SOLVED
Reply
Message 1 of 2
h3nrik
377 Views, 1 Reply

Command("Erase".. not behaving when run through ExecuteInCommandContextAsync

Hi

 

I have faced an issue I do not understand,

edit 4 of the post, added more tests ๐Ÿ™‚

edit 5, simplified first method even more.


This method,

 

 

[CommandMethod("testListConvertDxfDwgwithoutList", CommandFlags.Session)]
        public static async void testListConvertDxfDwgwithoutList()
        {
            try
            {
                var promptResult = Application.DocumentManager.MdiActiveDocument.Editor.GetString("\nEnter the parameter: ");
                if (promptResult.Status != PromptStatus.OK)
                {
                    return;
                }

                var path = promptResult.StringResult;

                DocumentCollection acDocMgr = Application.DocumentManager;
                var doc = acDocMgr.Open(path, false);

                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
                await Application.DocumentManager.ExecuteInCommandContextAsync(
                    async (obj) => {
                        await ed.CommandAsync(new object[] { "testConvertDxfDwg" });
                    },
                    null);
                
            } catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.ToString());
            }
        }

 


testConvertDxfDwg

 

    public class testDxfDwg {
        [CommandMethod("testConvertDxfDwg")]
        public void testConvertDxDwg()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            doc.Editor.Command("ERASE", "CROSS", "0,0", "500,500", "");
        }
    }

 

 

If I run test testListConvertDxfDwgwithoutList from a .scr file, like this:

 

 

secureload 0
netload "...."
testListConvertDxfDwg "path to dxf.file"

 

 

Only two object, that are in 0,0 will be erased. Nothing else.

 

If I open the dxf manually,  run this .scr file

 

secureload 0
netload "..."
testConvertDxfDwg

 

 

Erase will work and all 300ish object in the 0,0 - 500,500 area will be erased

 

Edit 4.
I changed the Erase command call to this,

 

doc.Editor.Command("_.ERASE", "CROSS", "-10,-10", "-5,-5", "");

 

When running it through the testListConvert... call, it still selects and erases the two objects that are in 0,0 but if I run it manually, it erases nothing (the expected behavior) How ?

So what am I missing? ๐Ÿ™‚

1 REPLY 1
Message 2 of 2
h3nrik
in reply to: h3nrik

I was missing the fact that I was required to execute a zoom extend before the erase call.

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report