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 CreateLevel
{
[TransactionAttribute(TransactionMode.Manual)]
class CreateLevel : IExternalCommand
{
Document document = null;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Application application = uiApp.Application;
UIDocument uIDocument = uiApp.ActiveUIDocument;
document = uIDocument.Document;
using (Transaction transaction = new Transaction(document, "创建标高"))
{
transaction.Start();
MainWindow mainWindow = new MainWindow();
mainWindow.ShowDialog();
//按点×关闭
if (!mainWindow.ClickClosed)
{
return Result.Cancelled;
}
double hight = Convert.ToDouble(mainWindow.hight.Text);
String name= mainWindow.name.Text;
Level level = LevelCreate(hight);
level.Name = name;
transaction.Commit();
}
return Result.Succeeded;
}
public Level LevelCreate(double var)
{
//创建标高
Level level = Level.Create(document, ToFoot(var));
//获取楼层平面
FilteredElementCollector collector = new FilteredElementCollector(document);
IList<Element> elements1 = collector.OfClass(typeof(ViewFamilyType)).ToElements();
ViewFamilyType viewFamilyType = null;
foreach (Element item in elements1)
{
viewFamilyType = item as ViewFamilyType;
if (viewFamilyType.ViewFamily == ViewFamily.FloorPlan)
{
break;
}
}
//创建视图
ViewPlan viewPlan = ViewPlan.Create(document, viewFamilyType.Id, level.Id);
return level;
}
public double ToFoot(double var)
{
double foot = UnitUtils.ConvertToInternalUnits(var, DisplayUnitType.DUT_MILLIMETERS);
return foot;
}
}
}
通过WPF创建窗口和revit交互创建标高
按钮:this.Close() 关闭
环境搭建:
删除App.xaml & App.config
引用revitAPI & revitAPIUI
复制本地:False
属性 输出类型:类库
然后再添加上button、textbox、label...