- 积分
- 26747
- 明经币
- 个
- 注册时间
- 2007-4-24
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 gzxl 于 2011-9-12 11:29 编辑
里面判断断面起点左正右负还在琢磨中........[em0],高手来指点下
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- namespace 断面采集//gzxl
- {
- public class Class1
- {
- [CommandMethod("cjdm")]
- public static void cjdm()
- {
- var db = HostApplicationServices.WorkingDatabase;
- var doc = Application.DocumentManager.GetDocument(db);
- var ed = doc.Editor;
- Database acCurDb = doc.Database;
- Application.SetSystemVariable("osmode", 513);
- PromptPointOptions prPointOptions = new PromptPointOptions("\n选择断面起点或中点:");
- PromptPointResult prPointRes;
- prPointRes = ed.GetPoint(prPointOptions);
- if (prPointRes.Status != PromptStatus.OK)
- return;
- Application.SetSystemVariable("osmode", 0);
- var resEnt = ed.GetEntity("\n请选择断面线(直线):");
- if (resEnt.Status != PromptStatus.OK)
- return;
- using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
- {
- Line line = resEnt.ObjectId.GetObject(OpenMode.ForRead) as Line;
- LineSegment3d ls3d = new LineSegment3d(line.StartPoint, line.EndPoint); ;
- Line3d l3d = new Line3d(line.StartPoint, line.EndPoint);
-
- TypedValue[] acTypValAr = new TypedValue[2];
- acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "INSERT"), 0);
- acTypValAr.SetValue(new TypedValue((int)DxfCode.LayerName, "GCD"), 1);
- SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);
- PromptSelectionResult acSSPrompt;
- acSSPrompt = ed.GetSelection(acSelFtr);
- if (acSSPrompt.Status == PromptStatus.OK)
- {
- SelectionSet acSSet = acSSPrompt.Value;
- int count2 = 0;
- string LineText2 = "";
- //double[] PositionX, PositionY, PositionZ;
- double[]PositionZ;
- // 遍历选择集中的对象
- foreach (SelectedObject acSSObj in acSSet)
- {
- // 检查以确定返回的 SelectedObject 对象是有效的
- if (acSSObj != null)
- {
- Entity acEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite) as Entity;
- if (acEnt != null)
- {
- count2++;
- //PositionX = new Double[count2];
- //PositionY = new Double[count2];
- PositionZ = new Double[count2];
- Point3d Position = ((Autodesk.AutoCAD.DatabaseServices.BlockReference)(acEnt)).Position;
- //PositionX[count2 - 1] = Position[0];
- //PositionY[count2 - 1] = Position[1];
- PositionZ[count2 - 1] = Position[2];
- Point3d pt1 = prPointRes.Value; //断面起点
- Point3d pt2 = l3d.GetClosestPointTo(Position).Point;
- //double dist = pt2.DistanceTo(pt1);
- LineText2 += (pt2 - pt1).Length + "," + PositionZ[count2 - 1].ToString() + "\n";
- }
- }
- }
- ed.WriteMessage(LineText2 + "\n");
- }
- }
- }
- }
- }
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|