.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ArcJig with 3points

4 REPLIES 4
Reply
Message 1 of 5
gilseorin
532 Views, 4 Replies

ArcJig with 3points

Hi, all!
Is it possible to create an Arc with 3 points?
With EntityJig or DrawJig?

I wrote code, but not working as autocad do.
Some help, please.

I will pay for the perfect code if you want.
gilseorin@hotmail.com

Thanks in advance.
4 REPLIES 4
Message 2 of 5
_gile
in reply to: gilseorin

Hi,

Here's a trick (current UCS plane have to be coplanar to WCS plane)

{code}using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace Circle3Points
{
public class CircleJigSample
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;

class ArcJig : EntityJig
{
Arc _arc;
Point3d _dragPoint;
Point3d _firstPoint;
Point3d _secondPoint;
Line2d _line;

public ArcJig(Arc arc, Point3d dragPoint, Point3d firstPoint, Point3d secondPoint, Line2d line)
: base(arc)
{
_arc = arc;
_dragPoint = dragPoint;
_firstPoint = firstPoint;
_secondPoint = secondPoint;
_line = line;
}

protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions jppo = new JigPromptPointOptions("\nSpecify the third point: ");
jppo.UserInputControls = (UserInputControls.Accept3dCoordinates);
PromptPointResult ppr = prompts.AcquirePoint(jppo);
if (ppr.Status == PromptStatus.OK)
{
if (ppr.Value.IsEqualTo(_dragPoint))
return SamplerStatus.NoChange;
else
{
_dragPoint = ppr.Value;
return SamplerStatus.OK;
}
}
return SamplerStatus.Cancel;
}

protected override bool Update()
{
Point3d cen;
Vector3d vecX = new Vector3d(1.0, 0.0, 0.0);
Vector3d normal = new Vector3d(0.0, 0.0, 1.0);
Point2d[] inters = _line.IntersectWith(Mediatrice(Point3dTo2d(_secondPoint), Point3dTo2d(_dragPoint)));
if (inters != null)
{
cen = new Point3d(inters[0].X, inters[0].Y, 0.0);
_arc.Center = cen;
_arc.Radius = cen.DistanceTo(_dragPoint);
if (Clockwise(_firstPoint, _secondPoint, _dragPoint))
{
_arc.StartAngle = vecX.GetAngleTo(cen.GetVectorTo(_dragPoint), normal);
_arc.EndAngle = vecX.GetAngleTo(cen.GetVectorTo(_firstPoint), normal);
}
else
{
_arc.StartAngle = vecX.GetAngleTo(cen.GetVectorTo(_firstPoint), normal);
_arc.EndAngle = vecX.GetAngleTo(cen.GetVectorTo(_dragPoint), normal);
}
}
return true;
}

public Point3d GetPoint()
{
return _dragPoint;
}
}

[CommandMethod("Test")]
public void Test()
{
Point3d pt1;
Point3d pt2;
PromptPointOptions ppo = new PromptPointOptions("\nSpecifiy the first point: ");
ppo.AllowNone = false;
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status == PromptStatus.OK)
{
pt1 = ppr.Value;
ppo.Message = "\nSpecify the second point: ";
ppo.AllowNone = false;
ppo.BasePoint = pt1;
ppo.UseBasePoint = true;
ppr = ed.GetPoint(ppo);
if (ppr.Status == PromptStatus.OK)
{
try
{
pt2 = ppr.Value;
pt1 = pt1.TransformBy(ed.CurrentUserCoordinateSystem);
pt2 = pt2.TransformBy(ed.CurrentUserCoordinateSystem);
Line2d med = Mediatrice(Point3dTo2d(pt1), Point3dTo2d(pt2));
Vector3d vec = pt1.GetVectorTo(pt2) / 2;
Arc ghost = new Arc(pt1 + vec, vec.Length, 0.0, pi);
ArcJig jig = new ArcJig(ghost, pt2, pt1, pt2, med);
PromptResult res = ed.Drag(jig);
if (res.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(ghost);
tr.AddNewlyCreatedDBObject(ghost, true);
tr.Commit();
}
}
else
ghost.Dispose();
}
catch(System.Exception ex)
{
ed.WriteMessage("\nError: " + ex.Message);
}
}
}
}

private static Line2d Mediatrice(Point2d p1, Point2d p2)
{
Vector2d vector = p1.GetVectorTo(p2);
Point2d midPt = p1 + (vector / 2);
return new Line2d(midPt, vector.TransformBy(Matrix2d.Rotation(pi / 2.0, p1)));
}

private static Point2d Point3dTo2d(Point3d pt)
{
return new Point2d(pt.X, pt.Y);
}

private static bool Clockwise(Point3d p1, Point3d p2, Point3d p3)
{
Vector3d vec1 = p1.GetVectorTo(p2);
Vector3d vec2 = p2.GetVectorTo(p3);
Vector3d norm = new Vector3d(0.0, 0.0, 1.0);
return vec1.GetAngleTo(vec2, norm) > pi;
}

private const double pi = 3.141592653589793;
}
}{code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 5
gilseorin
in reply to: gilseorin

It's cool.
Fantastic!
Thank you so much, _gile.
Email me, plz.
Message 4 of 5
_gile
in reply to: gilseorin

Here's a less verbose one (using a CircularArc3d as in your example) which works whatever the current UCS plane

{code}using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace Arc3Points
{
public class ArcJigSample
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
private const double pi = 3.141592653589793;

class ArcJig : EntityJig
{
Arc _arc;
Point3d _dragPoint;
Point3d _firstPoint;
Point3d _secondPoint;

public ArcJig(Arc arc, Point3d dragPoint, Point3d firstPoint, Point3d secondPoint)
: base(arc)
{
_arc = arc;
_dragPoint = dragPoint;
_firstPoint = firstPoint;
_secondPoint = secondPoint;
}

protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions jppo = new JigPromptPointOptions("\nSpecify the third point: ");
jppo.UserInputControls = (UserInputControls.Accept3dCoordinates);
PromptPointResult ppr = prompts.AcquirePoint(jppo);
if (ppr.Status == PromptStatus.OK)
{
if (ppr.Value.IsEqualTo(_dragPoint))
return SamplerStatus.NoChange;
else
{
_dragPoint = ppr.Value;
return SamplerStatus.OK;
}
}
return SamplerStatus.Cancel;
}

protected override bool Update()
{
CircularArc3d cArc = new CircularArc3d(_firstPoint, _secondPoint, _dragPoint);
Point3d cen = cArc.Center;
_arc.Center = cen;
_arc.Radius = cArc.Radius;
Vector3d vec1 = _firstPoint.GetVectorTo(_secondPoint);
Vector3d vec2 = _secondPoint.GetVectorTo(_dragPoint);
Vector3d norm = cArc.Normal;
_arc.Normal = norm;
Vector3d vecX = new Vector3d(1.0, 0.0, 0.0).TransformBy(Matrix3d.PlaneToWorld(norm));
double angToFirst = vecX.GetAngleTo(cen.GetVectorTo(_firstPoint), norm);
double angToDrag = vecX.GetAngleTo(cen.GetVectorTo(_dragPoint), norm);
if (vec1.GetAngleTo(vec2, norm) > pi)
{
_arc.StartAngle = angToDrag;
_arc.EndAngle = angToFirst;
}
else
{
_arc.StartAngle = angToFirst;
_arc.EndAngle = angToDrag;
}
return true;
}

public Point3d GetPoint()
{
return _dragPoint;
}
}

[CommandMethod("Test")]
public void Test()
{
Point3d pt1;
Point3d pt2;
PromptPointOptions ppo = new PromptPointOptions("\nSpecifiy the first point: ");
ppo.AllowNone = false;
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status == PromptStatus.OK)
{
pt1 = ppr.Value;
ppo.Message = "\nSpecify the second point: ";
ppo.AllowNone = false;
ppo.BasePoint = pt1;
ppo.UseBasePoint = true;
ppr = ed.GetPoint(ppo);
if (ppr.Status == PromptStatus.OK)
{
try
{
Matrix3d curUCS = ed.CurrentUserCoordinateSystem;
pt2 = ppr.Value;
pt1 = pt1.TransformBy(curUCS);
pt2 = pt2.TransformBy(curUCS);
Vector3d vec = pt1.GetVectorTo(pt2) / 2;
Arc ghost = new Arc(pt1 + vec, vec.Length, 0.0, pi);
ArcJig jig = new ArcJig(ghost, pt2, pt1, pt2);
PromptResult res = ed.Drag(jig);
if (res.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(ghost);
tr.AddNewlyCreatedDBObject(ghost, true);
tr.Commit();
}
}
else
ghost.Dispose();
}
catch (System.Exception ex)
{
ed.WriteMessage("\nError: " + ex.Message);
}
}
}
}
}
}
{code} Edited by: _gile on Sep 6, 2009 3:55 PM


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 5
SEANT61
in reply to: gilseorin

Less verbose and more versatile; you got to like that combination. Nice work gile.

************************************************************
May your cursor always snap to the location intended.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost