Skip to content

Make ball_bearing_info function similar to screw_info (ball_bearing_info returns struct) #1933

@llewellyn-marriott

Description

@llewellyn-marriott

Hello everyone,

I am fairly new to OpenSCAD and BOSL2 so please be kind if there are mistakes here or I am misunderstanding something. I also want to say thanks for this amazing tool.

My feature request is to make ball_bearing_info function more like screw_info in that it would return a struct which could be passed to ball_bearing.

Is your feature request related to a problem? Please describe.
I am using a ball bearing that doesn't have a supported trade size, I had hoped I would be able to use the ball_bearing_info function to construct the array using my custom dimensions, then pass that around to modules. But ball_bearing_info only accepts trade sizes. So I must construct the array with values in the correct order.
It is possible, but I thought with a small change here it would be much easier.

Describe the solution you'd like
I like how the screw_info function returns a struct that can be used with all the related screw functions.
I would like to see the same for ball_bearing_info and ball_bearing.

Describe alternatives you've considered
Currently I am using a wrapper of ball_bearing and ball_bearing_info to achieve the above.

Example Code
This is the wrapper I am using

module ball_bearing_from_info(ball_bearing_info) {
    if(is_struct(ball_bearing_info)) {
        ball_bearing(
            id=struct_val(ball_bearing_info,"shaft_diam"),
            od=struct_val(ball_bearing_info,"outer_diam"),
            width=struct_val(ball_bearing_info,"width"),
            shield=struct_val(ball_bearing_info,"shielded"),
            flange=struct_val(ball_bearing_info,"flanged"),
            fd=struct_val(ball_bearing_info,"flange_diam"),
            fw=struct_val(ball_bearing_info,"flange_width"),
        );
    } else {
        ball_bearing(ball_bearing_info);
    }
    children();
}

function ball_bearing_info_struct(trade_size, id, od, width, shield = true, flange = false, fd, fw, rounding) =
  is_def(trade_size) && is_string(trade_size) ?
  let(
    info = ball_bearing_info(trade_size)
  ) struct_set(
    [],
    [
      "shaft_diam",
      info[0],
      "outer_diam",
      info[1],
      "width",
      info[2],
      "shielded",
      info[3],
      "flanged",
      info[4],
      "flange_diam",
      info[5],
      "flange_width",
      info[6],
    ]
  ) :
  struct_set(
    [],
    [
      "shaft_diam",
      id,
      "outer_diam",
      od,
      "width",
      width,
      "shielded",
      shield,
      "flanged",
      flange,
      "flange_diam",
      fd,
      "flange_width",
      fw,
    ]
  ) ;

my_custom_ball_bearing = ball_bearing_info_struct(id=17, od=35, width=14, shield=true, flange=false);
my_standard_bb = ball_bearing_info_struct("6003");

echo_struct(my_custom_ball_bearing);
echo_struct(my_standard_bb);

// render from ball bearing info
ball_bearing_from_info(my_custom_ball_bearing);
// render ball bearing from trade size
ball_bearing_from_info("6003");

How it would work from source modification:

To implement this I would modify the ball_bearing module to check if trade_size is a struct, if it is then read values from the struct. This part shouldn't be a breaking change.

However if ball_bearing_info was changed to return a struct that could break some existing workflows.
An additional paramter could be added called as_struct defaulted to false which will return a struct when set to true.

my_custom_ball_bearing = ball_bearing_info(id=17, od=35, width=14, shield=true, flange=false, as_struct=true);
ball_bearing(my_custom_ball_bearing);

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions