[Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class cmd : IExternalCommand { public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements) { UIDocument uiDoc = cmdData.Application.ActiveUIDocument; Document doc = uiDoc.Document; Selection sel = uiDoc.Selection; Transaction ts = new Transaction(doc, " http://revit.5d6d.com "); ts.Start(); XYZ xyzOrigin = sel.PickPoint(); XYZ pt1 = sel.PickPoint(); XYZ pt2 = sel.PickPoint(); // XYZ baseVec = new XYZ( 0, 0, 0); XYZ upVec = new XYZ( 0, 0, 0); double dWidth = 0.16; TextAlignFlags textAlign = TextAlignFlags.TEF_ALIGN_LEFT | TextAlignFlags.TEF_ALIGN_TOP; TextNote textNote = doc.Create.NewTextNote( doc.ActiveView, xyzOrigin, baseVec, upVec, dWidth, textAlign , TextNoteLeaderTypes.TNLT_STRAIGHT_L, TextNoteLeaderStyles.LCS_ONE_SEG_LINE, pt1, pt2, " 标注 "); ts.Commit(); return Result.Succeeded; } }