using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using FWindSoft.Revit; using FWindSoft.Revit.Menu; namespace LRH.Tool { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] [Button(ButtonName = "Panel菜单")] public class CreateBallFlagCommand: ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { SelectedChangedCommand command = new SelectedChangedCommand(); command.Register(ExternalApplication.CurrentApp); command.Execute += Command_Execute; /* * 使用步骤:1、application中注册 * 2、命令中打开 */ var pane = RevitCustomDockablePanels.GetDockablePane(commandData.Application, RevitCustomDockablePanels.Default); pane.Show(); using (Transaction tran = new Transaction(RevitCore.Doc, "标记")) { try { tran.Start(); ElementId id = new ElementId(312320); RevitCore.Doc.SetDefaultFamilyTypeId(new ElementId(BuiltInCategory.OST_StructuralColumnTags), id); tran.Commit(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); tran.RollBack(); } } //var doc = RevitCore.Doc; //using (Transaction tran = new Transaction(doc, "标记")) //{ // try // { // tran.Start(); // var s = new XYZ(163700.147789060/304.8, 49780.037928369/304.8, 4500.000000000/304.8); // DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); // var solid = SolidUtil.CreateSphereAtPoint(s, 1); // ds.AppendShape(new List() {solid}); // SolidUtil.SetColor(ds, new Color(255, 0, 0)); // tran.Commit(); // RevitCore.UIApp.SetShowElements(new List() { ds }); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message.ToString()); // tran.RollBack(); // } //} return Result.Succeeded; } private void Command_Execute(object sender, UIApplication e) { DockableWindow win; if (RevitCustomDockablePanels.TryGetCoustomDockWindow(RevitCustomDockablePanels.Default, out win)) { DockablePane pane = RevitCustomDockablePanels.GetDockablePane(e, win.PaneId); if (pane == null || !pane.IsShown()) return; var ids = e.ActiveUIDocument.Selection.GetElementIds(); if (ids.Any()) { win.Content = ids.FirstOrDefault().ToString(); } } } } }