Since you asked me to test myself... I wrote the following code and bumped into another problem..The Unit formats doesn't change!!! Even when I change the units_doc.SetFormatOptions(ut, nFt);!!!
I opened two documents in my Revit Session. One with the basic Imperial template and the other one with basic Metric template. Then i tried to copy the units.FormatOptions of one document to another document for all the UnitTypes...There was not exceptions faced while debugging.. and "quick watch" ing while debug suggested that the Units.Formatoptions had changed.. However when the program ended nothing reflected in the revit .. as if no changes had taken place...
below is the code:
Document doc;
UIDocument uiDoc;
Application app;
UIApplication uiApp;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
this.doc = commandData.Application.ActiveUIDocument.Document;
this.uiDoc = commandData.Application.ActiveUIDocument;
this.app = commandData.Application.Application;
this.uiApp = commandData.Application;
try
{
Document doc1 = this.app.Documents.Cast<Document>().Where(x => x.Title != this.doc.Title).FirstOrDefault();
Units units_doc = this.doc.GetUnits();
Units units_1 = doc1.GetUnits();
List<UnitType> unitTypes = Enum.GetValues(typeof(UnitType)).Cast<UnitType>().ToList();//UnitUtils.GetValidUnitTypes().ToList();
foreach (var ut in unitTypes.Where(x => x != UnitType.UT_Undefined && x != UnitType.UT_Custom))
{
try
{
FormatOptions fmtOpts_1 = units_1.GetFormatOptions(ut);
FormatOptions fmtOpts_doc = units_doc.GetFormatOptions(ut);
//units_doc.SetFormatOptions(ut, fmtOpts_1); //since this did not work i wrote the below two lines
FormatOptions ft = new FormatOptions(fmtOpts_1);
ft.UseDefault = false;
units_doc.SetFormatOptions(ut, ft);
fmtOpts_doc = units_doc.GetFormatOptions(ut); // during debug this showed that the unit formats had changed.
}
catch (Exception ex)
{
}
}
return Result.Succeeded;
}
catch(Exception ex)
{
return Result.Failed;
}
}
next I tried with just one simple code on a imperial template revit file:
try
{
UnitType ut = UnitType.UT_Length;
FormatOptions ft_doc = units_doc.GetFormatOptions(ut);
//FormatOptions ft_1 = units_1.GetFormatOptions(ut);
FormatOptions nFt = new FormatOptions();
nFt.UseDefault = false;
nFt.DisplayUnits = DisplayUnitType.DUT_MILLIMETERS;
units_doc.SetFormatOptions(ut, nFt);
}
catch (Exception ex)
{
}
even this did not work!!!
Is not possible to change the format options through code??
Please help