乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 58|回复: 1

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

[复制链接]

18

主题

113

帖子

10

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
184
发表于 2011-9-12 11:26:00 | 显示全部楼层 |阅读模式

5xguomc45qu.gif

5xguomc45qu.gif


里面判断断面起点左正右负还在琢磨中........[em0],高手来指点下
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autodesk..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. }

回复

使用道具 举报

1

主题

6

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2019-12-2 20:09:00 | 显示全部楼层
牛牛牛牛
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 02:36 , Processed in 0.355871 second(s), 59 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表