明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2396|回复: 1

[学c#第一个处女贴,呵呵]断面数据采集,请高手指点下

[复制链接]
发表于 2011-9-12 11:26 | 显示全部楼层 |阅读模式
本帖最后由 gzxl 于 2011-9-12 11:29 编辑


里面判断断面起点左正右负还在琢磨中........[em0],高手来指点下

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autodesk.AutoCAD.ApplicationServices;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using Autodesk.AutoCAD.Runtime;
  8. using Autodesk.AutoCAD.DatabaseServices;
  9. using Autodesk.AutoCAD.Geometry;

  10. namespace 断面采集//gzxl
  11. {
  12.     public class Class1
  13.     {
  14.         [CommandMethod("cjdm")]
  15.         public static void cjdm()
  16.         {
  17.             var db = HostApplicationServices.WorkingDatabase;
  18.             var doc = Application.DocumentManager.GetDocument(db);
  19.             var ed = doc.Editor;
  20.             Database acCurDb = doc.Database;

  21.             Application.SetSystemVariable("osmode", 513);
  22.             PromptPointOptions prPointOptions = new PromptPointOptions("\n选择断面起点或中点:");
  23.             PromptPointResult prPointRes;
  24.             prPointRes = ed.GetPoint(prPointOptions);
  25.             if (prPointRes.Status != PromptStatus.OK)
  26.                 return;
  27.             Application.SetSystemVariable("osmode", 0);

  28.             var resEnt = ed.GetEntity("\n请选择断面线(直线):");
  29.             if (resEnt.Status != PromptStatus.OK)
  30.                 return;

  31.             using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  32.             {
  33.                 Line line = resEnt.ObjectId.GetObject(OpenMode.ForRead) as Line;
  34.                 LineSegment3d ls3d = new LineSegment3d(line.StartPoint, line.EndPoint); ;
  35.                 Line3d l3d = new Line3d(line.StartPoint, line.EndPoint);               
  36.                
  37.                 TypedValue[] acTypValAr = new TypedValue[2];
  38.                 acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "INSERT"), 0);
  39.                 acTypValAr.SetValue(new TypedValue((int)DxfCode.LayerName, "GCD"), 1);
  40.                 SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);

  41.                 PromptSelectionResult acSSPrompt;
  42.                 acSSPrompt = ed.GetSelection(acSelFtr);

  43.                 if (acSSPrompt.Status == PromptStatus.OK)
  44.                 {
  45.                     SelectionSet acSSet = acSSPrompt.Value;
  46.                     int count2 = 0;
  47.                     string LineText2 = "";
  48.                     //double[] PositionX, PositionY, PositionZ;
  49.                     double[]PositionZ;
  50.                     // 遍历选择集中的对象
  51.                     foreach (SelectedObject acSSObj in acSSet)
  52.                     {
  53.                         // 检查以确定返回的 SelectedObject 对象是有效的
  54.                         if (acSSObj != null)
  55.                         {

  56.                             Entity acEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite) as Entity;
  57.                             if (acEnt != null)
  58.                             {
  59.                                 count2++;
  60.                                 //PositionX = new Double[count2];
  61.                                 //PositionY = new Double[count2];
  62.                                 PositionZ = new Double[count2];
  63.                                 Point3d Position = ((Autodesk.AutoCAD.DatabaseServices.BlockReference)(acEnt)).Position;
  64.                                 //PositionX[count2 - 1] = Position[0];
  65.                                 //PositionY[count2 - 1] = Position[1];
  66.                                 PositionZ[count2 - 1] = Position[2];   

  67.                                 Point3d pt1 = prPointRes.Value; //断面起点
  68.                                 Point3d pt2 = l3d.GetClosestPointTo(Position).Point;

  69.                                 //double dist = pt2.DistanceTo(pt1);
  70.                                 LineText2 += (pt2 - pt1).Length + "," + PositionZ[count2 - 1].ToString() + "\n";
  71.                             }                           
  72.                         }
  73.                     }
  74.                     ed.WriteMessage(LineText2 + "\n");
  75.                 }
  76.             }
  77.         }
  78.     }
  79. }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

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

GMT+8, 2024-6-18 10:55 , Processed in 0.141634 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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