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

How to get the data from a routine which is registered to AutoCAD Command

3 REPLIES 3
Reply
Message 1 of 4
springgump
153 Views, 3 Replies

How to get the data from a routine which is registered to AutoCAD Command

There are three controls on a docking pallette, one "Textbox" and tow "Button". Button2 change the TextBox's text directly, it works, Button1 do it by execute a AutoCAD command, it doesn't works. Why?
As if the rountine register to AutoCAD Command is annother thread...Is there a way to get data form routine which is registered to AutoCAD Command? I need it to interact with the dockingpallette.

Below is the code and the source file is in the attachment.:

//Button1 can not change the Textbox, but Button2 do, why? Please help.

private void button1_Click(object sender, EventArgs e)
{
AcadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("CommandName\n", true, false, false);
}
[Autodesk.AutoCAD.Runtime.CommandMethod("CommandName")]
public void aRountine()
{
// Notice, it can not change the TextBox1
this.textBox1.Text = "abc";
MessageBox.Show("this.textBox1.Text is: " + this.textBox1.Text,"Click form Button1");
}

private void button2_Click(object sender, EventArgs e)
{
this.textBox1.Text = "abc";
MessageBox.Show("this.textBox1.Text is: " + this.textBox1.Text, "Click form Button2");
}

}

Thanks for any help.
3 REPLIES 3
Message 2 of 4
springgump
in reply to: springgump

PS: Using AutoCAD2007 and Visual Studio2005
Message 3 of 4
Anonymous
in reply to: springgump

The problem you're having is that your command
method is non-static.

This is no good, because the runtme is going
to create an instance of the containing/declaring
class (e..g, the UserControl that you add to the
palette) to invoke the command method on.

IOW, the command method is not being invoked
on the instance of your control on the palette, it
is being invoked on a different instance of that
control, that was created by the runtime the first
time you execute the command in the current
document.

One solution:

1. Add a static variable to your TestControl class:

private static TestControl ThisControl = null;

2. In your TestControl's c'tor, initialize the static
variable (assign it to the 'this' pointer):

public TestControl()
{
InitializeComponent();
ThisControl = this;
}

3. Delcare your command method as static,
and in place of 'this', use 'ThisControl':

[CommandMethod("CommandName")]
public static void aRountine()
{
ThisControl.textBox1.Text = "abc";
}

Note that this will only work if your UserControl
is a singleton (e.g., there is only one instance of
it created).


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5316454@discussion.autodesk.com...
There are three controls on a docking pallette, one "Textbox" and tow "Button". Button2 change the TextBox's text directly, it works, Button1 do it by execute a AutoCAD command, it doesn't works. Why?
As if the rountine register to AutoCAD Command is annother thread...Is there a way to get data form routine which is registered to AutoCAD Command? I need it to interact with the dockingpallette.

Below is the code and the source file is in the attachment.:

//Button1 c
an not change the Textbox, but Button2 do, why? Please help.

private void button1_Click(object sender, EventArgs e)
{
AcadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("CommandName\n", true, false, false);
}
[Autodesk.AutoCAD.Runtime.CommandMethod("CommandName")]
public void aRountine()
{
// Notice, it can not change the TextBox1
this.textBox1.Text = "abc";
MessageBox.Show("
this.textBox1.Text is: " + this.textBox1.Text,"Click form Button1");
}

private void button2_Click(object sender, EventArgs e)
{
this.textBox1.Text = "abc";
MessageBox.Show("this.textBox1.Text is: " + this.textBox1.Text, "Click form Button2");
}

}

Thanks for any help.
Message 4 of 4
springgump
in reply to: springgump

Thank you Tony! It works.
Admiring your program skill.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost