How to Batch Change Project Units

Hello,

I have a folders full of .rfa files that have the same set of Family type parameters. Among them, is a Weight parameter which is given with the units kN (kilo-Newtons). I want to create a dynamo script that batch changes the units used from kN to kgf (kilograms force) as shown below:

I found the video guide below which describes how to accomplish this, however even after following the instructions I am unable to achieve the same result:
Revit Change Units of Project using Dynamo (youtube.com)

The video is able to use methods such as DisplayUnitType or UnitType, however I receive errors that unit type is not defined. This may be due to the fact that the video works with rvt files instead of rfa.
I have attached my script below where I was able to output the Autodesk.Revit.DB.Units object.

I was wondering if there is a way to access the units from this object and change them. Any help would be greatly appreciated, thank you!

Have a look at my code here to see if that helps - Change project unit node - #2 by Mike.Buttery

weight = SpecTypeId.Weight
kg_force = UnitTypeId.KilogramsForce
current = units.GetFormatOptions(weight).GetUnitTypeId()

if current != kg_force:
    units.SetFormatOptions(weight, FormatOptions(kg_force))

# etc.

@Mike.Buttery Thank you for the reply. I tried out your solution and SpecTypeId and UnitTypeId do work in allowing me to accessing the units.

According to the Dynamo python script output window it shows that the units were changed, however when I actually open the files to check the project units they are still kN and not kgf.

As shown below I used LabelUtils.GetLabelForUnit to output the unit label before and after the change occurs in the 4 documents I have in my testing file folder. I output two lists; one with Weight’s units before the change, and one with Weight’s units after the change. According to the output window shown below, it looks like it worked:

However when I open the files manually to check, I see that in Project Units > Structural > Weight is still in kN:


The weight family type parameter also remains unchanged:
image

Is there something I’m missing here? Thank you for all your help so far!

@Mike.Buttery Nevermind! I just realized I omitted doc.SetUnits(units) from my script. I added it to the transaction and it works! Thank you so much

1 Like