一業內朋友讓我寫個快速創建標高的插件。
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
cmdDrawLevel : IExternalCommand
{
Result Execute(ExternalCommandData commandData, messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Selection sel = app.ActiveUIDocument.Selection;
{
Transaction ts = Transaction(doc, );
ts.Start();
dStart = RevitTools.Unit.CovertToAPI(.Parse(XmlTools.levelStart), DisplayUnitType.DUT_METERS);
dDis = RevitTools.Unit.CovertToAPI(.Parse(XmlTools.levelDis), DisplayUnitType.DUT_METERS);
iNum = .Parse(XmlTools.levelNum);
Level levelStart = doc.Create.NewLevel(dStart);
levelStart.Name = XmlTools.levelPre + ;
( i = ; i <= iNum; i++)
{
Level level = doc.Create.NewLevel(dStart + i * dDis);
level.Name = XmlTools.levelPre + (i + );
}
ts.Commit();
}
(Exception ex)
{
TaskDialog.Show(, );
}
Result.Succeeded;
}
} System;
System.Collections.Generic;
System.Linq;
System.Text;
RevitCodes
{
XmlTools
{
levelStart = ;
levelDis = ;
levelNum = ;
levelPre = ;
}
}
System;
System.Collections.Generic;
System.Text;
Autodesk.Revit.DB;
System.Configuration;
System.Reflection;
RevitTools
{
Unit
{
Methods
CovertFromAPI(DisplayUnitType to, value)
{
value *= ImperialDutRatio(to);
}
CovertToAPI( value, DisplayUnitType )
{
value /= ImperialDutRatio();
}
ImperialDutRatio(DisplayUnitType dut)
{
(dut)
{
DisplayUnitType.DUT_DECIMAL_FEET: ;
DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES: ;
DisplayUnitType.DUT_DECIMAL_INCHES: ;
DisplayUnitType.DUT_FRACTIONAL_INCHES: ;
DisplayUnitType.DUT_METERS: ;
DisplayUnitType.DUT_CENTIMETERS: ;
DisplayUnitType.DUT_MILLIMETERS: ;
DisplayUnitType.DUT_METERS_CENTIMETERS: ;
: ;
}
}
}
}url:http://greatverve.cnblogs.com/p/revit-api-create-level.html