CreateSpaceCommand.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:CreateSpaceCommand
  3. * 作者:xulisong
  4. * 创建时间: 2019/3/21 8:59:02
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Autodesk.Revit.Attributes;
  13. using Autodesk.Revit.DB;
  14. using Autodesk.Revit.UI;
  15. using FWindSoft.Revit;
  16. namespace LRH.Tool
  17. {
  18. [Transaction(TransactionMode.Manual)]
  19. [Regeneration(RegenerationOption.Manual)]
  20. public class CreateSpaceCommand : ExternalCommand
  21. {
  22. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  23. {
  24. using (Transaction tran = new Transaction(RevitCore.Doc, "创建空间"))
  25. {
  26. try
  27. {
  28. tran.Start();
  29. //CreateSpaces();
  30. var arc=Arc.Create(new XYZ(-100, 0, 0), new XYZ(100, 0, 0), new XYZ(0, 100, 0));
  31. var arc1=arc.CreateOffset(30, arc.Normal);
  32. var arc2 = arc.CreateOffset(-30, arc.Normal);
  33. Transform trans1 = Transform.CreateTranslation(XYZ.BasisX+ XYZ.BasisY);
  34. Transform trans2 = Transform.CreateTranslation(XYZ.BasisX + XYZ.BasisY);
  35. var dd1 = trans1.ScaleBasisAndOrigin(10);
  36. var dd2 = trans1.ScaleBasis(10);
  37. tran.Commit();
  38. }
  39. catch (Exception e)
  40. {
  41. tran.RollBack();
  42. throw;
  43. }
  44. }
  45. return Result.Succeeded;
  46. }
  47. private void CreateSpaces()
  48. {
  49. var doc = RevitCore.Doc;
  50. var view = doc.ActiveView;
  51. if (view != null)
  52. {
  53. var level = view.GenLevel;
  54. Parameter para = view.GetParameter(BuiltInParameter.VIEW_PHASE);
  55. ElementId phaseId = para.AsElementId();
  56. var phase = doc.GetElement(phaseId) as Phase;
  57. #region 创建新的节点
  58. List<XYZ> points = new List<XYZ>();
  59. //using (SubTransaction sub = new SubTransaction(doc))
  60. //{
  61. // var spaceSipliter = doc.GetElements<>()
  62. //}
  63. var topology = doc.get_PlanTopology(level, phase);
  64. foreach (PlanCircuit topologyCircuit in topology.Circuits)
  65. {
  66. var point = topologyCircuit.GetPointInside();
  67. var xyz = new XYZ(point.U, point.V, level.ProjectElevation); //适当升高一些
  68. points.Add(xyz);
  69. }
  70. foreach (var point in points)
  71. {
  72. var oldSpace = doc.GetSpaceAtPoint(point, phase);
  73. if (oldSpace == null)
  74. {
  75. doc.Create.NewSpace(level, phase, new UV(point.X, point.Y));
  76. }
  77. }
  78. #endregion
  79. // doc.Create
  80. var newSpaces = doc.Create.NewSpaces2(level, phase, view);
  81. }
  82. }
  83. }
  84. }