.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Create Arc with StartPoint EndPoint Radius?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
[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.
Solved! Go to Solution.
Re: Create Arc with StartPoint EndPoint Radius?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.msg4
Gaston Nunez
Re: Create Arc with StartPoint EndPoint Radius?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Create Arc with StartPoint EndPoint Radius?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.....
Re: Create Arc with StartPoint EndPoint Radius?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Then you can to look at acedCmd and use the same command promts
as per as in ARC command , just an idea
C6309D9E0751D165D0934D0621DFF27919
Re: Create Arc with StartPoint EndPoint Radius?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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 =
new PromptDistanceOptions("\nRadius: ");
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.AddNewlyCreatedDBObject(arc, true);
tr.Commit();
}
}
Re: Create Arc with StartPoint EndPoint Radius?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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~ ![]()




