internal static bool PickPoint(UIDocument doc, string prompt, out XYZ point, ObjectSnapTypes snapSettings = DefaultSnapTypes) { point = null; try { point = doc.Selection.PickPoint(snapSettings, prompt + "Please pick a point on the current work plane"); } catch (OperationCanceledException) { } return(null != point); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements) { try { m_application = commandData.Application; m_document = m_application.ActiveUIDocument; if (m_document.Document.IsFamilyDocument) { m_CreationBase = m_document.Document.FamilyCreate; } else { m_CreationBase = m_document.Document.Create; } //Pick a face from UI, create a new sketch plane via the face and set it to the current view. Reference faceRef = m_document.Selection.PickObject(ObjectType.Face, new PlanarFaceFilter(m_document.Document), "Please pick a planar face to set the work plane. ESC for cancel."); GeometryObject geoObject = m_document.Document.GetElement(faceRef).GetGeometryObjectFromReference(faceRef); PlanarFace planarFace = geoObject as PlanarFace; SketchPlane faceSketchPlane = CreateSketchPlane(planarFace.FaceNormal, planarFace.Origin); if (faceSketchPlane != null) { Transaction changeSketchPlane = new Transaction(m_document.Document, "Change Sketch Plane."); changeSketchPlane.Start(); m_document.Document.ActiveView.SketchPlane = faceSketchPlane; m_document.Document.ActiveView.ShowActiveWorkPlane(); changeSketchPlane.Commit(); } // Pick point from current work plane with snaps. ObjectSnapTypes snapType = ObjectSnapTypes.Centers | ObjectSnapTypes.Endpoints | ObjectSnapTypes.Intersections | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Nearest | ObjectSnapTypes.WorkPlaneGrid; XYZ point = m_document.Selection.PickPoint(snapType, "Please pick a point to place component."); // Create a model curve by a circle with picked point as center. Transaction createModelCurve = new Transaction(m_document.Document, "Create a circle."); createModelCurve.Start(); Curve circle = Arc.Create(point, 5, 0, Math.PI * 2, faceSketchPlane.GetPlane().XVec, faceSketchPlane.GetPlane().YVec); m_CreationBase.NewModelCurve(circle, faceSketchPlane); createModelCurve.Commit(); return(Result.Succeeded); } catch (Exceptions.OperationCanceledException) { // Selection Cancelled. For picking face and picking point. return(Result.Cancelled); } catch (System.Exception ex) { // If any error, give error information and return failed message = ex.Message; return(Result.Failed); } }
internal static bool PickPoint(UIDocument doc, string prompt, out XYZ point, ObjectSnapTypes snapSettings = DefaultSnapTypes) { point = null; View view = null; do { view = doc.ActiveView; try { point = doc.Selection.PickPoint(snapSettings, prompt + "Please pick a point on the current work plane"); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { } }while (doc.ActiveView.Id != view.Id); return(null != point); }
public void PickPoint(UIDocument uidoc, Application app) { View activeView = uidoc.ActiveView; SketchPlane sketch = activeView.SketchPlane; ObjectSnapTypes snapTypes = ObjectSnapTypes.Points | ObjectSnapTypes.Nearest | ObjectSnapTypes.Perpendicular; XYZ startPoint; XYZ endPoint; Plane geometryPlane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero); sketch = SketchPlane.Create(uidoc.Document, geometryPlane); uidoc.Document.ActiveView.SketchPlane = sketch; uidoc.Document.ActiveView.ShowActiveWorkPlane(); try //Выбор точек { startPoint = uidoc.Selection.PickPoint(snapTypes, "Select start point"); endPoint = uidoc.Selection.PickPoint(snapTypes, "Select end point"); } catch (Autodesk.Revit.Exceptions.OperationCanceledException oc) { Console.WriteLine(oc.Message); return; } catch (Autodesk.Revit.Exceptions.InvalidOperationException oe) { Console.WriteLine(oe.Message); TaskDialog.Show("Revit", "No work plane set in current view."); return; } catch (Autodesk.Revit.Exceptions.ArgumentNullException n) { Console.WriteLine(n.Message); return; } double dist = startPoint.DistanceTo(endPoint); string distance = "Distance is " + dist.ToString(); string strCoords = "Selected start point is " + startPoint.ToString() + "\nSelected end point is " + endPoint.ToString() + distance; Line line = Line.CreateBound(startPoint, endPoint); CreateLinearDimension1(uidoc.Document, startPoint, endPoint, sketch, app); // TaskDialog.Show("Revit", strCoords); }
bool PickPointOnFace(UIDocument doc, string prompt, out XYZ point, ObjectSnapTypes snapSettings = DefaultSnapTypes) { point = null; if (doc.ActiveView.ViewType != ViewType.ThreeD) { try { point = doc.Selection.PickPoint(snapSettings, prompt + "Please pick a point on the current work plane"); } catch (OperationCanceledException) { } } else { var reference = doc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Face, prompt + "Please select a face to define a work plane"); if (doc.Document.GetElement(reference.ElementId) is Element element) { if (element.GetGeometryObjectFromReference(reference) is Face face) { if (Keyboard.IsKeyDown(Key.LeftCtrl)) { point = face.Evaluate(reference.UVPoint); } else { var plane = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(face.ComputeNormal(reference.UVPoint), face.Evaluate(reference.UVPoint)); using (var transaction = new Transaction(doc.Document)) { transaction.Start("PickPointOnFace"); doc.ActiveView.SketchPlane = SketchPlane.Create(doc.Document, plane); doc.ActiveView.ShowActiveWorkPlane(); try { point = doc.Selection.PickPoint(snapSettings, prompt + "Please pick a point on the defined work plane"); } catch (OperationCanceledException) { } transaction.RollBack(); } } } } } return(null != point); }
public XYZ CreatePoint(UIDocument uidoc, PlanarFace face) { ObjectSnapTypes snapTypes = ObjectSnapTypes.Points | ObjectSnapTypes.Nearest | ObjectSnapTypes.Perpendicular; XYZ point = null; Plane plane = Plane.CreateByNormalAndOrigin( face.FaceNormal, face.Origin); // 2017 SketchPlane sp = SketchPlane.Create(uidoc.Document, plane); // 2014 uidoc.ActiveView.SketchPlane = sp; //Выбор точек try { point = uidoc.Selection.PickPoint(snapTypes, "Select start point"); //return point; } catch (Autodesk.Revit.Exceptions.OperationCanceledException oc) { Console.WriteLine(oc.Message); //return; } catch (Autodesk.Revit.Exceptions.InvalidOperationException oe) { Console.WriteLine(oe.Message); TaskDialog.Show("Revit", "No work plane set in current view."); // return; } catch (Autodesk.Revit.Exceptions.ArgumentNullException n) { Console.WriteLine(n.Message); // return; } return(point); }
public static Result PickPoint(this UIDocument doc, out DB.XYZ point, ObjectSnapTypes snapSettings, string statusPrompt) { return(Pick(out point, () => doc.Selection.PickPoint(snapSettings, statusPrompt))); }
}// end Execute public IndependentTag CreateIndependentTag(Document document, Element duct, ExternalCommandData commandData) { // TaskDialog.Show("Create Independent Tag Method", "Start Of Method Dialog"); // make sure active view is not a 3D view var view = document.ActiveView; UIApplication uiapp = commandData.Application; Document uidoc = uiapp.ActiveUIDocument.Document; ObjectSnapTypes snapTypes = ObjectSnapTypes.Perpendicular; // Reference pickedref = null; // Selection sel = uiapp.ActiveUIDocument.Selection; // XYZ point = sel.PickPoint(snapTypes, "Select an end point or intersection"); // GetEdges(duct); // define tag mode and tag orientation for new tag var tagMode = TagMode.TM_ADDBY_CATEGORY; var tagorn = TagOrientation.Horizontal; // Add the tag to the middle of the duct var ductLoc = duct.Location as LocationCurve; var ductStart = ductLoc.Curve.GetEndPoint(0); var ductEnd = ductLoc.Curve.GetEndPoint(1); var ductMid = ductLoc.Curve.Evaluate(.5, true); var ductRef = new Reference(duct); var newTag = IndependentTag.Create(document, view.Id, ductRef, true, tagMode, tagorn, ductMid); if (null == newTag) { throw new Exception("Create IndependentTag Failed."); } // newTag.TagText is read-only, so we change the Type Mark type parameter to // set the tag text. The label parameter for the tag family determines // what type parameter is used for the tag text. // var result = foundParameter.Set("Hello"); // set leader mode free // newTag.LeaderEndCondition = LeaderEndCondition.Free; // // Selection sel2 = uiapp.ActiveUIDocument.Selection; // XYZ point2 = sel2.PickPoint(snapTypes, "Select an end point or intersection"); // var leadEnd = point2; // newTag.LeaderEnd = leadEnd; // // Selection sel3 = uiapp.ActiveUIDocument.Selection; // XYZ point3 = sel3.PickPoint(snapTypes, "Select an end point or intersection"); // var elbowPnt = point3; // newTag.LeaderElbow = elbowPnt; // // Selection sel4 = uiapp.ActiveUIDocument.Selection; // XYZ point4 = sel4.PickPoint(snapTypes, "Select an end point or intersection"); // var headerPnt = point4; // newTag.TagHeadPosition = headerPnt; // // newTag.LeaderEndCondition = LeaderEndCondition.Attached; TaskDialog.Show("Create Lines", "Begin"); Selection sell1 = uiapp.ActiveUIDocument.Selection; XYZ p1 = sell1.PickPoint(snapTypes, "Select an end point or intersection"); Selection sell2 = uiapp.ActiveUIDocument.Selection; XYZ p2 = sell2.PickPoint(snapTypes, "Select an end point or intersection"); Line L1 = Line.CreateBound(p1, p2); uidoc.Create.NewDetailCurve(view, L1); TaskDialog.Show("Create Independent Tag Method", "End Of Method Dialog"); return(newTag); }// end
public void PickPoint(UIDocument uidoc, Application app) { ObjectSnapTypes snapTypes = ObjectSnapTypes.Points | ObjectSnapTypes.Nearest | ObjectSnapTypes.Perpendicular; XYZ startPoint; XYZ endPoint; try { //Выбор плоскости Reference r = uidoc.Selection.PickObject( ObjectType.Face, "Please select a planar face to define work plane"); Element e = uidoc.Document.GetElement(r.ElementId); if (null != e) { PlanarFace face = e.GetGeometryObjectFromReference(r) as PlanarFace; if (face != null) { Plane plane = Plane.CreateByNormalAndOrigin( face.FaceNormal, face.Origin); // 2017 /* Plane plane = Plane.CreateByNormalAndOrigin( * uidoc.Document.ActiveView.ViewDirection, uidoc.Document.ActiveView.Origin);*/ SketchPlane sp = SketchPlane.Create(uidoc.Document, plane); // 2014 uidoc.ActiveView.SketchPlane = sp; //uidoc.ActiveView.ShowActiveWorkPlane(); //Выбор точек try { startPoint = uidoc.Selection.PickPoint(snapTypes, "Select start point"); endPoint = uidoc.Selection.PickPoint(snapTypes, "Select end point"); double dist = startPoint.DistanceTo(endPoint); string distance = "Distance is " + dist.ToString(); //Расстояние между точками string strCoords = "Selected start point is " + startPoint.ToString() + "\nSelected end point is " + endPoint.ToString() + distance; // TaskDialog.Show("Revit", strCoords); //Вывод координат и расстояния Line line = Line.CreateBound(startPoint, endPoint); CreateLinearDimension1(uidoc.Document, startPoint, endPoint, sp, app); //Создание Dimension } catch (Autodesk.Revit.Exceptions.OperationCanceledException oc) { Console.WriteLine(oc.Message); return; } catch (Autodesk.Revit.Exceptions.InvalidOperationException oe) { Console.WriteLine(oe.Message); TaskDialog.Show("Revit", "No work plane set in current view."); return; } catch (Autodesk.Revit.Exceptions.ArgumentNullException n) { Console.WriteLine(n.Message); return; } } } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return; } }