Facing a problem when trying to combine Jigs and Palettes, I posted a question on the AutoDesk Discussion Forums.
The problem is as followed: 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 prompting the user to set points while a line is drawn to show the possible result. This mimics the PLINE functionality, which should be familiar to all of us :).
When doing this from a command, all is good. The line appears nicely when the user is moving his mouse. However, 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.
To get around this, Tony Tanzillo posted a nice solution with the AddCommand method in Autodesk.AutoCAD.Internals.Utils. This would work nicely, but this particular project is aimed at AutoCad 2007, where the AddCommand method is not yet present.
So, how can you get around this problem without AddCommand?
There may be many answers, but here is my implementation:
Say there’s a Palette where we want to display the number of Points or Vertices in the Polyline the user has just drawn with the Jig.
To display the number of points, we need to have the Polyline that was drawn. So we need to call a method returning the Polyline that was drawn.
Now, the first button is where the problem is. There, I call the Jig directly from the button, and if you’d run the code at the CCN repository, you’d see that the Jig does not really behave as expected.
So, I needed another way. When the Jig is run from a command, the problem is non existent. Bottom line: run a command from the palette, and make sure that the palette receives the result from the command.
We need a command to be run: so that will be the command from the Through The Interface post: MYPOLY. I changed the code a little bit, so that the promt itself is in a separate class.
This simply looks like this:
Second we need a delegate that we can call from the PromptNewPolylineByPoints method, and we need to invoke that delegate from the prompt:
The code stays the same overall, only difference is at the end:
Only thing left to do is setting an action to do when prompting the polyline, and we do this in the buttons Click Event:
And, finally, doing the desired logic on the resulting polyline:
That’s it, this nicely solved the problem for me. If you have any other solutions, or a different approach, please share :).
Links for the post:
- Polyline Jig on Through The Interface: http://through-the-interface.typepad.com/through_the_interface/2006/11/controlling_int_1.html
- Question on AutoDesk discussion Forums: http://discussion.autodesk.com/forums/thread.jspa?threadID=747119&tstart=0
- Solution in Cup o’ Cad .NET SVN Repository: http://code.google.com/p/cupocadnetdemos/source/browse/#svn/trunk/SampleCollection%3Fstate%3Dclosed