CAD transforms - read in feet and fractional inches

Hi @stephen_l,
Is it possible to have this read in fractions.
That is, go from 1.2187' to 1' - 2 5/8"?
Perhaps there's a preference where you can set the tolerance it measures by, like by 1/32, or 1/16, 1/8, etc,

Comments

  • Unit conversion to strings rely on blender's api (bpy.utils.units.to_string) and depends on "separate units" in scene units configuration. Unfortunately as far as i know, support for fractions is not implemented.
    Any known robust available algo ?

  • edited May 30

    Haha... :)
    not sure how useful it would be.

    https://chatgpt.com/share/0897babd-6b9f-48fd-9a98-ce11bc1f1de1

  • edited May 30

    Wow, we are in another world.
    https://chatgpt.com/share/0897babd-6b9f-48fd-9a98-ce11bc1f1de1


    from fractions import Fraction def decimal_to_feet_inches(decimal_feet, tolerance=16): """ Convert a decimal feet measurement to feet and inches with a specified fraction tolerance. :param decimal_feet: Measurement in decimal feet. :param tolerance: Fraction tolerance (denominator), e.g., 32, 16, 8, etc. :return: A string representation of the measurement in feet and inches. """ decimal_feet = decimal_feet * 3.28084 feet = int(decimal_feet) remaining_decimal_feet = decimal_feet - feet total_inches = remaining_decimal_feet * 12 inches = int(total_inches) remaining_decimal_inches = total_inches - inches fraction = Fraction(round(remaining_decimal_inches * tolerance), tolerance) # Adjust the fraction if fraction.denominator > tolerance: fraction = Fraction(round(remaining_decimal_inches * tolerance)) # If fraction is 0, we just return feet and inches if fraction == 0: return f"{feet}' - {inches}\"" else: # If the fraction is exactly 1, we just return feet and inches plus 1 if fraction == 1: inches += 1 readout = f"{feet}' - {inches}\"" else: readout = f"{feet}' - {inches} {fraction}\"" return readout

    def _translation(self, trs: TransformAction) -> Matrix: """Evaluate translation :param trs: TransformAction :return: Transform matrix """ # By default, trs.space is active object's matrix_world normalized about = trs.space # about.translation[:] = trs.snap_from # snap_to in trs.space delta = Geom3d.matrix_inverted(about) @ Constraint.apply(trs, trs.snap_to, about) delta_len = delta.length if trs.has(TransformType.KEYBOARD): # NOTE: for keyboard actions with axis constraints # ensure that delta is not null if delta_len == 0 and trs.has_constraint(ConstraintType.AXIS): if trs.has_constraint(ConstraintType.X): delta = X_AXIS elif trs.has_constraint(ConstraintType.Y): delta = Y_AXIS else: delta = Z_AXIS delta_len = 1.0 dist = Keyboard.value logger.debug("dist %.4f %s" % (dist, delta.normalized())) else: dist = delta_len # Store feedback for widget self.feedback_move[:] = delta steps = max(1, trs.steps) if trs.has(TransformType.COPY): trs.feedback = "%s( %s ) %s" % ( i18n.translate("Array"), trs.steps + 1, decimal_to_feet_inches(round(dist, 5), 16) ) else: trs.feedback = decimal_to_feet_inches(round(dist, 5), 16) if delta_len == 0: # delta not normalizable .. so transform is null return Matrix() about = Space.get(trs, self.matrix_step) # pre-translate return Geom3d.normalized( Geom3d.pre_transform(about, Matrix.Translation((trs.step * dist / steps) * delta.normalized())) )
  • @stephen_l would it be possible to implement something like this into the next version? or do you take pull requests?

  • Would rather implement in Units.to_string handling unit display, but will definitely take a look. Units.from_string should handle fraction input (as it does take care of math expressions) but may require some tricks like 2 + 3/4 in - perhaps even require 2 + (3/4) in (?).

Sign In or Register to comment.