1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /*-------------------------------------------------------------------------
- * 功能描述:CreateSpaceCommand
- * 作者:xulisong
- * 创建时间: 2019/3/21 8:59:02
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.Attributes;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.UI;
- using FWindSoft.Revit;
- namespace LRH.Tool
- {
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class CreateSpaceCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- using (Transaction tran = new Transaction(RevitCore.Doc, "创建空间"))
- {
- try
- {
- tran.Start();
- //CreateSpaces();
- var arc=Arc.Create(new XYZ(-100, 0, 0), new XYZ(100, 0, 0), new XYZ(0, 100, 0));
- var arc1=arc.CreateOffset(30, arc.Normal);
- var arc2 = arc.CreateOffset(-30, arc.Normal);
- Transform trans1 = Transform.CreateTranslation(XYZ.BasisX+ XYZ.BasisY);
- Transform trans2 = Transform.CreateTranslation(XYZ.BasisX + XYZ.BasisY);
- var dd1 = trans1.ScaleBasisAndOrigin(10);
- var dd2 = trans1.ScaleBasis(10);
- tran.Commit();
- }
- catch (Exception e)
- {
- tran.RollBack();
- throw;
- }
- }
- return Result.Succeeded;
- }
- private void CreateSpaces()
- {
- var doc = RevitCore.Doc;
- var view = doc.ActiveView;
- if (view != null)
- {
- var level = view.GenLevel;
- Parameter para = view.GetParameter(BuiltInParameter.VIEW_PHASE);
- ElementId phaseId = para.AsElementId();
- var phase = doc.GetElement(phaseId) as Phase;
- #region 创建新的节点
- List<XYZ> points = new List<XYZ>();
- //using (SubTransaction sub = new SubTransaction(doc))
- //{
- // var spaceSipliter = doc.GetElements<>()
- //}
- var topology = doc.get_PlanTopology(level, phase);
- foreach (PlanCircuit topologyCircuit in topology.Circuits)
- {
- var point = topologyCircuit.GetPointInside();
- var xyz = new XYZ(point.U, point.V, level.ProjectElevation); //适当升高一些
- points.Add(xyz);
- }
- foreach (var point in points)
- {
- var oldSpace = doc.GetSpaceAtPoint(point, phase);
- if (oldSpace == null)
- {
- doc.Create.NewSpace(level, phase, new UV(point.X, point.Y));
- }
- }
- #endregion
- // doc.Create
- var newSpaces = doc.Create.NewSpaces2(level, phase, view);
- }
- }
- }
- }
|