OSnaps in DrawJig

OSnaps in DrawJig

BrentBurgess1980
Collaborator Collaborator
1,068 Views
2 Replies
Message 1 of 3

OSnaps in DrawJig

BrentBurgess1980
Collaborator
Collaborator

Hi all,

 

I have a Jig that asks the user for start point, end point, and then places circles at spacings along the path.

 

When I use OSnap for the first point, all good (using Editor.GetPoint())

 

My issue is when I select the end point. If I use OSnaps, I might be slightly off the endpoint, but the marker has snapped to it, but when I click, the end point I need is slighty off (It will take location of the crosshairs, and not the snapped location).

 

Is there any way around this?

 public class ReinforcementSectionJig : DrawJig
        {
        public ReinforcementSectionJig()
            : base()
            {
            Reinforcement = new Reinforcement();
            Reinforcement.Points = new Point3dCollection();
     
            }

        public Reinforcement Reinforcement { get; set; }
        public Editor Editor { get { return AcApp.DocumentManager.MdiActiveDocument.Editor; } }

        protected override bool WorldDraw(WorldDraw draw)
            {
            return Reinforcement.JigBars(draw);
            }

        protected override SamplerStatus Sampler(JigPrompts prompts)
            {
            JigPromptPointOptions prOptions1 = new JigPromptPointOptions("\nSpecify point for last bar: ");
            prOptions1.UserInputControls = UserInputControls.GovernedByOrthoMode | UserInputControls.GovernedByUCSDetect | UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted;
            prOptions1.BasePoint = Reinforcement.StartPoint;
            PromptPointResult prResult1 = prompts.AcquirePoint(prOptions1);

            //if (prResult1.Status == PromptStatus.Cancel && prResult1.Status == PromptStatus.Error)
            //    {
            //    return SamplerStatus.Cancel;
            //    }
            if (Reinforcement.EndPoint == prResult1.Value)
                return SamplerStatus.NoChange;
            //else
            //    {
            Reinforcement.EndPoint = prResult1.Value;
            return SamplerStatus.OK;
            //}
            }

        public void Jig()
            {
            PromptPointResult ppr = Editor.GetPoint("\nSpecify point for first bar: ");
            if (ppr.Status == PromptStatus.OK)
                {
                Reinforcement.StartPoint = ppr.Value.TransformBy(Editor.CurrentUserCoordinateSystem);
                if (Editor.Drag(this).Status == PromptStatus.OK)
                    {
                    using (DocumentLock dLock = AcApp.DocumentManager.MdiActiveDocument.LockDocument())
                        {
                        Database db = AcApp.DocumentManager.MdiActiveDocument.Database;
                        using (Transaction tr = db.TransactionManager.StartTransaction())
                            {
                            BlockTableRecord space = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                            Reinforcement.DrawBars(tr, Reinforcement.Points, Reinforcement.Diameter, Reinforcement.Fill, space);
                            tr.Commit();
                            }
                        }
                    }
                }
            }
        }

Capture.PNG

Cheers

Brent

0 Likes
Accepted solutions (2)
1,069 Views
2 Replies
Replies (2)
Message 2 of 3

Alexander.Rivilis
Mentor
Mentor
Accepted solution

I did not found any problem. Compare your code with my code:

 

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.EditorInput;
using AcApp = Autodesk.AutoCAD.ApplicationServices.Application;

// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(AutoCAD_CSharp_plug_in2.ReinforcementSectionJig))]

namespace AutoCAD_CSharp_plug_in2
{

  public class ReinforcementSectionJig : DrawJig
  {
    public ReinforcementSectionJig()
      : base()
    {
      startPt = Point3d.Origin;
      endPt = Point3d.Origin;
    }

    public Point3d startPt, endPt;
    public Editor Editor { get { return AcApp.DocumentManager.MdiActiveDocument.Editor; } }

    protected override bool WorldDraw(WorldDraw draw)
    {
      using (Point3dCollection pts = new Point3dCollection())
      {
        pts.Add(startPt); pts.Add(endPt);
        draw.Geometry.Polyline(pts, Vector3d.ZAxis, IntPtr.Zero);
      }
      return true;
    }

    protected override SamplerStatus Sampler(JigPrompts prompts)
    {
      JigPromptPointOptions prOptions1 = 
        new JigPromptPointOptions("\nSpecify point for last bar: ");
      prOptions1.UserInputControls = 
        UserInputControls.GovernedByOrthoMode | 
        UserInputControls.GovernedByUCSDetect | 
        UserInputControls.Accept3dCoordinates | 
        UserInputControls.NoZeroResponseAccepted;
      prOptions1.BasePoint = startPt;
      prOptions1.UseBasePoint = true; // <--- Added line
      PromptPointResult prResult1 = prompts.AcquirePoint(prOptions1);

      if (endPt == prResult1.Value)
        return SamplerStatus.NoChange;
      endPt = prResult1.Value;
      return SamplerStatus.OK;
    }
    [CommandMethod("JIG")]
    public void Jig()
    {
      PromptPointResult ppr = Editor.GetPoint("\nSpecify point for first bar: ");
      if (ppr.Status == PromptStatus.OK)
      {
        startPt = ppr.Value.TransformBy(Editor.CurrentUserCoordinateSystem);
        if (Editor.Drag(this).Status == PromptStatus.OK)
        {
          using (DocumentLock dLock = AcApp.DocumentManager.MdiActiveDocument.LockDocument())
          {
            Database db = AcApp.DocumentManager.MdiActiveDocument.Database;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
              BlockTableRecord space = 
                (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
              Line line = new Line(startPt, endPt);
              line.SetDatabaseDefaults();
              space.AppendEntity(line);
              tr.AddNewlyCreatedDBObject(line, true);
              tr.Commit();
            }
          }
        }
      }
    }
  }
}

Video of command JIG:

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 3 of 3

BrentBurgess1980
Collaborator
Collaborator
Accepted solution

Thanks Alexander,

 

Your code to draw the line led me to the solution. The issue was how I was storing the bar positions from the jig and then using those to draw the entities. I have changed it so it calculates the bar positions after the user selects the points.

 

Cheers,

0 Likes