FamilyManager. NewType (""); add a new type and set the parameter to set the parameter for the new type.
[TransactionAttribute (Autodesk. Revit. Attributes. TransactionMode. Manual)]
Incluaddtype: IExternalCommand
{
AddType (FamilyManager familyMgr, name, w, d)
{
FamilyType type1 = familyMgr. NewType (name );
FamilyParameter paramW = familyMgr. get_Parameter ();
ValW = Util. mmToFeet (w );
(ParamW! =)
{
FamilyMgr. Set (paramW, valW );
}
FamilyParameter paramD = familyMgr. get_Parameter ();
ValD = Util. mmToFeet (d );
(ParamD! =)
{
FamilyMgr. Set (paramD, valD );
}
}
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;
AddType (m_familyMgr ,,,);
AddType (m_familyMgr ,,,);
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 );
}
} From: http://greatverve.cnblogs.com/p/revit-family-api-newtype.html