public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
if( !doc.IsFamilyDocument )
{
message = "Please run this command in afamily document.";
return Result.Failed;
}
Autodesk.Revit.Creation.Application creApp = app.Application.Create;
Autodesk.Revit.Creation.Document creDoc = doc.Create;
using ( Transaction t = new Transaction( doc ) )
{
t.Start( "New Dimension Label" );
SketchPlane skplane = findSketchPlane( doc, XYZ.BasisZ );
if ( null == skplane )
{
//Plane geometryPlane = creApp.NewPlane( XYZ.BasisZ, XYZ.Zero ); // 2016
Plane geometryPlane = Plane.CreateByNormalAndOrigin( XYZ.BasisZ, XYZ.Zero ); // 2017
//skplane = doc.FamilyCreate.NewSketchPlane( geometryPlane ); // 2013
skplane = SketchPlane.Create( doc, geometryPlane ); // 2014
}
double length = 1.23;
XYZ start = XYZ.Zero;
XYZ end = creApp.NewXYZ( 0, length, 0 );
//Line line = creApp.NewLine( start, end, true ); // 2013
Line line = Line.CreateBound( start, end ); // 2014
ModelCurve modelCurve
= doc.FamilyCreate.NewModelCurve(
line, skplane );
ReferenceArray ra = new ReferenceArray();
ra.Append( modelCurve.GeometryCurve.Reference );
start = creApp.NewXYZ( length, 0, 0 );
end = creApp.NewXYZ( length, length, 0 );
line = Line.CreateBound( start, end );
modelCurve = doc.FamilyCreate.NewModelCurve(
line, skplane );
ra.Append( modelCurve.GeometryCurve.Reference );
start = creApp.NewXYZ( 0, 0.2 * length, 0 );
end = creApp.NewXYZ( length, 0.2 * length, 0 );
line = Line.CreateBound( start, end );
Dimension dim
= doc.FamilyCreate.NewLinearDimension(
doc.ActiveView, line, ra );
FamilyParameter familyParam
= doc.FamilyManager.AddParameter(
"length",
BuiltInParameterGroup.PG_IDENTITY_DATA,
ParameterType.Length, false );
//dim.Label = familyParam; // 2013
dim.FamilyLabel = familyParam; // 2014
t.Commit();
}
return Result.Succeeded;
}