[学c#第一个处女贴,呵呵]断面数据采集,请高手指点下
本帖最后由 gzxl 于 2011-9-12 11:29 编辑里面判断断面起点左正右负还在琢磨中........,高手来指点下
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
{
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;
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;
//PositionY = new Double;
PositionZ = new Double;
Point3d Position = ((Autodesk.AutoCAD.DatabaseServices.BlockReference)(acEnt)).Position;
//PositionX = Position;
//PositionY = Position;
PositionZ = Position;
Point3d pt1 = prPointRes.Value; //断面起点
Point3d pt2 = l3d.GetClosestPointTo(Position).Point;
//double dist = pt2.DistanceTo(pt1);
LineText2 += (pt2 - pt1).Length + "," + PositionZ.ToString() + "\n";
}
}
}
ed.WriteMessage(LineText2 + "\n");
}
}
}
}
}
牛牛牛牛
页:
[1]