.NET

## .NET

Active Member
Posts: 6
Registered: ‎09-25-2012
Message 1 of 3 (336 Views)

# Creating a polyline using distances between points.

336 Views, 2 Replies
09-25-2012 08:42 AM

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.AddVertex ( use code equivalent of  New Point2d = @10.5<0 from point at 0 index)

Valued Mentor
Posts: 370
Registered: ‎05-06-2012
Message 2 of 3 (323 Views)

# Re: Creating a polyline using distances between points.

09-25-2012 09:42 AM in reply to: baw6718

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;

{
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 );
}

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 ) ) );
}
}
}```

*Expert Elite*
Posts: 862
Registered: ‎04-27-2009
Message 3 of 3 (318 Views)

# Re: Creating a polyline using distances between points.

09-25-2012 09:56 AM in reply to: baw6718

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.

Recently Solved