Пример #1
0
        public static void TestCallback()
        {
            _Count = 0;

            var ed = Application.DocumentManager.MdiActiveDocument.Editor;

            // start Line command, the first line
            Editor.CommandResult cmdResult1 = ed.CommandAsync(new object[] { "_.LINE", Editor.PauseToken, Editor.PauseToken });

            // delegate callback function, wait for interaction ends
            _actionCompletedDelegate = new Del(CreateLinesAsyncCallback);
            cmdResult1.OnCompleted(new Action(_actionCompletedDelegate));
        }
Пример #2
0
        // callback function
        public static void CreateLinesAsyncCallback()
        {
            // AutoCAD hands over to the callback function
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;

            //if Line command is running
            if (isLineActive())
            {
                if (_Count == 0)
                {
                    // get the first line ID
                    PromptSelectionResult LastEnt = ed.SelectLast();
                    oIdArray.Add(LastEnt.Value[0].ObjectId);

                    // increase count
                    _Count++;

                    // hand over to AutoCAD to execute the next interaction
                    Editor.CommandResult cmdResult = ed.CommandAsync(Editor.PauseToken);
                    // delegate callback function, wait for interaction ends
                    _actionCompletedDelegate = new Del(CreateLinesAsyncCallback);
                    cmdResult.OnCompleted(new Action(_actionCompletedDelegate));
                }
                else if (_Count == 1)
                {
                    // get the second line ID
                    PromptSelectionResult LastEnt = ed.SelectLast();
                    oIdArray.Add(LastEnt.Value[0].ObjectId);

                    // increase count
                    _Count++;

                    // hand over to AutoCAD to execute the next interaction
                    Editor.CommandResult cmdResult = ed.CommandAsync(Editor.PauseToken);
                    // delegate callback function, wait for interaction ends
                    _actionCompletedDelegate = new Del(CreateLinesAsyncCallback);
                    cmdResult.OnCompleted(new Action(_actionCompletedDelegate));
                }
            }
            else
            {
                //the end user ends the send command
                // display each id of the line
                foreach (ObjectId eachId in oIdArray)
                {
                    ed.WriteMessage("\nline object ID: {0}", eachId.ToString());
                }
            }
        }