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. 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