.NET

Reply
Valued Contributor
Ertqwa
Posts: 88
Registered: ‎10-03-2011
Message 1 of 8 (454 Views)
Accepted Solution

Projecting a circle on default UCS

454 Views, 7 Replies
12-22-2012 06:11 AM

Hi,

 

I have a cirlce which is rotated 45 degree around the X-axis. If you look at it from the top (normal=0,0,1) it will look like an ellipse.

I want to draw a new entity (ELLIPSE) that will have the same shape/look as the circle viewed from the top, but the whole entity must have z=0.

 

Basically, exactly what the command FLATTEN does.

 

Is there a way to do this easily? Or is the only way to figure out the math behind it? Does anyone know a site where this math is explained?

 

Thank you.

Moderator
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 2 of 8 (448 Views)

Re: Projecting a circle on default UCS

12-22-2012 07:40 AM in reply to: Ertqwa

Try this code:

using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.DatabaseServices;
[assembly: CommandClass(typeof(Rivilis.CurveProject))]
namespace Rivilis
{
  public class CurveProject
  {
    [CommandMethod("CrvPrjUCS")]
    static public void CrvPrjUCS()
    {
      Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
      Database db = Application.DocumentManager.MdiActiveDocument.Database;
      PromptEntityOptions opt = new PromptEntityOptions("\nSelect a Curve: ");
      opt.SetRejectMessage("Not a Curve");
      opt.AddAllowedClass(typeof(Curve), false);
      PromptEntityResult rs = ed.GetEntity(opt);
      Matrix3d mat = ed.CurrentUserCoordinateSystem;
      Plane pln = new Plane(Point3d.Origin, Vector3d.ZAxis);
      pln.TransformBy(mat);
      if (rs.Status == PromptStatus.OK) {
        using (Transaction tr = db.TransactionManager.StartTransaction()) {
          Curve crv = tr.GetObject(rs.ObjectId, OpenMode.ForRead) as Curve;
          if (crv != null) {
            Curve newCrv = crv.GetOrthoProjectedCurve(pln);
            if (newCrv != null) {
              BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
              if (btr != null) {
                btr.AppendEntity(newCrv);
                tr.AddNewlyCreatedDBObject(newCrv, true);
              } else {
                newCrv.Dispose();
              }
            }
          }
          tr.Commit();
        }
      }
    }
  }
}

 


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

*Expert Elite*
_gile
Posts: 2,077
Registered: ‎04-29-2006
Message 3 of 8 (426 Views)

Re: Projecting a circle on default UCS

12-22-2012 02:58 PM in reply to: Alexander.Rivilis

Hi Alexander,

 

I noticed the GetOrthoProjectedCurve() and GetProjectedCurve() methods gave unexpected results with polylines (all types).

You can have a look at the GetOrthoProjectedPolyline() and GetProjectedPolyline() extension methods for Polyline, Polyline2d and Polyline3d classes in the GeometryExtension library here:

http://www.theswamp.org/index.php?topic=31865.msg373672#msg373672

Gilles Chanteau
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 8 (408 Views)

Re: Projecting a circle on default UCS

12-23-2012 02:12 AM in reply to: _gile
Have disagree this code by Alexander is working good enough with aby type of curves [CommandMethod("3ps")] public static void test3dp() { // some dummy points for test Point3dCollection points = new Point3dCollection() { new Point3d(5, 15, 10), new Point3d(25, 20, 0), new Point3d(30, 5, -10), new Point3d(10, 10, 5) }; // create closed 3dpoly create3dPoly(HostApplicationServices.WorkingDatabase, points, true); } // code borrowed from Fenton Webb, Autodesk, 15/06/2012 static public void create3dPoly(Database db,Point3dCollection points,bool closed) { Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { // Create a 3D polyline with two segments (3 points) using (Polyline3d poly3d = new Polyline3d()) { poly3d.SetDatabaseDefaults(); // Add the new object to the current space block table record using (BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite) as BlockTableRecord) { // because before adding vertexes, the polyline must be in the drawing btr.AppendEntity(poly3d); foreach (Point3d pnt in points) { // now create the vertices using (PolylineVertex3d poly3dVertex = new PolylineVertex3d(pnt)) // and add them to the 3dpoly (this adds them to the db also poly3d.AppendVertex(poly3dVertex); } } poly3d.Closed = closed; } tr.Commit(); }//end using transaction }
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Moderator
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 5 of 8 (400 Views)

Re: Projecting a circle on default UCS

12-23-2012 03:17 AM in reply to: _gile

Hi, Gilles!

You probably right, but I've tested this code with different types of polylines in AutoCAD 2013 and found no problems. Maybe you can clarify the conditions in which these problems arise?


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

*Expert Elite*
_gile
Posts: 2,077
Registered: ‎04-29-2006
Message 6 of 8 (388 Views)

Re: Projecting a circle on default UCS

12-23-2012 09:09 AM in reply to: Alexander.Rivilis

Ok, with A3013 GetOrthoProjectedCurve() seems to work as expected with Polyline entities, but I still have unexpected results with Polyline2d entities (wrong elevation).

With prior AutoCAD versions GetOrthoProjectedCurve() raised a eNotApplicable exception with Polyline entities and gave unpredictable reulst with Polyline2d entities.

Gilles Chanteau
Moderator
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 7 of 8 (383 Views)

Re: Projecting a circle on default UCS

12-23-2012 09:15 AM in reply to: _gile

_gile wrote:

Ok, with A3013 ...


We already live in the fourth millennium after Christ? :smileyhappy:


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

Valued Contributor
Ertqwa
Posts: 88
Registered: ‎10-03-2011
Message 8 of 8 (263 Views)

Re: Projecting a circle on default UCS

02-17-2013 11:46 AM in reply to: Alexander.Rivilis

It's a bit late reply, but....great ty!

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.

Ask the Community