Author Topic: Examples  (Read 3608 times)

0 Members and 1 Guest are viewing this topic.

HAPEFT

  • Guest
Examples
« on: July 02, 2014, 10:46:58 AM »
Is anyone interested in providing some examples of using Giles geometry extensions?
I have the dll's, but can't precisely figure out how to utilize them.  My original quandary that led to
finding them was trying to figure out how to convert either a spline or ellipse to a polyline, seeing that
setting the pellipse system variable via code is ignored.

I've done multiple searches, but haven't yet found threads to fill in the knowledge.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Examples
« Reply #1 on: July 02, 2014, 02:38:45 PM »
Hi,

To convert a Spline into a Polyline, just use the AutoCAD .NET API provided Spline.ToPolyline() method (have a look at the docs for the different behaviours according to the PLINETYPE and PLINECONVERTMODE settings).

To convert an ellipse (or an elliptical arc) into a Polyline, you can use the Ellipse.ToPolyline() extension method provided in the GeometryExtensions assembly.

In both case the methods return an instance of Polyline (more accurately a Curve object with Spline.ToPolyline() method). If you want to replace the source object with the newly created one, you have to add to the source object owner and erase the source object.
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Examples
« Reply #2 on: July 02, 2014, 03:03:38 PM »
Here's a little (quick and dirty) example of the Ellipse.ToPolyline() method using:

Code - C#: [Select]
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Runtime;
  5. using GeometryExtensions;
  6.  
  7. [assembly: CommandClass(typeof(EllipseToPolylineSample.CommandMethods))]
  8.  
  9. namespace EllipseToPolylineSample
  10. {
  11.     public class CommandMethods
  12.     {
  13.         [CommandMethod("EL2PL", CommandFlags.Modal)]
  14.         public void EllipseToPolyline()
  15.         {
  16.             Document doc = Application.DocumentManager.MdiActiveDocument;
  17.             Database db = doc.Database;
  18.             Editor ed = doc.Editor;
  19.  
  20.             PromptEntityOptions peo = new PromptEntityOptions("\nSelect an ellipse: ");
  21.             peo.SetRejectMessage("Only an ellipse.");
  22.             peo.AddAllowedClass(typeof(Ellipse), true);
  23.             PromptEntityResult per = ed.GetEntity(peo);
  24.             if (per.Status != PromptStatus.OK) return;
  25.  
  26.             using (Transaction tr = db.TransactionManager.StartTransaction())
  27.             {
  28.                 BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  29.                 Ellipse ellipse = (Ellipse)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
  30.                 Polyline pline = ellipse.ToPolyline();
  31.                 btr.AppendEntity(pline);
  32.                 tr.AddNewlyCreatedDBObject(pline, true);
  33.                 ellipse.Erase();
  34.                 tr.Commit();
  35.             }
  36.         }
  37.     }
  38. }
  39.  
Speaking English as a French Frog

HAPEFT

  • Guest
Re: Examples
« Reply #3 on: July 07, 2014, 09:55:53 AM »
Thank you thank you thank you . . .
quick and dirty was exactly what I wanted.  specifically line 30.

Thank you for the spline reference.  I did not know there was a .net provided conversion.
My interest in the spline was looking for a work around for the ellipse, most specifically an elliptical arc.
I thought I read somewhere that the polyline to ellipse would return the entire ellipse, so I
was looking for a workaround, hence the spline.  At least I now have something I can try.

Thank you again.  Examples are like pictures.  They tell a whole lot more.