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

Re-trigger form event by pessing enter in AutoCAD?

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
438 Views, 1 Reply

Re-trigger form event by pessing enter in AutoCAD?

Not sure if i'm reaching here but i want to rerun some code after pressing enter in AutoCAD.  Here's some background on whats going on some background:

 

I have a floating windows form with a Data Grid View in it.  when you double click a row in the DGV a bunch of info is retrieved from the Data Source and passed to a draw line jig function so the line is drawn to the correct specifications.

 

This works fine except it may get tedious always having to double click the DGV to execute the draw line jig so i'm wondering/hoping if there is a way to embed the [CommandMethod("xxx")] caller or something similar so that you can just press enter and re-run DGV event again with the same info being passed to the draw line jig.  From what i've read by searching and tried it doesn't seem possible.

 

This is the code that calls the jig:

 

private void dgvLines_DoubleClick(object sender, EventArgs e)
        {
            
            // get the line details from the grid view click
            string lineNumber = acadAp.Application.GetSystemVariable("clayer").ToString();
            string lineType = (bindingSourceLines.Current as DataRowView)["LINE_TYPE"].ToString();
            string lineFile = (bindingSourceLines.Current as DataRowView)["LINE_FILE"].ToString();
            string lineColorStr = (bindingSourceLines.Current as DataRowView)["LINE_COLOR"].ToString();
            short lineColor = Convert.ToInt16(lineColorStr);
            string lineScaleStr = (bindingSourceLines.Current as DataRowView)["LINE_SCALE"].ToString();
            int lineScale = Convert.ToInt32(lineScaleStr);

            acadEd.Editor editor = acadApp.DocumentManager.MdiActiveDocument.Editor;
            if (Draw_Line.MultiPointJig(lineNumber, lineType, lineFile, lineColor, lineScale))
            {
                editor.WriteMessage("\nLine added to drawingn");
            }
            else
            {
                editor.WriteMessage("\nThere was an errorn");
            }

 

 

Most appreciative for any guidance.

Labels (3)
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

so to answer my own question, after getting some advice from @Anonymous on another thread:

 

just had to change a few things around:

  • public static class to define the variables to be passed
  • register an acad command with commandmethod
  • use sendstringtoexecute

 

// public static class to set global variables that can be accessed from anywhere
        public static class LineDetails
        {
            // get the line details from the grid view click
            public static string lineNumber;
            public static string lineType;
            public static string lineFile;
            public static string lineColorStr;
            public static short lineColor;
            public static string lineScaleStr;
            public static int lineScale;
        }

        // double click event to get the info from the gridview
        public void dgvLines_DoubleClick(object sender, EventArgs e)
        {
            // get the line details from the grid view click
            LineDetails.lineNumber = acadAp.Application.GetSystemVariable("clayer").ToString();
            LineDetails.lineType = (bindingSourceLines.Current as DataRowView)["LINE_TYPE"].ToString();
            LineDetails.lineFile = (bindingSourceLines.Current as DataRowView)["LINE_FILE"].ToString();
            LineDetails.lineColorStr = (bindingSourceLines.Current as DataRowView)["LINE_COLOR"].ToString();
            LineDetails.lineColor = Convert.ToInt16(LineDetails.lineColorStr);
            LineDetails.lineScaleStr = (bindingSourceLines.Current as DataRowView)["LINE_SCALE"].ToString();
            LineDetails.lineScale = Convert.ToInt32(LineDetails.lineScaleStr);

            // send string to execute to bypass the focus issue moving between form and window
            document.SendStringToExecute("DrawLine ",true, false, false);

        }

        // autocad command, allows user to press enter to access last command also
        [acadRt.CommandMethod("DrawLine")]
        public void DrawLine()
        {
            // call the draw line jig and report success to command line
            acadEd.Editor editor = acadApp.DocumentManager.MdiActiveDocument.Editor;
            if (Draw_Line.MultiPointJig(LineDetails.lineNumber, LineDetails.lineType, LineDetails.lineFile, LineDetails.lineColor, LineDetails.lineScale))
            {
                editor.WriteMessage("\nLine added to drawingn");
            }
            else
            {
                editor.WriteMessage("\nThere was an error adding Line to drawingn");
            }
        }

 

 

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

Post to forums  

Forma Design Contest


AutoCAD Beta