A friend in the industry asked me to write a plug-in to quickly create elevation.
[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 ();
}
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