图学二级第四题大部分是小别墅,标高几乎相同。
这样做或许可以让刷题变的更高效(bushi!)更具趣味性(√)!
代码如下:
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace revit_careateLevel
{
[TransactionAttribute(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
UIDocument uIDocument = null;
Document document = null;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
uIDocument = uiApp.ActiveUIDocument;
document = uIDocument.Document;
Application application = uiApp.Application;
using (Transaction transaction = new Transaction(document, "创建标高"))
{
transaction.Start();
Level level1 = CreateLevel(0);
level1.Name = "F1";
Level level2 = CreateLevel(3000);
level2.Name = "F2";
Level level3 = CreateLevel(6000);
level3.Name = "F3";
Level level4 = CreateLevel(9000);
level4.Name = "F4";
Level level5 = CreateLevel(12000);
level5.Name = "屋顶";
transaction.Commit();
TransactionStatus status = transaction.GetStatus();
if (status.Equals(TransactionStatus.Committed))
{
TaskDialog.Show("提示", "创建成功");
}
}
return Result.Succeeded;
}
/// <summary>
/// 创建标高和视图
/// </summary>
/// <param name="var">高度</param>
/// <returns></returns>
public Level CreateLevel(int var)
{
//创建标高
Level level1 = Level.Create(document, ToFoot(var));
//获取楼层平面
FilteredElementCollector collector = new FilteredElementCollector(document);
var elements1 = collector.OfClass(typeof(ViewFamilyType)).ToElements();
ViewFamilyType viewFamilyType = null;
foreach (var item in elements1)
{
viewFamilyType = item as ViewFamilyType;
if (viewFamilyType.ViewFamily == ViewFamily.FloorPlan)
{
break;
}
}
//创建视图
ViewPlan.Create(document, viewFamilyType.Id, level1.Id);
return level1;
}
/// <summary>
/// 单位转换
/// </summary>
/// <param name="var">毫米</param>
/// <returns></returns>
public double ToFoot(int var)
{
double L = UnitUtils.ConvertToInternalUnits(var, DisplayUnitType.DUT_MILLIMETERS);
return L;
}
}
}