Hi @Aravinth.Pichamani, Please provide more details on what you are trying to achieve then only we can help you with the problem.
var center = new Autodesk.AutoCAD.Geometry.Point3d(3, 5, 5);
var normal_XY_Plane = Autodesk.AutoCAD.Geometry.Vector3d.ZAxis;
var normal_custom = new Autodesk.AutoCAD.Geometry.Vector3d(3, 4, 5);
var radius = 10d;
var circle = new Autodesk.AutoCAD.DatabaseServices.Circle(center, normal_XY_Plane, radius);
i need to draw a circle with new UCS
have u tried any thing and failed, what is your problem exactly, the below pic shows the the vector v nad c1, c2 as line start/end points
pls guide me
if the input is the Line (center line) why we do transformation?, just the vector of the CL and a point lies on that line,
and u can use editor.CurrentUserCoordinateSystem to get current user coord system.
anyway if u can provide us with the dwg file and draw the input in a specific layer and the output u want in another layer it might help
here is what i understood, and the way it worked for me:
using cDB = Autodesk.Civil.DatabaseServices;
using P3D = Autodesk.AutoCAD.Geometry.Point3d;
using aApp = Autodesk.AutoCAD.ApplicationServices;
...
// get current doc and db
var aDoc = aApp.Application.DocumentManager.MdiActiveDocument;
var db = aDoc.Database;
var ed = aDoc.Editor;
// main start/end points (center line)
var p1 = new P3D(5, 5, 5); // random point
var p2 = new P3D(30, 25, 8); // random point
// distances on main line
double d1 = 10d, d2 = 20d; // for points m1, m2
// transaction
using (var tr = db.TransactionManager.StartTransaction())
{
// get current model space
var bt = tr.GetObject(db.BlockTableId, aDB.OpenMode.ForWrite) as aDB.BlockTable;
var btr = tr.GetObject(bt[aDB.BlockTableRecord.ModelSpace], aDB.OpenMode.ForWrite) as aDB.BlockTableRecord;
// draw main line (CL):
var cl = new aDB.Line(p1, p2);
// main line vector:
var v = p1.GetVectorTo(p2).GetNormal();
// calc any point at CL (m1, m2):
var v1 = v * d1;
var v2 = v * d2;
var m1 = new P3D(p1.X + v1.X, p1.Y + v1.Y, p1.Z + v2.Z);
var m2 = new P3D(p1.X + v2.X, p1.Y + v2.Y, p1.Z + v2.Z);
// draw circles
var circle_1 = new aDB.Circle(p1, v, radius: 10);
var circle_2 = new aDB.Circle(m1, v, radius: 12);
var circle_3 = new aDB.Circle(m2, v, radius: 14);
// add to current drawings
btr.AppendEntity(cl);
btr.AppendEntity(circle_1);
btr.AppendEntity(circle_2);
btr.AppendEntity(circle_3);
tr.AddNewlyCreatedDBObject(cl, true);
tr.AddNewlyCreatedDBObject(circle_1, true);
tr.AddNewlyCreatedDBObject(circle_2, true);
tr.AddNewlyCreatedDBObject(circle_3, true);
// apply changes
tr.Commit();
}
Hi,
Here's an example you can use as inspiration.
[CommandMethod("DRAW3DCIRCLE")]
public static void Draw3dCircle()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
// Prompt the user for the circle center
var ppo = new PromptPointOptions("\nSpecify the circle center: ");
var ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
return;
var center = ppr.Value;
// Prompt the user for a point in the circle normal direction
ppo.Message = "\nSpecify a point in the circle normal direction: ";
ppo.BasePoint = center;
ppo.UseBasePoint = true;
ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
return;
var normal = center.GetVectorTo(ppr.Value);
// Prompt the user for the circle radius
var pdo = new PromptDistanceOptions("\nSpecify the circle radius: ");
pdo.BasePoint = center;
pdo.UseBasePoint = true;
var pdr = ed.GetDistance(pdo);
if (pdr.Status != PromptStatus.OK)
return;
double radius = pdr.Value;
using (var tr = db.TransactionManager.StartTransaction())
{
// Create a Circle instance from the user inputs
// Both center and normal have to be transformed from current UCS to WCS
var circle = new Circle(
center.TransformBy(ed.CurrentUserCoordinateSystem),
normal.TransformBy(ed.CurrentUserCoordinateSystem),
radius);
// Add the circle to the current space
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
curSpace.AppendEntity(circle);
tr.AddNewlyCreatedDBObject(circle, true);
tr.Commit();
}
}
have your problem solved?
If you want to honor the current UCS as the CIRCLE native command does, you can simply transform the newly created circle with the Editor.CurrentCoordinateSystem matrix.
[CommandMethod("DRAWCIRCLEINUCS")]
public static void DrawCircleInUCS()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
// Prompt the user for the circle center
var ppo = new PromptPointOptions("\nSpecify the circle center: ");
var ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
return;
var center = ppr.Value;
// Prompt the user for the circle radius
var pdo = new PromptDistanceOptions("\nSpecify the circle radius: ");
pdo.BasePoint = center;
pdo.UseBasePoint = true;
var pdr = ed.GetDistance(pdo);
if (pdr.Status != PromptStatus.OK)
return;
double radius = pdr.Value;
using (var tr = db.TransactionManager.StartTransaction())
{
// Create a Circle instance from the user inputs
var circle = new Circle(center, Vector3d.ZAxis, radius);
// Transform the circle froim WCS to UCS
circle.TransformBy(ed.CurrentUserCoordinateSystem);
// Add the circle to the current space
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
curSpace.AppendEntity(circle);
tr.AddNewlyCreatedDBObject(circle, true);
tr.Commit();
}
}