CreateBallFlagCommand.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using Autodesk.Revit.Attributes;
  9. using Autodesk.Revit.DB;
  10. using Autodesk.Revit.UI;
  11. using FWindSoft.Revit;
  12. using FWindSoft.Revit.Menu;
  13. namespace LRH.Tool
  14. {
  15. [Transaction(TransactionMode.Manual)]
  16. [Regeneration(RegenerationOption.Manual)]
  17. [Button(ButtonName = "Panel菜单")]
  18. public class CreateBallFlagCommand: ExternalCommand
  19. {
  20. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  21. {
  22. SelectedChangedCommand command = new SelectedChangedCommand();
  23. command.Register(ExternalApplication.CurrentApp);
  24. command.Execute += Command_Execute;
  25. /*
  26. * 使用步骤:1、application中注册
  27. * 2、命令中打开
  28. */
  29. var pane = RevitCustomDockablePanels.GetDockablePane(commandData.Application, RevitCustomDockablePanels.Default);
  30. pane.Show();
  31. using (Transaction tran = new Transaction(RevitCore.Doc, "标记"))
  32. {
  33. try
  34. {
  35. tran.Start();
  36. ElementId id = new ElementId(312320);
  37. RevitCore.Doc.SetDefaultFamilyTypeId(new ElementId(BuiltInCategory.OST_StructuralColumnTags), id);
  38. tran.Commit();
  39. }
  40. catch (Exception ex)
  41. {
  42. MessageBox.Show(ex.Message.ToString());
  43. tran.RollBack();
  44. }
  45. }
  46. //var doc = RevitCore.Doc;
  47. //using (Transaction tran = new Transaction(doc, "标记"))
  48. //{
  49. // try
  50. // {
  51. // tran.Start();
  52. // var s = new XYZ(163700.147789060/304.8, 49780.037928369/304.8, 4500.000000000/304.8);
  53. // DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
  54. // var solid = SolidUtil.CreateSphereAtPoint(s, 1);
  55. // ds.AppendShape(new List<GeometryObject>() {solid});
  56. // SolidUtil.SetColor(ds, new Color(255, 0, 0));
  57. // tran.Commit();
  58. // RevitCore.UIApp.SetShowElements(new List<Element>() { ds });
  59. // }
  60. // catch (Exception ex)
  61. // {
  62. // MessageBox.Show(ex.Message.ToString());
  63. // tran.RollBack();
  64. // }
  65. //}
  66. return Result.Succeeded;
  67. }
  68. private void Command_Execute(object sender, UIApplication e)
  69. {
  70. DockableWindow win;
  71. if (RevitCustomDockablePanels.TryGetCoustomDockWindow(RevitCustomDockablePanels.Default, out win))
  72. {
  73. DockablePane pane = RevitCustomDockablePanels.GetDockablePane(e, win.PaneId);
  74. if (pane == null || !pane.IsShown())
  75. return;
  76. var ids = e.ActiveUIDocument.Selection.GetElementIds();
  77. if (ids.Any())
  78. {
  79. win.Content = ids.FirstOrDefault().ToString();
  80. }
  81. }
  82. }
  83. }
  84. }