123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- /*-------------------------------------------------------------------------
- * 功能描述: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<User>();
- 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<Element> newElements = new List<Element>();
- // foreach (var elementId in elementIds)
- // {
- // var element = RevitCore.Doc.GetElement(elementId);
- // if (element is Space space)
- // {
- // var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
- // List<CurveLoop> loops = new List<CurveLoop>();
- // 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<GeometryObject>() { 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;
- }
- }
- }
|