oops... wait a minute...
There's one small problem with that example, which is that it leaves the
command defined, which means the user could issue it, which is something you
can't allow.
Here's a slightly different version that adds the command just before it
runs, and removes it when it completes.
{code}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Acad = Autodesk.AutoCAD.ApplicationServices.Application;
using System.Drawing;
namespace Namespace1
{
public class MyPaletteControl : UserControl
{
// A button that when clicked, triggers the
// code in the modal command handler to run:
private Button button1 = new Button();
public MyPaletteControl()
{
this.Controls.Add( button1 );
button1.Location = new Point( 10, 10 );
button1.Visible = true;
button1.Click += new EventHandler( button1_Click );
}
void button1_Click( object sender, EventArgs e )
{
Document doc = Acad.DocumentManager.MdiActiveDocument;
if( doc != null && doc.Editor.IsQuiescent )
{
// Add the temporary command and then execute it:
Autodesk.AutoCAD.Internal.Utils.AddCommand(
"MYPALETTECONTROL",
"MYPALETTECOMMAND1",
"MYPALETTECOMMAND1",
CommandFlags.NoActionRecording
| CommandFlags.NoHistory
| CommandFlags.NoMultiple,
this.OnMyPaletteCommand1 );
doc.SendStringToExecute( "MYPALETTECOMMAND1\n",
true, false, false );
}
}
private void OnMyPaletteCommand1()
{
try
{
// disable the palette control to avoid unintended
// reentry while the command is in progress.
button1.Enabled = false;
////////////////////////////////////////////
// TODO:
// code here behaves like it is being run
// from a modal command method (because it is)
////////////////////////////////////////////
}
finally
{
// remove the command that triggered the call to
// this method, so the user can't issue it directly:
Autodesk.AutoCAD.Internal.Utils.RemoveCommand(
"MYPALETTECONTROL", "MYPALETTECOMMAND1" );
// reenable the button:
button1.Enabled = true;
}
}
}
}
{code}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010
http://www.acadxtabs.com
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
"Tony Tanzillo" wrote in message
news:6265911@discussion.autodesk.com...
Rather than run your code directly from a control event on your palette,
define an AutoCAD command dynamically using the undocumented AddCommand()
method from Autodesk.AutoCAD.Internal.Utils. From the control event handler
on your pallete, invoke the command using SendStringToExecute().
Here's a quick example:
{code}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Acad = Autodesk.AutoCAD.ApplicationServices.Application;
using System.Drawing;
namespace Namespace1
{
public class MyPaletteControl : UserControl
{
// A button that when clicked, triggers the
// code in the modal command handler to run:
private Button button1 = new Button();
// constructor
public MyPaletteControl()
{
this.Controls.Add( button1 );
button1.Location = new Point( 10, 10 );
button1.Visible = true;
button1.Click += new EventHandler( button1_Click );
// Add a command that runs when button1 is clicked:
Autodesk.AutoCAD.Internal.Utils.AddCommand(
"MYPALETTECONTROL",
"MYPALETTECOMMAND1",
"MYPALETTECOMMAND1",
CommandFlags.NoActionRecording
| CommandFlags.NoHistory
| CommandFlags.NoMultiple,
this.OnMyPalettteCommand1 );
}
void button1_Click( object sender, EventArgs e )
{
Document doc = Acad.DocumentManager.MdiActiveDocument;
if( doc != null && doc.Editor.IsQuiescent )
{
doc.SendStringToExecute( "MYPALETTECOMMAND1\n",
true, false, false );
}
}
private void OnMyPalettteCommand1()
{
// disable the palette control to avoid unintended
// reentry while the command is in progress.
this.Enabled = false;
////////////////////////////////////////////
// TODO:
// code here behaves like it is being run
// from a modal command method (because it is)
////////////////////////////////////////////
// reenable the control:
this.Enabled = true;
}
}
}
{code}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010
http://www.acadxtabs.com
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
wrote in message
news:6265716@discussion.autodesk.com...
Hi,
I implemented some code from the TTI blog to create polylines with a Jig.
(http://through-the-interface.typepad.com/through_the_interface/2006/11/controlling_int_1.html)
It is basically a Jig with a line that is drawn to mimic the PLINE
functionality.
When doing this from a command, all is good.
When doing this from a button on a palette, the line drawn by the Jig is not
visible, nor are snaps.
I also noticed that when running from a command, the comboboxes in the
toolbars lock up, but this does not happen from the palette.
Any thoughts? I'm using AutoCAD 2007 for this project.
--
http://cupocadnet.blogspot.com
Edited by: bert.vanpeteghem@dolmen.be on Oct 5, 2009 1:54 PM