Author Topic: Jig for a Polyline3d .. trial and error.  (Read 8602 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Jig for a Polyline3d .. trial and error.
« on: January 19, 2008, 11:56:32 PM »
I feel like I belong to a class that Eric Lippert calls 'cargo cultist'
.. that is I've been hacking without fully understanding the meaning and purpose of every line of code.


I've been playing with a  DrawJig to draw a Polyline3d.

Any comments (constructive or otherwise are appreciated)

Commands.cs
Code: [Select]
//
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcRx = Autodesk.AutoCAD.Runtime;
//
using AcCm = Autodesk.AutoCAD.Colors;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;
using AcLy = Autodesk.AutoCAD.LayerManager;
using AcPl = Autodesk.AutoCAD.PlottingServices;
using AcUi = Autodesk.AutoCAD.Windows;

using WinForms = System.Windows.Forms;

[assembly: AcRx.CommandClass(typeof(kdub.Testing.PolyLineJig.TestCommands))]

namespace kdub.Testing.PolyLineJig
{
    public class TestCommands
    {
        public TestCommands() { }
        [AcRx.CommandMethod("PLJig")]
        static public void PolyLineDrawJig_Sample()
        {
            try
            {
                AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
                Database db = ed.Document.Database;

                PolyLineDrawJig plJig = new PolyLineDrawJig();
                int vertexCount = plJig.DoPolyLineDrawJigMoJo();

                // force closed ... ToBeDone:needs to test vertex count                 
                ed.WriteMessage("\nVertexCount :{0}", vertexCount.ToString());

                AcDb.Polyline3d pline3D = new AcDb.Polyline3d(
                    AcDb.Poly3dType.SimplePoly,
                    plJig.Coordinates, true);

                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    AcDb.BlockTableRecord currentSpace = tr.GetObject
                        (db.CurrentSpaceId, OpenMode.ForWrite) as AcDb.BlockTableRecord;
                    currentSpace.AppendEntity(pline3D);
                    tr.AddNewlyCreatedDBObject(pline3D, true);
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                WinForms.MessageBox.Show(ex.Message,
                    "Exception",
                    WinForms.MessageBoxButtons.OK,
                    WinForms.MessageBoxIcon.Error);
            }
        }
    }
}
PolyLineJig.cs
Code: [Select]
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcRx = Autodesk.AutoCAD.Runtime;
//
using AcCm = Autodesk.AutoCAD.Colors;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;
using AcLy = Autodesk.AutoCAD.LayerManager;
using AcPl = Autodesk.AutoCAD.PlottingServices;
using AcUi = Autodesk.AutoCAD.Windows;

using WinForms = System.Windows.Forms;

namespace kdub.Testing.PolyLineJig
{
    public class PolyLineDrawJig : AcEd.DrawJig
    {  // local members 
        private AcGe.Point3d mPoint;
        private AcGe.Point3dCollection mPoints = new AcGe.Point3dCollection();
        //-----------------------------------------
        public AcGe.Point3dCollection Coordinates
        {
            get
            { return mPoints; }
        }
        //-------------------------------------------------------------------
        public PolyLineDrawJig()
        { }
        //-------------------------------------------------------------------

        public int DoPolyLineDrawJigMoJo()
        {
            AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            AcEd.PromptResult jigResult = null;
            do
            {
                jigResult = ed.Drag(this);
                if (jigResult.Status == AcEd.PromptStatus.OK)
                {
                    mPoints.Add(mPoint);
                }
                else if (jigResult.Status == AcEd.PromptStatus.None)
                {
                    break;
                }
            }
            while (jigResult.Status == AcEd.PromptStatus.OK);
            return mPoints.Count;
        }
        //-------------------------------------------------------------------
        protected override AcEd.SamplerStatus Sampler(AcEd.JigPrompts prompts)
        {
            AcEd.JigPromptPointOptions jigOptions = new AcEd.JigPromptPointOptions();
            jigOptions.UserInputControls =
                (AcEd.UserInputControls.Accept3dCoordinates
                | AcEd.UserInputControls.NullResponseAccepted);

            jigOptions.Message = "\nSelect vertex point for self-Closing Polyline: ";
            AcEd.PromptPointResult jigPointResult = prompts.AcquirePoint(jigOptions);

            AcGe.Point3d pt = jigPointResult.Value;
            if (pt == mPoint)
            {
                return AcEd.SamplerStatus.NoChange;
            }
            mPoint = pt;

            if (jigPointResult.Status == AcEd.PromptStatus.OK)
            {
                return AcEd.SamplerStatus.OK;
            }
            return AcEd.SamplerStatus.Cancel;
        }
        //-------------------------------------------------------------------
        protected override bool WorldDraw(AcGi.WorldDraw draw)
        {
            if (mPoints.Count == 0)
            {
                return true;
            }
            AcGe.Point3dCollection vertices = new AcGe.Point3dCollection();
            foreach (AcGe.Point3d point in mPoints)
            {
                vertices.Add(point);
            }
            vertices.Add(mPoint);

            draw.Geometry.Polyline(vertices, AcGe.Vector3d.ZAxis, new System.IntPtr(0));

            return true;
        }
        //-------------------------------------------------------------------
    }
}

amended: posted code into code pane.

and the piccy ...

« Last Edit: January 27, 2008, 05:30:18 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Jig for a Polyline3d .. trial and error.
« Reply #1 on: January 20, 2008, 12:10:50 AM »

this started out yesterday with an attempt to dynamically build a Point3dCollection
then the 'what-if's' sort of took over ...
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
« Last Edit: January 20, 2008, 12:24:20 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Jig for a Polyline3d .. trial and error.
« Reply #3 on: January 20, 2008, 02:58:52 PM »
Kerry I'd say you would have to be the anti cargo cultist. You understand how the code does it, here you were just finding how this particular part works.
The interesting part is that you designed a way that gives you a list of points without the necessity of adding a memory resident object, and it works great except for the flicker (On my screen it is bad, every new picked point). So now do you leave it, get rid of the jig and just add verticies or? 
It's definately hard to follow a code outline if you don't know what the code can do.

Glenn R

  • Guest
Re: Jig for a Polyline3d .. trial and error.
« Reply #4 on: January 20, 2008, 03:09:46 PM »
Kerry,

What are you doing to format your code as above? It looks good...

Glenn.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Jig for a Polyline3d .. trial and error.
« Reply #5 on: January 20, 2008, 05:24:27 PM »
I use Ctrl-E + D to auto format my code in the IDE
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

MickD

  • King Gator
  • Posts: 3646
  • (x-in)->[process]->(y-out) ... simples!
Re: Jig for a Polyline3d .. trial and error.
« Reply #6 on: January 20, 2008, 05:53:02 PM »
Just an observation (a thought why it might 'flicker') and there may be a very good reason for it but can't you just pass in your member var mpoints collection to the 'draw.Geometry.Polyline' method?

Every time the mouse moves while drawing the object calls the worlddraw function to update the screen and you are assigning to a 'new' array every time. I don't think the jig works as efficiently as the 'rubber band' line as the last point is stored internally, a jig is continually calling for all points.

hth.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3646
  • (x-in)->[process]->(y-out) ... simples!
Re: Jig for a Polyline3d .. trial and error.
« Reply #7 on: January 20, 2008, 06:10:02 PM »
vertices.Add(mPoint);

the mPoint above is also added in another method.

Like I was saying there may be a good reason but the way I understand the world draw function is that it reads it's values from the member variables and is there just to draw the object, these variables are updated from other methods that deal with user interaction/modifications etc.
hope that makes sense.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Jig for a Polyline3d .. trial and error.
« Reply #8 on: January 20, 2008, 09:19:50 PM »
Kerry,

What are you doing to format your code as above? It looks good...

Glenn.

For Posting :
remove the space at the braces

[ i ][ b ]FileName.cs[ /b ][ /i ]
[ color=navy ][ size=10pt ][ tt ]

// paste code here

[ /tt ][ /size ][ /color ]

added:
Formatting is a mix of VS default and my own edits
.. I like a little white space so the code can breathe ..
« Last Edit: January 20, 2008, 09:25:28 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Jig for a Polyline3d .. trial and error.
« Reply #9 on: January 20, 2008, 09:22:16 PM »

I'm away from home today .. and shall be regularly ..
will address comments tonight at home.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

sinc

  • Guest
Re: Jig for a Polyline3d .. trial and error.
« Reply #10 on: January 20, 2008, 11:23:08 PM »
Posting in color doesn't really work too well.  That code is very hard to read with some of the Swamp themes.   :?

Code tags work better - they separate the code from the rest of the text in a way that works in all the themes.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Jig for a Polyline3d .. trial and error.
« Reply #11 on: January 21, 2008, 12:11:17 PM »
Have to agree with Sinc here. I cannot read that code at all without selecting it so it's highlighted.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Jig for a Polyline3d .. trial and error.
« Reply #12 on: January 25, 2008, 08:15:59 PM »
just came across these .. Worth a read :

Controlling interactive polyline creation - Part 1 : November 8, 2006
http://through-the-interface.typepad.com/through_the_interface/2006/11/creating_a_poly.html

Controlling interactive polyline creation - Part 2
http://through-the-interface.typepad.com/through_the_interface/2006/11/controlling_int.html

Controlling interactive polyline creation - Part 3
http://through-the-interface.typepad.com/through_the_interface/2006/11/controlling_int_1.html

Advanced jigging with AutoCAD .NET - adding keywords : November 17, 2006
http://through-the-interface.typepad.com/through_the_interface/2006/11/advanced_jiggin.html
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Jig for a Polyline3d .. trial and error.
« Reply #13 on: January 27, 2008, 05:26:52 PM »
Jeff, Sinc,

I've changed the posted code text color from navy to default.
you guys must be using one of the black background Forum styles, yes ?

Just a reference note :
I've had been using the Cityscape forum style which puts vertical scroll bars on all the code panes.

The Mercury and Oxygen styles do not add the Scroll bars , consequently showing all the code in the code pane ( which is what I prefer).
so .. I've changed my furum style to Mercury, and should be able to post into code panes. Anyone using one of the other styles will just have to vertically scroll their code pane to read the code.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

sinc

  • Guest
Re: Jig for a Polyline3d .. trial and error.
« Reply #14 on: January 27, 2008, 09:39:57 PM »
Much better.   :-)