Revit API选择三维视图上一点
2014-02-25 18:21
363 查看
start
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdPickPointIn3d : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
XYZ point_in_3d;
if (PickFaceSetWorkPlaneAndPickPoint( app.ActiveUIDocument, out point_in_3d))
{
TaskDialog.Show("3D Point Selected",
"3D point picked on the plane"
+ " defined by the selected face: "
+ PointString(point_in_3d));
return Result.Succeeded;
}
else
{
messages = "3D point selection failed";
return Result.Failed;
}
return Result.Succeeded;
}
string PointString(XYZ p)
{
return string.Format("({0},{1},{2})",
RealString(p.X),
RealString(p.Y),
RealString(p.Z));
}
string PointString(UV p)
{
return string.Format("({0},{1})",
RealString(p.U),
RealString(p.V));
}
string RealString(double a)
{
return a.ToString("0.##");
}
bool PickFaceSetWorkPlaneAndPickPoint(UIDocument uidoc, out XYZ point_in_3d)
{
point_in_3d = null;
Document doc = uidoc.Document;
Reference r = uidoc.Selection.PickObject(
ObjectType.Face,
"Please select a planar face to define work plane");
Element e = doc.get_Element(r.ElementId);
if (null != e)
{
PlanarFace face
= e.GetGeometryObjectFromReference(r)
as PlanarFace;
if (face != null)
{
Plane plane = new Plane(
face.Normal, face.Origin);
Transaction t = new Transaction(doc);
t.Start("Temporarily set work plane"
+ " to pick point in 3D");
SketchPlane sp = doc.Create.NewSketchPlane(
plane);
uidoc.ActiveView.SketchPlane = sp;
uidoc.ActiveView.ShowActiveWorkPlane();
try
{
point_in_3d = uidoc.Selection.PickPoint(
"Please pick a point on the plane"
+ " defined by the selected face");
}
catch (OperationCanceledException)
{
}
t.RollBack();
}
}
return null != point_in_3d;
}
}url:http://greatverve.cnblogs.com/p/pick-a-point-in-3d.html
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdPickPointIn3d : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
XYZ point_in_3d;
if (PickFaceSetWorkPlaneAndPickPoint( app.ActiveUIDocument, out point_in_3d))
{
TaskDialog.Show("3D Point Selected",
"3D point picked on the plane"
+ " defined by the selected face: "
+ PointString(point_in_3d));
return Result.Succeeded;
}
else
{
messages = "3D point selection failed";
return Result.Failed;
}
return Result.Succeeded;
}
string PointString(XYZ p)
{
return string.Format("({0},{1},{2})",
RealString(p.X),
RealString(p.Y),
RealString(p.Z));
}
string PointString(UV p)
{
return string.Format("({0},{1})",
RealString(p.U),
RealString(p.V));
}
string RealString(double a)
{
return a.ToString("0.##");
}
bool PickFaceSetWorkPlaneAndPickPoint(UIDocument uidoc, out XYZ point_in_3d)
{
point_in_3d = null;
Document doc = uidoc.Document;
Reference r = uidoc.Selection.PickObject(
ObjectType.Face,
"Please select a planar face to define work plane");
Element e = doc.get_Element(r.ElementId);
if (null != e)
{
PlanarFace face
= e.GetGeometryObjectFromReference(r)
as PlanarFace;
if (face != null)
{
Plane plane = new Plane(
face.Normal, face.Origin);
Transaction t = new Transaction(doc);
t.Start("Temporarily set work plane"
+ " to pick point in 3D");
SketchPlane sp = doc.Create.NewSketchPlane(
plane);
uidoc.ActiveView.SketchPlane = sp;
uidoc.ActiveView.ShowActiveWorkPlane();
try
{
point_in_3d = uidoc.Selection.PickPoint(
"Please pick a point on the plane"
+ " defined by the selected face");
}
catch (OperationCanceledException)
{
}
t.RollBack();
}
}
return null != point_in_3d;
}
}url:http://greatverve.cnblogs.com/p/pick-a-point-in-3d.html
相关文章推荐
- 高效jQuery
- PHP性能优化工具–xhprof安装
- 寻找最大的k个数
- 解决jquery mobile的header和footer在点击屏幕的时候消失的办法
- 计算机基本概念
- URAL 1586. Threeprime Numbers
- ArrayAdapter
- Android Studio 快捷键盘
- libevent event_set函数与event_add函数解析 [SYM]
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read
- 五大常用算法之五:分支限界法
- OpenCV cvDFT 傅里叶变换
- ios UIButton得 几种触发方式
- 五大常用算法之四:回溯法
- 记录我的旅程
- zoj2967 Colorful Rainbows(凸包 排序 栈)
- java--有关前台展示图片流的用法
- 排列平方数
- iOS ARC相关
- 五大常用算法之三:贪心算法