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

Projecting a circle on default UCS

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Ertqwa
1324 Views, 7 Replies

Projecting a circle on default UCS

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.

7 REPLIES 7
Message 2 of 8
Alexander.Rivilis
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();
        }
      }
    }
  }
}

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 8
_gile
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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 8
Hallex
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
Message 5 of 8
Alexander.Rivilis
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?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 6 of 8
_gile
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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 8
Alexander.Rivilis
in reply to: _gile


@_gile wrote:

Ok, with A3013 ...


We already live in the fourth millennium after Christ? Smiley Happy

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 8 of 8
Ertqwa
in reply to: Alexander.Rivilis

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

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report