Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working on an add-in that will export a SAT file, but using the standard project unit of foot and fractional inches is causing the sat files to export at 1/12 scale. I found that changing the global units to fractional inches exports the SAT file at the correct scale.
To accomplish this via the API, I am trying to save the original units, change them to fractional inches, do the exports and then change the units back to the original. I am getting really hung up with the ForgeTypeId's and cannot get the code to run. What am I doing wrong? I am extremely new to coding/the Revit API so explain it to me like I am 5 please lol!
public void ExportSATFiles(Document doc, View3D view, ElementId dualDeckId)
{
// Retrieve the project's current unit settings for length
FormatOptions originalFormatOptions = doc.GetUnits().GetFormatOptions(SpecTypeId.Length);
Units originalUnits = doc.GetUnits();
try
{
// Change the project units to fractional inches
Units tempUnits = new Units(UnitSystem.Imperial);
FormatOptions inchFormatOptions = new FormatOptions(new ForgeTypeId("autodesk.spec.aec:length.unit#fractionalInches"));
tempUnits.SetFormatOptions(SpecTypeId.Length, inchFormatOptions);
using (Transaction tx = new Transaction(doc, "Set Project Units to Fractional Inches"))
{
tx.Start();
doc.SetUnits(tempUnits);
tx.Commit();
}
// Now perform the SAT export with units set to fractional inches
PerformSATExport(doc, view, dualDeckId);
// Restore the original units
using (Transaction tx = new Transaction(doc, "Restore Original Project Units"))
{
tx.Start();
doc.SetUnits(originalUnits);
tx.Commit();
}
}
catch (Exception ex)
{
MessageBox.Show("Error during SAT export: " + ex.Message);
// Ensure the units are set back to original even if an error occurs
using (Transaction tx = new Transaction(doc, "Restore Original Project Units"))
{
tx.Start();
doc.SetUnits(originalUnits);
tx.Commit();
}
}
}
Solved! Go to Solution.