If the doc.DisplayUnitSystem is set to Imperial and I change all the Units format by SetFormatOptions to metric format, will that be same as a doc.DisplayUnitSystem set to Metric...??
Solved! Go to Solution.
Solved by ratno123s. Go to Solution.
Have you tried it out yet? What is the result, please? Thank you!
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
When in doubt, always first check the Revit SDK samples.
In this case, the Units sample may be a good place to look.
Cheers,
Jeremy
🙂
Thank you very much for your appreciation and confirmation!
Cheers,
Jeremy
According to my findings... The Document.DisplayUnitSystem depends solely on the format of Units for UnitType.UT_Length....
Is that correct?
Just by changing the Unit format of UT_Length the DisplayUnitSystem of the document changes automatically changes
hello , i want to change the unit of my project from meter to millimeter i can do that directly? or i stick to change the value of my parameter from meter to millimeter
I would suggest researching this from the end user point of view and determining the best practices there before even starting to think about doing anything on this programmatically. Otherwise, you could easily end up shooting yourself in the foot:
https://duckduckgo.com/?q=revit+change+project+units
I tried this but it doesnt seem to work
Units units = doc.GetUnits();
// Change the display units of length to feet
units.GetFormatOptions(UnitType.UT_Length).DisplayUnits = DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES;
// Apply the new units to the project
doc.SetUnits(units);
Maybe it does work. Create a wall in your project that is 1 metre long. Look at its length in the user interface. Change the project units. Look at its length in the user interface again. Hasn't it changed?
when i do that manually project units and change it does work indeed but for some reason when i run the code it doesnt i will try again maybe my revit is slow or something
Can't find what you're looking for? Ask the community or share your knowledge.