start
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
cmdPickPointIn3d : IExternalCommand
{
Result Execute(ExternalCommandData commandData, messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
XYZ point_in_3d;
(PickFaceSetWorkPlaneAndPickPoint( app.ActiveUIDocument, point_in_3d))
{
TaskDialog.Show(,
+
+ PointString(point_in_3d));
Result.Succeeded;
}
{
messages = ;
Result.Failed;
}
Result.Succeeded;
}
PointString(XYZ p)
{
.Format(,
RealString(p.X),
RealString(p.Y),
RealString(p.Z));
}
PointString(UV p)
{
.Format(,
RealString(p.U),
RealString(p.V));
}
RealString( a)
{
a.ToString();
}
PickFaceSetWorkPlaneAndPickPoint(UIDocument uidoc, XYZ point_in_3d)
{
point_in_3d = ;
Document doc = uidoc.Document;
Reference r = uidoc.Selection.PickObject(
ObjectType.Face,
);
Element e = doc.get_Element(r.ElementId);
( != e)
{
PlanarFace face
= e.GetGeometryObjectFromReference(r)
PlanarFace;
(face != )
{
Plane plane = Plane(
face.Normal, face.Origin);
Transaction t = Transaction(doc);
t.Start(
+ );
SketchPlane sp = doc.Create.NewSketchPlane(
plane);
uidoc.ActiveView.SketchPlane = sp;
uidoc.ActiveView.ShowActiveWorkPlane();
{
point_in_3d = uidoc.Selection.PickPoint(
+ );
}
(OperationCanceledException)
{
}
t.RollBack();
}
}
!= point_in_3d;
}
}url:http://greatverve.cnblogs.com/p/pick-a-point-in-3d.html