using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System; using System.Collections.Generic; namespace HYJig { [Transaction(TransactionMode.Manual)] [Regeneration(0)] public class JigRectangle : IExternalCommand { public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements) { UIDocument activeUIDocument = cmdData.Application.ActiveUIDocument; ViewAssist.ViewValidating(activeUIDocument.Document, activeUIDocument.ActiveView); XRectJig xrectJig = new XRectJig(activeUIDocument); XYZ xyz = xrectJig.PickStartPoint("请确定矩形第一个角点:"); Result result; if (xyz == null) { xrectJig.Dispose(); result = 0; } else { XYZ xyz2 = xrectJig.PickRectAngle(xyz, "请确定矩形方向:"); if (xyz2 == null) { xrectJig.Dispose(); result = 0; } else { XYZ xyz3 = xrectJig.PickEndPoint(xyz, xyz2, "请确定矩形另一对角点:"); if (xyz3 == null) { xrectJig.Dispose(); result = 0; } else { Transaction transaction = new Transaction(activeUIDocument.Document); transaction.Start("CreateCurve"); List list = xrectJig.CreateCurves(); foreach (Curve curve in list) { activeUIDocument.Document.Create.NewDetailCurve(activeUIDocument.ActiveView, curve); } transaction.Commit(); xrectJig.Dispose(); result = 0; } } } return result; } } }