Author Topic: Button Control Event  (Read 3972 times)

0 Members and 2 Guests are viewing this topic.

HD

  • Guest
Button Control Event
« on: September 06, 2008, 10:12:29 PM »
The button control event code below is work in progress. What is happenning is after returning to my main form, the "Insertion Point" prompt remains as the AutoCAD command-line prompt.

Am I doing something wrong or is there some way to clear the command-line prompt prior to returning to my main form?

Just for the heck of it, I placed the code, minus a couple of statements, into a CommandMethod and it works fine.

Code: [Select]
private void btnInsertion_Click(object sender, EventArgs e)
{
    Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;

    this.Hide();

    PromptPointOptions options =
        new PromptPointOptions("Insertion Point");

    PromptPointResult result = ed.GetPoint(options);
    if (result.Status != PromptStatus.OK)
        return;

    this.Show();

    Point3d insertionPoint = result.Value;
}

Glenn R

  • Guest
Re: Button Control Event
« Reply #1 on: September 07, 2008, 06:11:06 AM »
Try knocking out the Hide() and Show() function calls and see what happens...

sinc

  • Guest
Re: Button Control Event
« Reply #2 on: September 08, 2008, 09:01:12 PM »
What happens if you simply print "\nCommand: " to the command window using Editor.WriteMessage(), just before your button handler ends?

sinc

  • Guest
Re: Button Control Event
« Reply #3 on: September 08, 2008, 11:58:31 PM »
Ah, the Swamp gives better answers than ADN.   :-D

Spike Wilbury

  • Guest
Re: Button Control Event
« Reply #4 on: September 09, 2008, 12:25:49 AM »
I have done something like this:

Code: [Select]
        [DllImport("user32.dll")]
        public static extern System.IntPtr SetFocus(System.IntPtr hwnd);

        // modeless form
        private void onClick_InstallDoor(object sender, EventArgs e)
        {
            str_doorwidth = doorWidths_comboBox.GetItemText(doorWidths_comboBox.Items[doorWidthsIndex]);
            str_doorname = doorNames_comboBox.GetItemText(doorNames_comboBox.Items[doorNamesIndex]);
            str_doortype = doorTypes_comboBox.GetItemText(doorTypes_comboBox.Items[doorTypesIndex]);
            str_doorframe = doorFrames_comboBox.GetItemText(doorFrames_comboBox.Items[doorFramesIndex]);
            str_doorposition = doorWallPositions_comboBox.GetItemText(doorWallPositions_comboBox.Items[doorWallPositionsIndex]);

            str_distanceCorner = editDistanceCorner.Text;
            double d_distCorner = Converter.StringToDistance(str_distanceCorner, DistanceUnitFormat.Architectural);
            editDistanceCorner.Text = Converter.DistanceToString(d_distCorner, DistanceUnitFormat.Architectural, -1);

            try
            {
                // hide the dialog while doing the installation of doors
                Visible = false;
                doorInstaller(); // call the function
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message); //in case there is an error, show a message
            }
            finally
            {
                Visible = true;
                SetFocus(Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle);
            }
        }

// where the called function is something like:
        public static void doorInstaller()
        {
            string block_dwg = "90 degrees swing"; //default
            switch (doorNamesIndex)
            {
                case 0:
                    block_dwg = "90 degrees swing";
                    break;
                case 1:
                    block_dwg = "45 degrees swing";
                    break;
                case 2:
                    block_dwg = "30 degrees swing";
                    break;
                case 3:
                    block_dwg = "15 degrees swing";
                    break;
                case 4:
                    block_dwg = "180 degrees swing";
                    break;
                case 5:
                    block_dwg = "Pair 90 degrees swing";
                    break;
                case 6:
                    block_dwg = "Pair 90 degrees double egress";
                    break;
                case 7:
                    block_dwg = "Sliding";
                    break;
                case 8:
                    block_dwg = "Pocket";
                    break;
                case 9:
                    block_dwg = "Folding";
                    break;
                case 10:
                    block_dwg = "Rolling";
                    break;
            }

            Database db = HostApplicationServices.WorkingDatabase;
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            while (true)
            {
                PromptEntityResult res = ed.GetEntity("\nSelect hinge position: "); //("\n<Enter & back to dialog>/Select hinge position: ")
                if (res.Status != PromptStatus.OK)
                {
                    //SetFocus(Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle);
                    //acedPostCommand("");
                    //acedPostCommand("\003" + "\003" + "\003");
                    return;
                }

                using (DocumentLock doclock = ed.Document.LockDocument())
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {

// [color=blue]more mojo..... salsa, guacamole, enchiladas, quesadillas..... goes here[/color]

                        tr.Commit();
                    }//transaction
                }//docklock
            }//while
        }
« Last Edit: September 09, 2008, 12:30:38 AM by LE »

Glenn R

  • Guest
Re: Button Control Event
« Reply #5 on: September 09, 2008, 02:47:53 AM »

sinc

  • Guest
Re: Button Control Event
« Reply #6 on: September 09, 2008, 08:23:31 AM »
** yawn **

PostCommandPrompt

Are you trying to say "Use Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt()"?

If so, what's wrong with just saying it?  Is the commentary ("** yawn**") really necessary?

Glenn R

  • Guest
Re: Button Control Event
« Reply #7 on: September 09, 2008, 08:34:31 AM »
** yawn **

PostCommandPrompt

Are you trying to say "Use Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt()"?

Yes.

]
If so, what's wrong with just saying it?  Is the commentary ("** yawn**") really necessary?

Considering it was 6:45AM or so in the morning, my eyes were barely open and I knew you'd bite - yes  :-D

sinc

  • Guest
Re: Button Control Event
« Reply #8 on: September 09, 2008, 06:23:05 PM »

If so, what's wrong with just saying it?  Is the commentary ("** yawn**") really necessary?

Considering it was 6:45AM or so in the morning, my eyes were barely open and I knew you'd bite - yes  :-D


<insert politically-incorrect comment here>    :evil: