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 JigTexts : IExternalCommand { public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements) { UIDocument activeUIDocument = cmdData.Application.ActiveUIDocument; ViewAssist.ViewValidating(activeUIDocument.Document, activeUIDocument.ActiveView); XYZ xyz = null; List list = new List(); List list2 = new List(); try { IList list3 = activeUIDocument.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element); foreach (Reference reference in list3) { TextNote textNote = activeUIDocument.Document.GetElement(reference) as TextNote; if (textNote != null) { BoundingBoxXYZ boundingBoxXYZ = textNote.get_BoundingBox(activeUIDocument.ActiveView); XYZ xyz2 = boundingBoxXYZ.Min + (boundingBoxXYZ.Max - boundingBoxXYZ.Min) / 2.0; list.Add(textNote); list2.Add(xyz2); } } xyz = activeUIDocument.Selection.PickPoint("请选择基点<退出>:"); } catch { return 0; } XTextsJig xtextsJig = new XTextsJig(activeUIDocument); XYZ xyz3 = xtextsJig.DragTexts(list, list2, xyz, "请确定位置:"); Result result; if (xyz3 == null) { xtextsJig.Dispose(); result = 0; } else { Transform transform = Transform.CreateTranslation(xyz3 - xyz); Transaction transaction = new Transaction(activeUIDocument.Document); transaction.Start("CreateText"); foreach (TextNote textNote2 in list) { XYZ xyz4 = transform.OfPoint(textNote2.Coord); TextNote.Create(activeUIDocument.Document, activeUIDocument.ActiveView.Id, xyz4, textNote2.Text, textNote2.TextNoteType.Id); } transaction.Commit(); xtextsJig.Dispose(); result = 0; } return result; } } }