/*------------------------------------------------------------------------- * 功能描述:CreateSpaceSolidCommand * 作者:xulisong * 创建时间: 2019/3/12 17:12:59 * 版本号:v1.0 * -------------------------------------------------------------------------*/ 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.DB.Mechanical; using Autodesk.Revit.UI; using FWindSoft.Revit; using FWindSoft.Revit.ExtensibleStorage; using FWindSoft.Revit.Utils; namespace LRH.Tool { public class User { public string Name { get; set; } = "JJPPS"; public int Age { get; set; } = 29; } [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class CreateSpaceSolidCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var doc = RevitCore.Doc; using (Transaction tran = new Transaction(doc, "标记")) { try { tran.Start(); var infoOld = RevitCore.Doc.ProjectInformation.GetSimpleClass(); if (infoOld == null) { infoOld = new User(); } else { infoOld.Age = infoOld.Age + 1; } RevitCore.Doc.ProjectInformation.SetSimpleClass(infoOld); tran.Commit(); MessageBox.Show("创建成功"); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); tran.RollBack(); } } //RevitCore.Doc.Create.NewFamilyInstance(,) #region 标记创建 //using (Transaction tran = new Transaction(doc, "标记")) //{ // try // { // tran.Start(); // var elementIds = RevitCore.Selection.GetElementIds(); // List newElements = new List(); // foreach (var elementId in elementIds) // { // var element = RevitCore.Doc.GetElement(elementId); // if (element is Space space) // { // var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions()); // List loops = new List(); // foreach (var segment in segments) // { // CurveLoop loop = new CurveLoop(); // foreach (var boundarySegment in segment) // { // loop.Append(boundarySegment.GetCurve()); // } // if (loop.Any()) // { // loops.Add(loop); // } // } // if (!loops.Any()) // { // continue; // } // DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); // var lowLevel = // (doc.GetElement(space.GetParameterElementId(BuiltInParameter.ROOM_LEVEL_ID)) as Level) // .Elevation; // var highLevel = // (doc.GetElement(space.GetParameterElementId(BuiltInParameter.ROOM_UPPER_LEVEL)) as Level) // .Elevation; // double height = (highLevel + space.GetParameterDouble(BuiltInParameter.ROOM_UPPER_OFFSET)) - (lowLevel + space.GetParameterDouble(BuiltInParameter.ROOM_LOWER_OFFSET)); // var solid = SolidUtil.CreateSphere(loops, XYZ.BasisZ * height); // ds.AppendShape(new List() { solid }); // newElements.Add(ds); // } // } // tran.Commit(); // if (newElements.Any()) // { // RevitCore.UIApp.SetShowElements(newElements); // MessageBox.Show("创建成功"); // } // } // catch (Exception ex) // { // MessageBox.Show(ex.Message.ToString()); // tran.RollBack(); // } //} #endregion return Result.Succeeded; } } }