Jig functionality when invoked from Palette

Jig functionality when invoked from Palette

Anonymous
Not applicable
822 Views
6 Replies
Message 1 of 7

Jig functionality when invoked from Palette

Anonymous
Not applicable
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
0 Likes
823 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
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
0 Likes
Message 3 of 7

Anonymous
Not applicable
Very very nice, thanks !
0 Likes
Message 4 of 7

Anonymous
Not applicable
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
0 Likes
Message 5 of 7

Anonymous
Not applicable
Hmm, it seams this method does not yet exist in 2007, any idea on how to do this in AutoCAD 2007?
0 Likes
Message 6 of 7

Anonymous
Not applicable
No can do in 2007. The method it uses didn't appear until AutoCAD 2009.
There's no other simple way of doing that in 2007 I'm afraid.

--
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:6267453@discussion.autodesk.com...
Hmm, it seams this method does not yet exist in 2007, any idea on how to do
this in AutoCAD 2007?
0 Likes
Message 7 of 7

Anonymous
Not applicable
I found a way 🙂
With delegates and SendStringToExecute, I managed to get this working. I will post the details later today.

Update: I posted the details on my blog: http://cupocadnet.blogspot.com/2009/10/using-jigs-from-palettes.html


--

http://cupocadnet.blogspot.com Edited by: bert.vanpeteghem@dolmen.be on Oct 12, 2009 8:20 AM
0 Likes