Draw circle in the XY plane.

Draw circle in the XY plane.

Aravinth.Pichamani
Enthusiast Enthusiast
1,221 Views
16 Replies
Message 1 of 17

Draw circle in the XY plane.

Aravinth.Pichamani
Enthusiast
Enthusiast

AravinthPichamani_0-1731389946168.png

 

0 Likes
Accepted solutions (1)
1,222 Views
16 Replies
Replies (16)
Message 2 of 17

prem_kumar8SXZJ
Enthusiast
Enthusiast

Hi @Aravinth.Pichamani, Please provide more details on what you are trying to achieve then only we can help you with the problem.

0 Likes
Message 3 of 17

essam-salah
Collaborator
Collaborator

hi @Aravinth.Pichamani 

      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);
0 Likes
Message 4 of 17

Aravinth.Pichamani
Enthusiast
Enthusiast

i need to draw a circle with new UCS 

AravinthPichamani_0-1731398127538.png

 

0 Likes
Message 5 of 17

essam-salah
Collaborator
Collaborator

hi@Aravinth.Pichamani 

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 

 

 

essamsalah_0-1731398500227.png

 

0 Likes
Message 6 of 17

Aravinth.Pichamani
Enthusiast
Enthusiast

AravinthPichamani_0-1731398698303.png

 

0 Likes
Message 7 of 17

Aravinth.Pichamani
Enthusiast
Enthusiast

AravinthPichamani_0-1731398777406.png

 

0 Likes
Message 8 of 17

cuongtk2
Advocate
Advocate
The normal vector of a plane is a vector that is perpendicular to the plane and is commonly used to represent the orientation of the plane in three-dimensional space.
var circle = new Autodesk.AutoCAD.DatabaseServices.Circle(center, normal_custom, radius);
0 Likes
Message 9 of 17

Aravinth.Pichamani
Enthusiast
Enthusiast

AravinthPichamani_0-1731399987135.png

 

0 Likes
Message 10 of 17

Aravinth.Pichamani
Enthusiast
Enthusiast

AravinthPichamani_0-1731400695286.png

pls guide me

0 Likes
Message 11 of 17

essam-salah
Collaborator
Collaborator

@Aravinth.Pichamani 

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

0 Likes
Message 12 of 17

Aravinth.Pichamani
Enthusiast
Enthusiast

AravinthPichamani_0-1731403337918.png

 

0 Likes
Message 13 of 17

essam-salah
Collaborator
Collaborator

hi @Aravinth.Pichamani 

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

 

 

 

essamsalah_0-1731406589853.png

 

essamsalah_2-1731406832001.png

 

 

 

 

0 Likes
Message 14 of 17

_gile
Consultant
Consultant

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

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 15 of 17

essam-salah
Collaborator
Collaborator

hi @Aravinth.Pichamani 

have your problem solved?

0 Likes
Message 16 of 17

_gile
Consultant
Consultant
Accepted solution

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



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 17 of 17

Aravinth.Pichamani
Enthusiast
Enthusiast
0 Likes