Hello I am new to the .Net api. I am aware of creating a polyline and using .AddVertexAt() to give the points, my question is if I want to create a polyline in acad I generally will pick a point and then type out @10.5<0 or something similar of that nature to pick my next point. Is it possible to add vertices to a polyline in .Net giving it the distance and angle of one point2d to the next point2d?
Example:
acPoly.AddVertexAt(0, New Point2d(0,0),0,0,0)
acPoly.AddvertexAt(0, New Point2d(1,0),0,0,0)
but instead?
acPoly.AddVertexAt(0, New Point2d(0,0),0,0,0)
acPoly.AddVertex ( use code equivalent of New Point2d = @10.5<0 from point at 0 index)
Solved! Go to Solution.
Solved by DiningPhilosopher. Go to Solution.
Here's a few C# extension methods for Point3d that compute polar and spherical points relative to a given Point3d.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Autodesk.AutoCAD.Geometry { public static class AcGeExtensions { /// 2D Polar specificiation (distance/angle) public static Point3d GetPointAt( this Point3d basepoint, double distance, double AngleInXYPlane ) { return new Point3d( basepoint.X + ( distance * Math.Cos( AngleInXYPlane ) ), basepoint.Y + ( distance * Math.Sin( AngleInXYPlane ) ), basepoint.Z ); } /// Spherical Coordinate (radius/phi/theta) public static Point3d GetPointAt( this Point3d center, double radius, double phi, double theta ) { double phicos = Math.Cos( phi ); return new Point3d( center.X + ( radius * phicos * Math.Cos( theta ) ), center.Y + ( radius * phicos * Math.Sin( theta ) ), center.Z + ( radius * Math.Sin( phi ) ) ); } } }
It will depend on how you collect user input.
If you write code to get user input as a text string like "@10<0", then you have to first validate the text string to make sure it is in expected format and then you need to parse it into a number as distance and a number as angle. Then you can calculate the point, based on previous point, as shown in the other reply.
However, AutoCAD .NET API provides a built-in way to get point, which allows user to pick point, or enter point iin the standard AutoCAD input format (i.e. like "@10<0"). You do not need to do anything, the method returns the point. What the the magic method? it is:
Editor.GetPoint(PromptPointOptions options)
When you call this method with UseBasePoint option being true and BasePoint being specified, user can either pick a point or enter "@10<0" at command line. The method will give you a point back, spare you from doing geometric calculation.