.NET

## .NET

Valued Contributor
Posts: 95
Registered: ‎04-04-2012
Message 1 of 7 (1,278 Views)

# Create Arc with StartPoint EndPoint Radius?

1278 Views, 6 Replies
02-07-2013 04:09 AM

[Managed ObjectARX 2007 with C#]

I am trying to create an arc with start point, end point, and radius.

So that if the arc gets drawn, I going to use the center point.

Well, I guess I can use "SendStringToExecute()" or "SendCommand()" and "ObjectAppended" eventhandler to get the arc object.

But this approach seems bit messy, so I am wondering if there is any other simple way.

Valued Mentor
Posts: 450
Registered: ‎04-11-2010
Message 2 of 7 (1,269 Views)

# Re: Create Arc with StartPoint EndPoint Radius?

02-07-2013 06:25 AM in reply to: dynamicscope

Hi,

The problem is that the arc constructor use angles intead points, so you have to calculate the angles from the points, check this link: http://www.theswamp.org/index.php?topic=40382.msg456904#msg456904

Gaston Nunez

Moderator
Posts: 1,398
Registered: ‎04-09-2008
Message 3 of 7 (1,264 Views)

# Re: Create Arc with StartPoint EndPoint Radius?

02-07-2013 07:05 AM in reply to: gasty1001

Creating of arc with startpoint, endpoint and radius can not be unique. Such arcs can be either two or none.

Пожалуйста не забывайте про Утвердить в качестве решения и Баллы
Please remember to Accept as Solution and Kudos

Valued Contributor
Posts: 95
Registered: ‎04-04-2012
Message 4 of 7 (1,241 Views)

# Re: Create Arc with StartPoint EndPoint Radius?

02-07-2013 05:06 PM in reply to: Alexander.Rivilis

As you would know AutoCAD already provides such feature. (Drawing Arc with Start point + End point + Radius).

So I was wondering if there is any API I can use.

It looks like I have to manually calculate angles and stuff.

Hmm.....

*Expert Elite*
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 7 (1,231 Views)

# Re: Create Arc with StartPoint EndPoint Radius?

02-07-2013 11:38 PM in reply to: dynamicscope

Then you can to look at acedCmd and use the same command promts

as per as in ARC command , just an idea

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Moderator
Posts: 1,398
Registered: ‎04-09-2008
Message 6 of 7 (1,226 Views)

# Re: Create Arc with StartPoint EndPoint Radius?

02-08-2013 01:50 AM in reply to: dynamicscope

OK. Try this code (as usually minimum error checking done):

```[CommandMethod("ARC2PR", CommandFlags.Modal)]
public static void Arc2PointsRadius()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptPointResult pRes1 = ed.GetPoint("\nFirst point: ");
if (pRes1.Status != PromptStatus.OK) return;
PromptPointResult pRes2 = ed.GetPoint("\nSecond point: ");
if (pRes2.Status != PromptStatus.OK) return;
PromptDistanceOptions prDist =
prDist.BasePoint = pRes2.Value;
prDist.UseBasePoint = true;
PromptDoubleResult rRes = ed.GetDistance(prDist);
if (rRes.Status != PromptStatus.OK) return;
Matrix3d ucsMat = ed.CurrentUserCoordinateSystem;
Vector3d vNormal = ucsMat.CoordinateSystem3d.Zaxis;
Point3d pStart = pRes1.Value.TransformBy(ucsMat); // Start point in WCS
Point3d pEnd = pRes2.Value.TransformBy(ucsMat); // End point in WCS
//  Finding center point of arc.
CircularArc3d circ1 = new CircularArc3d(pStart, vNormal, rRes.Value);
CircularArc3d circ2 = new CircularArc3d(pEnd, vNormal, rRes.Value);
Point3d[] pts = circ1.IntersectWith(circ2);
circ1.Dispose(); circ2.Dispose();
if (pts.Length < 2) {
ed.WriteMessage("\nInvalid arguments"); return;
}
Point3d pCenter = pts[0];
Vector3d v1 = pStart - pCenter, v2 = pEnd - pCenter;
if (v1.CrossProduct(v2).DotProduct(vNormal) < 0) {
pCenter = pts[1];
}
CircularArc3d cCirc = new CircularArc3d(pCenter, vNormal, rRes.Value);
double parStart = cCirc.GetParameterOf(pStart);
double parEnd   = cCirc.GetParameterOf(pEnd);
double parMid = (parStart + parEnd) * 0.5;
Point3d pMid = cCirc.EvaluatePoint(parMid);
cCirc.Dispose();
CircularArc3d cArc = new CircularArc3d(pStart, pMid, pEnd);
double angle =
cArc.ReferenceVector.AngleOnPlane(new Plane(cArc.Center,cArc.Normal));
Arc arc =
new Arc(cArc.Center, cArc.Normal,
cArc.Radius, cArc.StartAngle + angle,  cArc.EndAngle + angle);
cArc.Dispose();
using (Transaction tr = doc.TransactionManager.StartTransaction()) {
BlockTableRecord btr =
tr.GetObject(doc.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(arc);
tr.Commit();
}
}
```

Пожалуйста не забывайте про Утвердить в качестве решения и Баллы
Please remember to Accept as Solution and Kudos

Valued Contributor
Posts: 95
Registered: ‎04-04-2012
Message 7 of 7 (1,176 Views)

# Re: Create Arc with StartPoint EndPoint Radius?

02-13-2013 01:36 AM in reply to: Alexander.Rivilis

WOW!!!

Didn't expect the answer code.

It works great for me and it solves my problem.

Plus, I learned a lot from your code.

There are so many APIs I can utilize in ObjectARX.

Awesome!!

Thank you always~

### You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

### Need installation help?

Start with some of our most frequented solutions to get help installing your software.

### Maintenance Subscription Resources

Upgrading to a 2015 product? Make sure to check these out 1st!