First create a closed curve and then create an entity. here you need to manually draw a reference plane
[TransactionAttribute (Autodesk. Revit. Attributes. TransactionMode. Manual)]
Using createsolid: IExternalCommand
{
CurveArrArray createProfileLShape (Application _ rvtApp)
{
W = Util. mmToFeet (); d = Util. mmToFeet ();
Tw = Util. mmToFeet (); td = Util. mmToFeet ();
NVerts =;
XYZ [] pts = XYZ [] {
XYZ (-w/,-d /,),
XYZ (w/,-d /,),
XYZ (w/, (-d/) + td ,),
XYZ (-w/) + tw, (-d/) + td ,),
XYZ (-w/) + tw, d /,),
XYZ (-w/, d /,),
XYZ (-w/,-d /,)};
CurveArray pLoop = _ rvtApp. Create. NewCurveArray ();
(I =; I <nVerts; ++ I)
{
Line line = _ rvtApp. Create. NewLineBound (pts [I], pts [I +]);
PLoop. Append (line );
}
CurveArrArray pProfile = _ rvtApp. Create. NewCurveArrArray ();
PProfile. Append (pLoop );
PProfile;
}
Extrusion CreateSolid (Application app, Document doc)
{
CurveArrArray pProfile = createProfileLShape (app );
ReferencePlane pRefPlane = Util. findElement (doc, (ReferencePlane),) ReferencePlane;
SketchPlane pSketchPlane = doc. FamilyCreate. NewSketchPlane (pRefPlane. Plane );
DHeight = Util. mmToFeet ();
BIsSolid =;
Extrusion pSolid = doc. FamilyCreate. NewExtrusion (bIsSolid, pProfile, pSketchPlane, dHeight );
PSolid;
}
Result Execute (ExternalCommandData commandData, messages, ElementSet elements)
{
UIApplication app = commandData. Application;
Document doc = app. ActiveUIDocument. Document;
Transaction ts = Transaction (doc ,);
Ts. Start ();
FamilyManager m_familyMgr = doc. FamilyManager;
CreateSolid (app. Application, doc );
Ts. Commit ();
Result. Succeeded;
}
}
Util
{
MmToFeet (val) {val /;}
FeetToMm (val) {val *;}
Element findElement (Document _ rvtDoc, Type targetType, targetName)
{
FilteredElementCollector collector = FilteredElementCollector (_ rvtDoc );
Collector. WherePasses (ElementClassFilter (targetType ));
TargetElems = element collector element. Name. Equals (targetName) element;
List <Element> elems = targetElems. ToList <Element> ();
(Elems. Count>)
{Elems [];
}
;
}
Formatting and message handlers
Caption =;
InfoMsg (msg)
{
System. Diagnostics. Debug. WriteLine (msg );
WinForm. MessageBox. Show (msg, Caption, WinForm. MessageBoxButtons. OK, WinForm. MessageBoxIcon. Information );
}
ErrorMsg (msg)
{
WinForm. MessageBox. Show (msg, Caption, WinForm. MessageBoxButtons. OK, WinForm. MessageBoxIcon. Error );
}
} Url: http://greatverve.cnblogs.com/p/revit-family-api-create-solid.html