明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 680|回复: 0

[Kean专集] 【转载】C# 沿路径阵列实例

[复制链接]
发表于 2022-5-23 17:16 | 显示全部楼层 |阅读模式
  1. [CommandMethod("AAP")]
  2.             public void CreateAssocArrayPath()
  3.             {
  4.                 Database db =
  5.                   Application.DocumentManager.MdiActiveDocument.Database;
  6.                 Transaction tr =
  7.                   db.TransactionManager.StartTransaction();
  8.                 using (tr)
  9.                 {
  10.                     BlockTable bt =
  11.                       (BlockTable)tr.GetObject(
  12.                         db.BlockTableId, OpenMode.ForRead
  13.                       );
  14.                     BlockTableRecord btr =
  15.                       (BlockTableRecord)tr.GetObject(
  16.                         bt[BlockTableRecord.ModelSpace],
  17.                         OpenMode.ForWrite
  18.                       );
  19.                     // Add profile entities: a Circle and a Line
  20.                     Circle cir =
  21.                       new Circle(
  22.                         new Point3d(-10, 0, 0),
  23.                         new Vector3d(0, 0, 1),
  24.                         1.0
  25.                       );
  26.                     cir.ColorIndex = 3; // Green
  27.                     btr.AppendEntity(cir);
  28.                     tr.AddNewlyCreatedDBObject(cir, true);
  29.                     Line ln =
  30.                       new Line(
  31.                         new Point3d(-11, -1, 0),
  32.                         new Point3d(-9, 1, 0)
  33.                       );
  34.                     ln.ColorIndex = 3; // Green
  35.                     btr.AppendEntity(ln);
  36.                     tr.AddNewlyCreatedDBObject(ln, true);
  37.                     // Add path entity: a Spline, in this case
  38.                     double fitTol = 0.0;
  39.                     int order = 4;
  40.                     // An array of doubles to define the points
  41.                     // in our spline
  42.                     double[] ptAr =
  43.                       new double[]{
  44.             -6.8447, 0.9430,  0,
  45.             -5.1409, -3.0562, 0,
  46.             -2.4095, 2.1049,  0,
  47.             3.4590, -3.9479, 0,
  48.             7.1370, 6.3472,  0
  49.                       };
  50.                     // We'll add the points to a collection
  51.                     Point3dCollection pts = new Point3dCollection();
  52.                     for (int i = 0, j = 0; i < ptAr.Length / 3; i++)
  53.                     {
  54.                         pts.Add(new Point3d(ptAr[j++], ptAr[j++], ptAr[j++]));
  55.                     }
  56.                     // Create the spline path and add it to the database
  57.                     Spline sp = new Spline(pts, order, fitTol);
  58.                     btr.AppendEntity(sp);
  59.                     tr.AddNewlyCreatedDBObject(sp, true);
  60.                     // Offset the Circle, Line and Spline by a fixed amount
  61.                     Matrix3d offset =
  62.                       Matrix3d.Displacement(new Vector3d(60, 10, 0));
  63.                     cir.TransformBy(offset);
  64.                     ln.TransformBy(offset);
  65.                     sp.TransformBy(offset);
  66.                     ObjectIdCollection srcEnts = new ObjectIdCollection();
  67.                     srcEnts.Add(cir.ObjectId);
  68.                     srcEnts.Add(ln.ObjectId);
  69.                     // Take the base point as the center of our Circle
  70.                     VertexRef basePt = new VertexRef(cir.Center);
  71.                     // Set some variables to define parameters for our path
  72.                     int itemCount = 6;
  73.                     double itemSpacing =
  74.                       sp.GetDistanceAtParameter(sp.EndParam) / itemCount;
  75.                     double rowSpacing = 0.0;
  76.                     double levelSpacing = 0.0;
  77.                     int rowCount = 0;
  78.                     int levelCount = 0;
  79.                     double rowElevation = 0.0;
  80.                     // Create the parameters for our associative path array
  81.                     //为关联路径数组创建参数
  82.                     AssocArrayPathParameters pars =
  83.                       new AssocArrayPathParameters(
  84.                         itemSpacing,
  85.                         rowSpacing,
  86.                         levelSpacing,
  87.                         itemCount,
  88.                         rowCount,
  89.                         levelCount,
  90.                         rowElevation
  91.                       );
  92.                     pars.Method =
  93.                       AssocArrayPathParameters.MethodType.Measure;
  94.                     pars.Path = new EdgeRef(sp);
  95.                     // Create the associative array itself
  96.                     AssocArray array =
  97.                       AssocArray.CreateArray(
  98.                         srcEnts,
  99.                         basePt,
  100.                         pars
  101.                       );
  102.                     // Evaluate the array
  103.                     AssocManager.EvaluateTopLevelNetwork(db, null, 0);
  104.                     tr.Commit();
  105.                 }
  106.             }


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-28 20:15 , Processed in 3.008482 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表