<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Offset polyline by pick point on side like autocad in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/3769549#M51280</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great.It worked OK.&lt;/P&gt;&lt;P&gt;Thank Rivilis,&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/481027" target="_self"&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Feb 2013 08:05:22 GMT</pubDate>
    <dc:creator>ditran7577</dc:creator>
    <dc:date>2013-02-05T08:05:22Z</dc:date>
    <item>
      <title>Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/3768533#M51277</link>
      <description>&lt;P&gt;Hi pro,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know how to offset a &lt;SPAN&gt;opened&amp;nbsp;&lt;/SPAN&gt;polyline by pick point on side of opened polyline.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2013 01:32:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/3768533#M51277</guid>
      <dc:creator>ditran7577</dc:creator>
      <dc:date>2013-02-04T01:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/3768695#M51278</link>
      <description>&lt;P&gt;With minimum error checking. Only as idea.&lt;/P&gt;
&lt;PRE&gt;using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

[assembly: CommandClass(typeof(Rivilis.CurveUtils))]

namespace Rivilis
{
  public class CurveUtils
  {
    [CommandMethod("OffsetCurve", CommandFlags.Modal)]
    public static void OffsetCurve()
    {
      Document doc = Application.DocumentManager.MdiActiveDocument;
      Editor ed = doc.Editor;
      PromptDoubleResult resValueOff = ed.GetDistance("\nOffset value: ");
      if (resValueOff.Status != PromptStatus.OK) return;
      PromptPointResult  resPointOff = ed.GetPoint("\nOffset side: ");
      if (resPointOff.Status != PromptStatus.OK) return;
      PromptEntityOptions prCurv = new PromptEntityOptions("\nSelect curve: ");
      prCurv.SetRejectMessage("not a Curve");
      prCurv.AddAllowedClass(typeof(Curve),false);
      PromptEntityResult resCurv = ed.GetEntity(prCurv);
      if (resCurv.Status != PromptStatus.OK) return;
      
      using  (Transaction tr = doc.TransactionManager.StartTransaction()) {
        Curve curve = tr.GetObject(resCurv.ObjectId, OpenMode.ForRead) as Curve;
        if (curve != null) {
          BlockTableRecord btr = tr.GetObject(curve.BlockId, OpenMode.ForWrite) as BlockTableRecord;
          if (btr != null) {
            Point3d pDir = (Point3d)(Application.GetSystemVariable("VIEWDIR"));
            if (pDir != null) {
              Point3d pWCS = resPointOff.Value.TransformBy(ed.CurrentUserCoordinateSystem);
              double offset = IsRightDirection(curve, pWCS, pDir.GetAsVector()) ? resValueOff.Value : -resValueOff.Value;
              DBObjectCollection curvCols = curve.GetOffsetCurves(offset);
              foreach (DBObject obj in curvCols) {
                Curve subCurv = obj as Curve;
                if (subCurv != null) {
                  btr.AppendEntity(subCurv);
                  tr.AddNewlyCreatedDBObject(subCurv, true);
                }
              }
            }
          }
        }
        tr.Commit();
      }
    }
    // Detect side of point
    public static bool IsRightDirection(Curve pCurv, Point3d p, Vector3d vDir)
    {
      Vector3d vNormal = Vector3d.ZAxis;
      if (pCurv.IsPlanar) {
        Plane plane = pCurv.GetPlane();
        vNormal = plane.Normal;
        p = p.Project(plane, vDir);
      }
      Point3d pNear = pCurv.GetClosestPointTo(p, true);
      Vector3d vSide = p - pNear;
      Vector3d vDeriv = pCurv.GetFirstDerivative(pNear);
      if (vNormal.CrossProduct(vDeriv).DotProduct(vSide) &amp;lt; 0.0)
        return true;
      else
        return false;
    }
  }
}
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2013 10:17:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/3768695#M51278</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2013-02-04T10:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/3768724#M51279</link>
      <description>&lt;P&gt;Nice solution&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hats off&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Cheers &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2013 11:34:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/3768724#M51279</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2013-02-04T11:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/3769549#M51280</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great.It worked OK.&lt;/P&gt;&lt;P&gt;Thank Rivilis,&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/481027" target="_self"&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2013 08:05:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/3769549#M51280</guid>
      <dc:creator>ditran7577</dc:creator>
      <dc:date>2013-02-05T08:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/5058954#M51281</link>
      <description>&lt;P&gt;Hello Rivilis,&lt;/P&gt;&lt;P&gt;Thank you for the code, it works perfect with polyline and circle I tried but works inverse in case of line.&lt;/P&gt;&lt;P&gt;How can I solve this?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 May 2014 17:32:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/5058954#M51281</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-05-27T17:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/5532005#M51282</link>
      <description>&lt;P&gt;From ARX docs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;nbsp;AcDbCurve::getOffsetCurves&lt;BR /&gt;&amp;gt; If the offsetDist value is negative, it is usually interpreted as being an offset to make a smaller curve (that is, for an arc it would offset to a radius that is offsetDist less than the starting curve's radius). If the negative value has no meaning in terms of making the curve smaller, a negative offsetDist may be interpreted as an offset in the direction of smaller X,Y,Z WCS coordinates. This is not enforced, so custom entities can interpret the sign of the offsetDist value however they want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you can not know where the offset curves will go. You have to offset, then check if the new curves are on the desired&amp;nbsp;side and if not, negate&amp;nbsp;the offset.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2015 10:47:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/5532005#M51282</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2015-03-07T10:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/5833794#M51283</link>
      <description>&lt;P&gt;had trouble with the suggested solution(need to brush up on my math), but I have devised a method that worked with different entities:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public static bool IsRightDirection2(Curve pCurv, Point3d picked) //picked - picked point (not point on curve)
        {
            Point3d pOnCurve = pCurv.GetClosestPointTo(picked, false);
            var dist = picked.DistanceTo(pOnCurve);

            double distCheck = new double(); 
            DBObjectCollection acDbObjColl = pCurv.GetOffsetCurves(dist);
            foreach (Entity acEnt in acDbObjColl)
            {
                Curve testCurve = acEnt as Curve;
                distCheck = picked.DistanceTo(testCurve.GetClosestPointTo(picked, false)); 
            }
            if (distCheck == 0) 
                return true;
            else
                return false;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I still need to do some bug testing, and to be safe, you can implement the planar check from previous solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;basically, it creates a temporary object offset-ed at small distance, and checks if distance from the new object to that point is 0. (if not 0, means its on the opposite side of the object).&lt;/P&gt;</description>
      <pubDate>Sat, 26 Sep 2015 07:22:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/5833794#M51283</guid>
      <dc:creator>5thSth</dc:creator>
      <dc:date>2015-09-26T07:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6534721#M51284</link>
      <description>&lt;P&gt;Hate to wake up an old post, but it is one of the closer relevant posts to what I need. I'm a newer programmer trying to work a set of tools and was wondering if anyone could help me do this same style of function in VB.NET rather than C#.NET?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already have it set to create a line from point a (User Selected) to point b (Also user selected), and have it offset 1 foot, but I need it to offset in a specific direction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Namespace Tools

    Public Class Commands
        &amp;lt;CommandMethod("OffSeC")&amp;gt;
        Public Sub OffSeC()
            '' Get the current document and database
            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database

            Dim pPtRes As PromptPointResult
            Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")

            '' This asks for the Dead.
            pPtOpts.Message = vbLf &amp;amp; "Choose Dead."
            pPtRes = acDoc.Editor.GetPoint(pPtOpts)
            Dim ptDead As Point3d = pPtRes.Value

            '' Emergency Exit Here!
            If pPtRes.Status = PromptStatus.Cancel Then Exit Sub

            '' This asks for the Live.
            pPtOpts.Message = vbLf &amp;amp; "Live?"
            pPtOpts.UseBasePoint = True
            pPtOpts.BasePoint = ptDead
            pPtRes = acDoc.Editor.GetPoint(pPtOpts)
            Dim ptLive As Point3d = pPtRes.Value

            '' Emergency Exit Numero Dos!
            If pPtRes.Status = PromptStatus.Cancel Then Exit Sub

            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                '' Open the Block Table for read.
                Dim acBlkTbl As BlockTable
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)

                '' Open the Block table record Model space for write
                Dim acBlkTblRec As BlockTableRecord
                acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

                Using acLine As Line = New Line(ptDead, ptLive)
                    acBlkTblRec.AppendEntity(acLine)
                    acTrans.AddNewlyCreatedDBObject(acLine, True)

                    Dim acDbObjColl As DBObjectCollection = acLine.GetOffsetCurves(12)

                    For Each acEnt As Entity In acDbObjColl
                        acBlkTblRec.AppendEntity(acEnt)
                        acTrans.AddNewlyCreatedDBObject(acEnt, True)
                    Next
                End Using
                '
                acTrans.Commit()

            End Using
        End Sub

    End Class

End Namespace&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2016 17:50:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6534721#M51284</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-31T17:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536059#M51285</link>
      <description>&lt;P&gt;To offset a line, you only need to translate the two end points, it's trivial.&amp;nbsp;The GetSecondDerivative function should return you a vector perpendicular to your line. Not sure, but it should be an unit vector. After that, you multiply this vector with your offset and you add it to the end points:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim v As Vector3d =&amp;nbsp;line.GetSecondDerivative(0) * offset&lt;BR /&gt;Dim newLine As New Line(line.StartPoint + v, line.EndPoint + v)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 08:50:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536059#M51285</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2016-09-01T08:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536676#M51286</link>
      <description>&lt;P&gt;But wouldn't that Offset the line to the point clicked? Rather than offset it the one foot as it already does?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 14:18:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536676#M51286</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-01T14:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536699#M51287</link>
      <description>&lt;P&gt;To check the side, you can use a cross product between a vector starting from the start of your line to the point clicked by the user and the line direction vector. The Z coordinate will&amp;nbsp;be positive if the point clicked by the user is on the left of the line, negative if it is on the right.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 14:25:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536699#M51287</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2016-09-01T14:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536732#M51288</link>
      <description>&lt;P&gt;Well, now the issue I keep running into is Line.GetSecondDerivative(0). where GetSecondDerivative spits out the "Cannot access function" error. &amp;nbsp;Would I need to import anything other than these?&lt;BR /&gt;Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;Imports Autodesk.AutoCAD.Geometry&lt;BR /&gt;Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;Imports Autodesk.AutoCAD.EditorInput&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 14:36:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536732#M51288</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-01T14:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536757#M51289</link>
      <description>&lt;P&gt;&lt;SPAN&gt;GetSecondDerivative is an instance method of the Autodesk.AutoCAD.DatabaseServices.Curve class, so if you have a&amp;nbsp;Autodesk.AutoCAD.DatabaseServices import, it should be OK.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 14:40:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536757#M51289</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2016-09-01T14:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536801#M51290</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1027563"&gt;@FRFR1426&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;To offset a line, you only need to translate the two end points, it's trivial.&amp;nbsp;The GetSecondDerivative function should return you a vector perpendicular to your line. Not sure, but it should be an unit vector. After that, you multiply this vector with your offset and you add it to the end points:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim v As Vector3d =&amp;nbsp;line.GetSecondDerivative(0) * offset&lt;BR /&gt;Dim newLine As New Line(line.StartPoint + v, line.EndPoint + v)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As far as I remember GetSecondDerivative for Line and stretch segment of polyline return zero-vector. &lt;/P&gt;
&lt;P&gt;On this picture 1 - First Derivative, 2 - Second Derivative:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="0_115f1c_2f4b11af_orig.png" style="width: 468px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/269059i53317F55C96B8FCE/image-size/large?v=v2&amp;amp;px=999" role="button" title="0_115f1c_2f4b11af_orig.png" alt="0_115f1c_2f4b11af_orig.png" /&gt;&lt;/span&gt;﻿&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 14:52:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536801#M51290</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2016-09-01T14:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536819#M51291</link>
      <description>&lt;P&gt;Yes, it's because lines have no curvature, so there is an infinity of second derivatives. You can use instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(line.EndPoint - line.StartPoint).GetPerpendicularVector()&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Sep 2016 14:58:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536819#M51291</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2016-09-01T14:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536907#M51292</link>
      <description>&lt;P&gt;I cant help you with VB, but I can give you my complete code for c#.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;there are online translators C# to VB that could do the translating for ya.&amp;nbsp;&lt;A href="http://converter.telerik.com/" target="_blank"&gt;http://converter.telerik.com/&lt;/A&gt; 4 example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this was a jig class that would do the realtime offset preview. I was newb back then(still am), and I'm not sure if I finished everything I had planned, but&amp;nbsp;here's the code I have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;basically, it would&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a) project&amp;nbsp;the offset line&lt;/P&gt;
&lt;P&gt;b) check to see if the offset line is there where it's supposed to be&lt;/P&gt;
&lt;P&gt;c) if its not there, flip the&amp;nbsp;direction&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using System;
using System.Collections.Generic;
//using System.Linq;
//using System.Text;


namespace myOffset
{
    public class myOffsetJig : DrawJig
    {
        #region fields
        private Point3d jigOnLinePt;
        private Point3d selectedPt;
        private Polyline myPoly;
        //private double myAngle;

        private double myDist;
        private Entity theEntity;
        public Entity testCurve;

        private List&amp;lt;double&amp;gt; myOffsets = new List&amp;lt;double&amp;gt;() { 0, 5, 10, 15 };

        private Matrix3d myPointUCS;
        #endregion
        #region constructor
        public myOffsetJig(Point3d onLinePt, Point3d picked, Polyline myPolyline, Matrix3d pointUCS)
        {
            jigOnLinePt = onLinePt;
            selectedPt = picked.TransformBy(UCS);
            myPoly = myPolyline;
            myPointUCS = pointUCS;
            //myAngle = angle;
        }
        #endregion
        #region properties
        public double Distance
        {
            get { return myDist; }
            set { myDist = value; }
        }

        public Matrix3d UCS
        {
            get
            {
                return Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem;
            }
        }

        #endregion

        #region offet
        public Entity offsetPoly
        {
            get
            {
                DBObjectCollection acDbObjColl = myPoly.GetOffsetCurves(myDist);
                foreach (Entity acEnt in acDbObjColl)
                {
                    theEntity = acEnt;
                }
                theEntity.ColorIndex = 4;
                return theEntity;
            }
        }
        #endregion

   
        #region // Detect side of point¸2
        public static bool IsRightDirection2(Curve pCurv, Point3d picked/*, Vector3d vDir*/)
        {

            Point3d pOnCurve = pCurv.GetClosestPointTo(picked, false);
            var dist = picked.DistanceTo(pOnCurve);
            DBObjectCollection acDbObjColl = pCurv.GetOffsetCurves(dist);
            double distCheck = new double();

            foreach (Entity acEnt in acDbObjColl)
            {
                Curve testCurve = acEnt as Curve;
                distCheck = picked.DistanceTo(testCurve.GetClosestPointTo(picked, false));
            }
            if (distCheck == 0)
                return true;
            else
                return false;
        }
        #endregion


        #region WorldDraw
        protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
        {
            //Matrix3d mat = Matrix3d.Displacement(mBase.GetVectorTo(mLocation));

            Autodesk.AutoCAD.GraphicsInterface.WorldGeometry geo = draw.Geometry;
            if (geo != null)
            {
                geo.Draw(offsetPoly);
                foreach (var offset in myOffsets)
                {
                    var myEnt = offsetWidget.drawLine(offset);
                    myEnt.TransformBy(myPointUCS);
                    myEnt.ColorIndex = 4;
                    myEnt.IsContentSnappable();
                    geo.Draw(myEnt);
                }
                //geo.PushModelTransform(mat);
                //geo.PopModelTransform();
            }
            return true;
        }
        #endregion

        #region SamplerStatus
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            JigPromptPointOptions prDistOpt = new JigPromptPointOptions("\nInput offset");
            prDistOpt.BasePoint = jigOnLinePt;
            prDistOpt.UseBasePoint = true;
            //prDistOpt.Cursor = CursorType.Parallelogram;

            var prDist = prompts.AcquirePoint((JigPromptPointOptions)prDistOpt);
            if (prDist.Status == PromptStatus.Cancel || prDist.Status == PromptStatus.Error)
                return SamplerStatus.Cancel;

            if (!prDist.Equals(0))
            {
                myDist = prDist.Value.TransformBy(myPointUCS.Inverse()).Y;
                myDist = IsRightDirection2(myPoly, selectedPt /*, pDir.GetAsVector()*/) ? myDist : -myDist;
                return SamplerStatus.OK;
            }
            else
                return SamplerStatus.NoChange;
        }
        #endregion


        #region Initialize Jig
        //[CommandMethod("OffsetJig")]
        public void OffsetJigCommand()
        {
            try
            {
                Database db = HostApplicationServices.WorkingDatabase;
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {

                    PromptResult jigRes = Application.DocumentManager.MdiActiveDocument.Editor.Drag(this);

                    if (jigRes.Status == PromptStatus.OK)
                    {

                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                        DBObjectCollection acDbObjColl = myPoly.GetOffsetCurves(myDist);
                        foreach (Entity acEnt in acDbObjColl)
                        {
                            // Add each offset object
                            btr.AppendEntity(acEnt);
                            tr.AddNewlyCreatedDBObject(acEnt, true);
                        }
                        tr.Commit();
                    }
                    else
                        tr.Abort();
                }
            }
        #endregion

            #region exception
            catch (System.Exception ex)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString());
            }
            #endregion
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;p.s. thanks giles for transformation matrix&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 15:31:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6536907#M51292</guid>
      <dc:creator>5thSth</dc:creator>
      <dc:date>2016-09-01T15:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6550444#M51293</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/481027"&gt;@Alexander.Rivilis&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;With minimum error checking. Only as idea.&lt;/P&gt;&lt;PRE&gt;using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

[assembly: CommandClass(typeof(Rivilis.CurveUtils))]

namespace Rivilis
{
  public class CurveUtils
  {
    [CommandMethod("OffsetCurve", CommandFlags.Modal)]
    public static void OffsetCurve()
    {
      Document doc = Application.DocumentManager.MdiActiveDocument;
      Editor ed = doc.Editor;
      PromptDoubleResult resValueOff = ed.GetDistance("\nOffset value: ");
      if (resValueOff.Status != PromptStatus.OK) return;
      PromptPointResult  resPointOff = ed.GetPoint("\nOffset side: ");
      if (resPointOff.Status != PromptStatus.OK) return;
      PromptEntityOptions prCurv = new PromptEntityOptions("\nSelect curve: ");
      prCurv.SetRejectMessage("not a Curve");
      prCurv.AddAllowedClass(typeof(Curve),false);
      PromptEntityResult resCurv = ed.GetEntity(prCurv);
      if (resCurv.Status != PromptStatus.OK) return;
      
      using  (Transaction tr = doc.TransactionManager.StartTransaction()) {
        Curve curve = tr.GetObject(resCurv.ObjectId, OpenMode.ForRead) as Curve;
        if (curve != null) {
          BlockTableRecord btr = tr.GetObject(curve.BlockId, OpenMode.ForWrite) as BlockTableRecord;
          if (btr != null) {
            Point3d pDir = (Point3d)(Application.GetSystemVariable("VIEWDIR"));
            if (pDir != null) {
              Point3d pWCS = resPointOff.Value.TransformBy(ed.CurrentUserCoordinateSystem);
              double offset = IsRightDirection(curve, pWCS, pDir.GetAsVector()) ? resValueOff.Value : -resValueOff.Value;
              DBObjectCollection curvCols = curve.GetOffsetCurves(offset);
              foreach (DBObject obj in curvCols) {
                Curve subCurv = obj as Curve;
                if (subCurv != null) {
                  btr.AppendEntity(subCurv);
                  tr.AddNewlyCreatedDBObject(subCurv, true);
                }
              }
            }
          }
        }
        tr.Commit();
      }
    }
    // Detect side of point
    public static bool IsRightDirection(Curve pCurv, Point3d p, Vector3d vDir)
    {
      Vector3d vNormal = Vector3d.ZAxis;
      if (pCurv.IsPlanar) {
        Plane plane = pCurv.GetPlane();
        vNormal = plane.Normal;
        p = p.Project(plane, vDir);
      }
      Point3d pNear = pCurv.GetClosestPointTo(p, true);
      Vector3d vSide = p - pNear;
      Vector3d vDeriv = pCurv.GetFirstDerivative(pNear);
      if (vNormal.CrossProduct(vDeriv).DotProduct(vSide) &amp;lt; 0.0)
        return true;
      else
        return false;
    }
  }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I ended up using this, kind of, but I have to click the opposite side for it to offset properly, is there anyway to counteract this?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2016 17:55:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6550444#M51293</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-08T17:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6550551#M51294</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;got some time to play, test the code below, hth.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;                            double offset = IsRightDirection(curve, pWCS, pDir.GetAsVector()) ? resValueOff.Value : -resValueOff.Value;

                            var curve1 = curve.GetOffsetCurves(-resValueOff.Value)[0] as Curve;
                            var curve2 = curve.GetOffsetCurves(resValueOff.Value)[0] as Curve;

                            if (curve1 != null &amp;amp;&amp;amp; curve2 != null)
                            {
                                var givenPoint = resPointOff.Value;

                                if (curve1.GetClosestPointTo(givenPoint, false).DistanceTo(givenPoint) &amp;lt;
                                    curve2.GetClosestPointTo(givenPoint, false).DistanceTo(givenPoint))
                                {
                                    btr.AppendEntity(curve1);
                                    tr.AddNewlyCreatedDBObject(curve1, true);
                                }
                                else
                                {
                                    btr.AppendEntity(curve2);
                                    tr.AddNewlyCreatedDBObject(curve2, true);
                                }
                            }

                            //DBObjectCollection curvCols = curve.GetOffsetCurves(offset);
                            //foreach (DBObject obj in curvCols)
                            //{
                            //    Curve subCurv = obj as Curve;
                            //    if (subCurv != null)
                            //    {
                            //        btr.AppendEntity(subCurv);
                            //        tr.AddNewlyCreatedDBObject(subCurv, true);
                            //    }
                            //}&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Sep 2016 18:28:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6550551#M51294</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-08T18:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6550645#M51295</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you can get some inspiration from &lt;A href="https://www.theswamp.org/index.php?topic=31862.msg494503#msg494503" target="_self"&gt;&lt;STRONG&gt;this&lt;/STRONG&gt;&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2016 18:53:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/6550645#M51295</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-09-08T18:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Offset polyline by pick point on side like autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/7797621#M51296</link>
      <description>&lt;P&gt;This is the shortest code and easiest way for me to make it work!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[CommandMethod("OffsetPolyLine")]&lt;/P&gt;&lt;P&gt;public void OffsetPlines(object obj)&lt;BR /&gt;{&lt;BR /&gt;Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Editor ed = doc.Editor;&lt;BR /&gt;Database db = doc.Database;&lt;BR /&gt;CivilDocument cdoc = CivilApplication.ActiveDocument;&lt;/P&gt;&lt;P&gt;//select ROW polyline prompt&lt;BR /&gt;PromptEntityOptions peo = new PromptEntityOptions("\nSelect ROW polyline:");&lt;BR /&gt;peo.SetRejectMessage("\nSelected entity is not a curve");&lt;BR /&gt;peo.AddAllowedClass(typeof(Curve), false);&lt;BR /&gt;peo.AllowNone = true;&lt;BR /&gt;PromptEntityResult per = ed.GetEntity(peo);&lt;BR /&gt;if (per.Status == PromptStatus.Cancel) return;&lt;/P&gt;&lt;P&gt;while (per.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;using (DocumentLock dl = doc.LockDocument())&lt;BR /&gt;{&lt;BR /&gt;using (Transaction tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;//prompt to specify offset distance&lt;BR /&gt;PromptDoubleOptions pdo = new PromptDoubleOptions("\nSpecify the offset distance:");&lt;BR /&gt;pdo.AllowNegative = false;&lt;BR /&gt;pdo.AllowZero = false;&lt;BR /&gt;pdo.DefaultValue = 10;&lt;BR /&gt;pdo.UseDefaultValue = true;&lt;BR /&gt;PromptDoubleResult pdr = ed.GetDouble(pdo);&lt;BR /&gt;double distance = pdr.Value;&lt;BR /&gt;if (pdr.Status == PromptStatus.Cancel) return;&lt;/P&gt;&lt;P&gt;//prompt to select side&lt;BR /&gt;PromptPointResult ppr = ed.GetPoint("\nSelect side to offset to:");&lt;BR /&gt;if (ppr.Status == PromptStatus.Cancel) return;&lt;/P&gt;&lt;P&gt;Polyline pl = (Polyline) tr.GetObject(per.ObjectId, OpenMode.ForRead);&lt;BR /&gt;Point3d cp = pl.GetClosestPointTo(ppr.Value, false);&lt;/P&gt;&lt;P&gt;DBObjectCollection offsetCurvesCollection1 = pl.GetOffsetCurves(distance);&lt;BR /&gt;DBObjectCollection offsetCurvesCollection2 = pl.GetOffsetCurves(-distance);&lt;BR /&gt;Curve curve1 = null;&lt;BR /&gt;Curve curve2 = null;&lt;BR /&gt;Point3d p1 = new Point3d();&lt;BR /&gt;Point3d p2 = new Point3d();&lt;BR /&gt;double dist1 = 0;&lt;BR /&gt;double dist2 = 0;&lt;BR /&gt;for (int i = 0; i &amp;lt; offsetCurvesCollection1.Count; i++)&lt;BR /&gt;{&lt;BR /&gt;curve1 = (Curve) offsetCurvesCollection1[i];&lt;BR /&gt;curve2 = (Curve) offsetCurvesCollection2[i];&lt;BR /&gt;p1 = curve1.GetClosestPointTo(ppr.Value, false);&lt;BR /&gt;p2 = curve2.GetClosestPointTo(ppr.Value, false);&lt;BR /&gt;dist1 = p1.DistanceTo(ppr.Value);&lt;BR /&gt;dist2 = p2.DistanceTo(ppr.Value);&lt;/P&gt;&lt;P&gt;if (dist1 &amp;lt; dist2)&lt;BR /&gt;{&lt;BR /&gt;AcadUtilities.PlaceEntityinDrawing(curve1);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;AcadUtilities.PlaceEntityinDrawing(curve2);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;tr.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;per = ed.GetEntity(peo);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2018 23:50:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/offset-polyline-by-pick-point-on-side-like-autocad/m-p/7797621#M51296</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-21T23:50:45Z</dc:date>
    </item>
  </channel>
</rss>

