ADN Open CIS
Сообщество программистов Autodesk в СНГ

12/10/2013

Проецирование кривой на поверхность

Ниже пример кода проецирования отрезка на цилиндрическую поверхность. Создаётся цилиндрическая поверхность и отрезок, а затем отрезок проецируется на поверхность. Проекция добавляется в базу чертежа.

Код - C#: [Выделить]
  1. [CommandMethod("ProjectLine")]
  2. static public void ProjectLineMethod()
  3. {
  4.   Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  5.   Document doc = Application.DocumentManager.MdiActiveDocument;
  6.   Database db = doc.Database;
  7.  
  8.   ObjectId surfaceId = ObjectId.Null;
  9.   using (Transaction tr
  10.                   = db.TransactionManager.StartTransaction())
  11.   {
  12.     BlockTable bt = tr.GetObject(
  13.                                     db.BlockTableId,
  14.                                     OpenMode.ForRead
  15.                                 ) as BlockTable;
  16.  
  17.     BlockTableRecord ms = tr.GetObject(
  18.                             bt[BlockTableRecord.ModelSpace],
  19.                             OpenMode.ForWrite
  20.                                 ) as BlockTableRecord;
  21.  
  22.     Arc arc = new Arc(  Point3d.Origin,
  23.                         10.0,
  24.                         Math.PI * 0.5,
  25.                         Math.PI * 1.5
  26.                     );
  27.     ms.AppendEntity(arc);
  28.     tr.AddNewlyCreatedDBObject(arc, true);
  29.  
  30.     Line line = new Line(   Point3d.Origin,
  31.                             new Point3d(0.0, 10.0, 0.0)
  32.                         );
  33.     ms.AppendEntity(line);
  34.     line.ColorIndex = 2;
  35.     tr.AddNewlyCreatedDBObject(line, true);
  36.  
  37.     Profile3d profile = new Profile3d(arc);
  38.     Vector3d direction = new Vector3d(0, 0, 20.0);
  39.  
  40.     SweepOptions sweepOptions = new SweepOptions();
  41.  
  42.     surfaceId =
  43.         Autodesk.AutoCAD.DatabaseServices.Surface.CreateExtrudedSurface
  44.         (
  45.             profile,
  46.             direction,
  47.             sweepOptions,
  48.             true
  49.         );
  50.     Autodesk.AutoCAD.DatabaseServices.Surface surface
  51.         = tr.GetObject
  52.             (
  53.                 surfaceId,
  54.                 OpenMode.ForWrite
  55.             ) as Autodesk.AutoCAD.DatabaseServices.Surface;
  56.  
  57.     Entity[] projectedEntities
  58.         = surface.ProjectOnToSurface(line, Vector3d.XAxis.Negate());
  59.     if (projectedEntities != null)
  60.     {
  61.         foreach (Entity ent in projectedEntities)
  62.         {
  63.             ed.WriteMessage(
  64.                 String.Format("Примитив-проекция: {0}",
  65.                                 ent.GetType().ToString()));
  66.             ent.ColorIndex = 1;
  67.             ms.AppendEntity(ent);
  68.             tr.AddNewlyCreatedDBObject(ent, true);
  69.         }
  70.     }
  71.     tr.Commit();
  72.   }
  73. }

 

Источник: http://adndevblog.typepad.com/autocad/2013/02/projection-of-a-curve-on-a-surface.html

 

Обсуждение: http://adn-cis.org/forum/index.php?topic=247

Опубликовано 12.10.2013