Author Topic: Pline jig with double  (Read 3157 times)

0 Members and 1 Guest are viewing this topic.

krkec

  • Guest
Pline jig with double
« on: December 31, 2013, 09:25:07 AM »
hi

I want to modify Kean Walmsely polyline Jig. For before every point user will be asked for entering double and this double will be subtacted form points y value.

Here is class code;

Code: [Select]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace prolazi
{
    class PlineJig : EntityJig
    {
        // Maintain a list of vertices...
        // Not strictly necessary, as these will be stored in the
        // polyline, but will not adversely impact performance
        Point3dCollection m_pts;
        // Use a separate variable for the most recent point...
        // Again, not strictly necessary, but easier to reference
        Point3d m_tempPoint;
        Plane m_plane;
        double nadsloj = 1;
        double cent;
        double promjerC = 300;

        public PlineJig(Matrix3d ucs)
            : base(new Polyline())
        {
            // Create a point collection to store our vertices
            m_pts = new Point3dCollection();

            // Create a temporary plane, to help with calcs
            Point3d origin = new Point3d(0, 0, 0);
            Vector3d normal = new Vector3d(0, 0, 1);
            normal = normal.TransformBy(ucs);
            m_plane = new Plane(origin, normal);

            // Create polyline, set defaults, add dummy vertex
            Polyline pline = Entity as Polyline;
            pline.SetDatabaseDefaults();
            pline.Normal = normal;
            pline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
        }

        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            JigPromptPointOptions jigOpts =
              new JigPromptPointOptions();
            jigOpts.UserInputControls =
              (UserInputControls.Accept3dCoordinates |
              UserInputControls.NullResponseAccepted |
              UserInputControls.NoNegativeResponseAccepted
              );
           
            //JigPromptOptions jpo = new JigPromptOptions();


            if (m_pts.Count == 0)
            {
               
                // For the first vertex, just ask for the point
                jigOpts.Message =
                  "\nStart point of polyline: ";
               
            }
            else if (m_pts.Count > 0)
            {
                //cent = funkcije.odnadsloj(nadsloj) + promjerC * 0.0005;
                // For subsequent vertices, use a base point
                jigOpts.BasePoint = m_pts[m_pts.Count - 1];
                jigOpts.UseBasePoint = true;
                jigOpts.Message = "\nPolyline vertex: ";
            }
            else // should never happen
                return SamplerStatus.Cancel;

            // Get the point itself
           
            PromptPointResult res =
              prompts.AcquirePoint(jigOpts);
            // Check if it has changed or not
            // (reduces flicker)
            if (m_tempPoint == res.Value)
            {
                return SamplerStatus.NoChange;
            }
            else if (res.Status == PromptStatus.OK)
            {
               
                m_tempPoint = res.Value;
                //m_tempPoint = new Point3d(res.Value.X, res.Value.Y - cent, 0);
                return SamplerStatus.OK;
            }
            return SamplerStatus.Cancel;
        }

        protected override bool Update()
        {
            // Update the dummy vertex to be our
            // 3D point projected onto our plane
            Polyline pline = Entity as Polyline;
            pline.SetPointAt(
              pline.NumberOfVertices - 1,
              m_tempPoint.Convert2d(m_plane)
            );
            return true;
        }

        public Entity GetEntity()
        {
            return Entity;
        }

        public void AddLatestVertex()
        {

            cent = funkcije.odnadsloj(nadsloj) + promjerC * 0.0005;
            Point3d k = new Point3d(m_tempPoint.X, m_tempPoint.Y - cent, 0);
           //_tempPoint = k;
            m_pts.Add(k);
            Polyline pline = Entity as Polyline;
            // Create a new dummy vertex...
            // can have any initial value
            pline.AddVertexAt(
              pline.NumberOfVertices,
              new Point2d(0, 0),
              0, 0, 0
            );
        }

        public void RemoveLastVertex()
        {
            // Let's remove our dummy vertex
            Polyline pline = Entity as Polyline;
            pline.RemoveVertexAt(m_pts.Count);
        }
    }
}


Here is function code:

Code: [Select]
[CommandMethod("MYPOLY")]
        public void MyPolyJig()
        {
            Document doc =
              Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            // Get the current UCS, to pass to the Jig
            Matrix3d ucs =
              ed.CurrentUserCoordinateSystem;

            // Create our Jig object
            PlineJig jig = new PlineJig(ucs);

            // Loop to set the vertices directly on the polyline
            bool bSuccess = true, bComplete = false;
            do
            {
                PromptResult res = ed.Drag(jig);
                bSuccess =
                  (res.Status == PromptStatus.OK);
                // A new point was added
                if (bSuccess)
                    jig.AddLatestVertex();
                // Null input terminates the command
                bComplete =
                  (res.Status == PromptStatus.None);
                if (bComplete)
                    // Let's clean-up the polyline before adding it
                    jig.RemoveLastVertex();
            } while (bSuccess && !bComplete);

            // If the jig completed successfully, add the polyline
            if (bComplete)
            {
                // Append entity
                Database db = doc.Database;
                Transaction tr =
                  db.TransactionManager.StartTransaction();
                using (tr)
                {
                    BlockTable bt =
                      (BlockTable)tr.GetObject(
                        db.BlockTableId,
                        OpenMode.ForRead,
                        false
                      );
                    BlockTableRecord btr =
                      (BlockTableRecord)tr.GetObject(
                        bt[BlockTableRecord.ModelSpace],
                        OpenMode.ForWrite,
                        false
                      );
                    btr.AppendEntity(jig.GetEntity());
                    tr.AddNewlyCreatedDBObject(jig.GetEntity(), true);
                    tr.Commit();
                }
            }
        }

I tried everyting please help.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Pline jig with double
« Reply #1 on: February 02, 2017, 10:58:21 AM »
I reckon that this one stumped all the readers.... 3+ year old post, read 428 times, not one response. When I found this in a search I was hopeful of locating an answer to a very similar question I have. Actually, it's pretty much identical, wherein I need to prompt the user for an elevation after a point is successfully picked by the user. I have the Jig working as I need, complete with similar options allowed by the ACAD Polyline command, but I need to store the vertices of the polyline, including user entered Z values, for creating a Civil3D featureline (which is essentially a 3dpoly with arcs) from the polyline. Hoping a bump here will stir some interest...

huiz

  • Swamp Rat
  • Posts: 917
  • Certified Prof C3D
Re: Pline jig with double
« Reply #2 on: February 02, 2017, 03:15:39 PM »
I think you should keep a List<double> for the Z-values next to the Jig polyline and afterwards create the Feature Line with the vertices and bulges combined with the doubles.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Pline jig with double
« Reply #3 on: February 02, 2017, 03:44:40 PM »
Right, Huiz, but, how to get the doubles for the Z as the user selects a point? I think the Jig needs to be stopped/paused, get the double, resume the Jig. I'm just not coming up with the How to do that.

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Pline jig with double
« Reply #4 on: February 02, 2017, 04:30:12 PM »
Can you just drop something in the SamplerStatus Override?

Like this?
Code - C#: [Select]
  1. protected override SamplerStatus Sampler(JigPrompts prompts)
  2. {
  3.         PromptPointResult ppResult;
  4.                 JigPromptPointOptions jigOpts = new JigPromptPointOptions
  5.                 {
  6.                         UserInputControls = UserInputControls.NullResponseAccepted,
  7.                 };
  8.                 ppResult = prompts.AcquirePoint(jigOpts);
  9.                 if (ppResult.Status==PromptStatus.Keyword)
  10.                 else if (ppResult.Status==PromptStatus.OK)
  11.                 {
  12.                         if (ppResult.Value.DistanceTo(LastPoint) < 0.1)
  13.                         {
  14.                                 return SamplerStatus.NoChange;
  15.                         }
  16.                         // get us an ELEVATION, YEAH!
  17.                         PromptDoubleResult pdr = Active.Editor.GetDouble("Enter Elevation: ");
  18.                         double z = 0;
  19.                         if (pdr.Status==PromptStatus.OK)
  20.                         {
  21.                                 LastPoint = ppResult.Value;
  22.                                 z = pdr.Value;
  23.                                 // do something cool here
  24.                         }                      
  25.                 }
  26.         }
  27. }
  28.  
  29.  

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Pline jig with double
« Reply #5 on: February 02, 2017, 06:20:40 PM »
Atook, thanks but I don't think it's that simple. The ppResult.Status = OK every time the cursor moves. I only want to get the elevation from the user when they Pick a point.

ANd as I was typing this I realized I need to do this in the code which calls the ed.Drag() when that Result is OK. Will report back with what I find... Thanks!

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Pline jig with double
« Reply #6 on: February 02, 2017, 10:00:38 PM »
Hmm... I thought ppr only returned when the user clicks, I'll have to look at the complete implementation of my jig.

That code is pulled from I jig I use that prompts the user for an angle after they click to insert a block. I may have simplified it too much for this post.

Curious to see what you come up with.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Pline jig with double
« Reply #7 on: February 03, 2017, 12:23:11 PM »
OK, this is now working as I had hoped. I have a global Point3dCollection, _vertices, that I add each polyline vertex created with the user entered elevation. It is much simpler than I had thought it would be (as usual, it seems).

Code - C#: [Select]
  1. //portion of the command code which constructs and calls the Jig
  2.             while (true)
  3.             {
  4.                 PromptResult res = ed.Drag(jig);
  5.                 switch (res.Status)
  6.                 {
  7.                     // New point was added, keep going
  8.                     case PromptStatus.OK:
  9.                         jig.AddDummyVertex();
  10.                         _vertices.Add(getElevatedPoint(ed, jig._tempPoint)); //<<<<Added this line, had to set the _tempPoint to public in the jig class
  11.                         break;
  12.  
  13.                     // Keyword was entered
  14.                     case PromptStatus.Keyword:
  15. //remainder of code unchanged from Kean's example
  16.  


The getElevatedPoint function handles the ed.GetDouble(), and has options as well to set by elevation/grade/slope/difference, with the end result being the elevated point for use later with the featureline.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Pline jig with double
« Reply #8 on: February 03, 2017, 01:22:52 PM »
ARGHHH. So I hadn't noticed that the jig disappears while it is asking for the elevation...now to figure out why that is.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Pline jig with double
« Reply #9 on: February 03, 2017, 02:16:33 PM »
I've got one that automatically fillets polyline as you draw it and had to drop the jig and just did it with prompting and using Editor.Command.
If you like I can dig it up and post it.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Pline jig with double
« Reply #10 on: February 03, 2017, 02:59:53 PM »
Thanks Jeff, I got it sorted out. While I'm asking for the user to enter the elevation I create a TransientGraphic of the Jig's Entity, then dispose of it when it goes back to jigging.. This keeps the polyline on the screen at all times.