Converting decimal feet to fractional feet and inches

Hello all,

new user here and I was wondering if I could get some help on a particular issue.

I am trying to have dynamo convert a decimal feet number to fraction feet and inches. the converted dimension should be formatted like xx’-yy". the idea is to then push this “converted” dimension back into Revit. also i need to have the precision of the “converted” dimension set at the nearest 1/2".

for example, I need to go from
4.56’ to 4’-6 3/4" (need to keep the “dash” as part of the dimension)

I did a search but have had no luck and unfortunately my programming skills are severely lacking.

any help would be appreciated.

You could try something like rounding your number to the nearest 1/2" (in decimal format) first. Then convert the decimal to inches, round that down to an integer, take the difference, and convert that to fractional inches.

Springs has a node that already does this to the nearest inch. You could use that as a guide as well.

Hi, I just made a custom node to do it, it should work but you might get a string as an output, I’m not expert in imperial numbers.

Round is at 1/4, but can easily fixed at 1/2, I was not sure what you needed.

FractionalInchesConverter.dyn (2.2 KB)

@vincitygialam Here a better version, where you can pick your denominator (1/2, 1/4, 1/8…). Is it what you needed?

FractionalInchesConverter.dyn (18.0 KB)

1 Like

Nice work, but I was not able to get that to work quickly, but I found (edit) “spring nodes” package has a node called Feet.ToFraction that works well. However you can not specify the precision, I assume it uses the project units precision.

1 Like

Any progress on this one? The spring node would be perfect if it weren’t for 256th precision.

many years late to the game but something like this is what you are looking for. In this line - round(aVSFParamVal, 3) the 3 stands for decimal places.

doc = DocumentManager.Instance.CurrentDBDocument
activeView = doc.ActiveView

activeStrucFrame = FilteredElementCollector(doc,activeView.Id).OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType().ToElements()

result = []

def GetStringFromNumber(document,number, unitType):
    return UnitFormatUtils.Format(doc.GetUnits(), unitType, number, True, False)

for aVSF in activeStrucFrame:
		aVSFParamVal = aVSF.get_Parameter(BuiltInParameter.INSTANCE_LENGTH_PARAM).AsDouble()
		aVSFPVRound = round(aVSFParamVal, 3)
		reconvertedToFtIn = GetStringFromNumber(doc, aVSFPVRound, UnitType.UT_Length)
		pV = "L" + str(reconvertedToFtIn)
		aVSF.LookupParameter("Prefab ID").Set(pV)
		message = traceback.format_exc()

OUT = "Success"