Yes I can chime in with the problem you're trying to solve because I have created some MASSIVE designs in a very similar tool (called OpenSCAD). Just a disclaimer, I come from a computer science and mathematics background, so I describe an approach taken in the field of 3D computer graphics. I am not exactly sure what carpenters or mechanical engineers are taught when they study their respective arts. I think the use of tools such as computers is relatively new to all areas of study, so there is room for exploration, discovery, and innovation.
In the topic of 3D computer graphics courses that you would take at a higher learning institution, the jargon they would use for what you're referring to is a "scene graph". To render a scene, you traverse the entire "tree" or "graph", where as you descend into each branch or node there is associated with it a transformation (3D translation and 3D rotation, or change of coordinate axes). In other words you try to make everything highly orderly and highly organized. This is probably the most difficult task in engineering in general, which is how to be highly organized.
The other dimension along which you bring up a good point is whether to use functional/procedural programming paradigm or an object oriented approach. I prefer the functional/procedural approach for the kinds of stuff you're describing, but this is a matter of opinion.
To begin you can try defining your lowest leaf node, the 2x4 stud. A parameter you may take as input would be the length.
def two_by_four(length):
...
return stud
Above you would create a paradigm of where the stud is centered (or not centered). This is by your choice, but you would typically start to rigorously model your design not only in the code but also in API comments left immediately before the method declarations, as to the exact locations/orientations of objects returned by the methods. Essentially you want to encapsulate everything and forget about the gory details, unless you're working on the gory details.
You could then start building the wall, but as a carpenter you'd know how far apart to space the two by four's. Or maybe the spacing is configurable. Maybe the wall could take a height, a length, and the spacing between two by fours.
def wall(height, length, spacing):
....
return wall
Inside the code of wall() you would instantiate many two by fours. Yes, the technical term for this in computer graphics jargon is "instantiation".
And so on. It's like building things out of Lego blocks.
In my case I have such intricate parts, I have a differential, a top shaft, a chassis, a motor mount, a front differential, etc. and all of those parts are defined in a coordinate system which makes sense for that part. Each of those assemblies is divided into node parts, which are the leaf modes. Then a monster function combines all assemblies by transforming them properly into the chassis coordinate system.
One approach I take as well, which may not be suitable in your case, is I tend to define LOTS of various constants in an external file which contains JUST CONSTANTS. Then that constants file is imported by all other files that define parts. In this way I can quickly find and make a change, by only looking at a constants file and not through the entire multi-file code. Code ends up always relying on the constants and the code NEVER hardcodes numerical values in logic, unless it is something harmless like an epsilon value to get overlaps.
##### GENERAL GEAR PROPERTIES #################################################
gear_pitch_48 = 1.66243 # The 'mm_per_tooth' value passed to spur_gear().
tooth_pressure = 25 # Pressure angle of gear tooth profile in degrees.
##### DIFF GEAR SECTION BELOW #################################################
n_diff_gear_teeth = 59 # 59t diff gear & 16t drive gear have been decided upon.
mm_diff_gear_width = 9 # Width of diff gear; change far-reaching effect.
n_diff_balls = 8 # Also number of rear belt pulley prongs.
mm_diff_ball = 3.175 # Diameter of rear diff ball, 1/8 inch.
mm_diff_ball_wiggle = 0.08 # Radial wiggle around the diff ball. The holes in
# the diff gear where the diff balls ride will be
# larger in diameter than the diff ball by twice
# this amount.
mm_diff_ball_protrusion = 0.15 # The amount by which the diff balls protrude
# past the diff gear walls, to be better grabbed
# by the diff rings. Multiply this value by two
# and subtract it from the diff ball diameter to
# arrive at the diff gear inner wall thickness.
mm_diff_gear_recess_diameter = 23.5 # Diameter of inner cylinder for rear
# pulley prongs. That cylinder aligns
# perfectly with the cavity diameter of
# diff gear.
z_max_diff_ring = 5.0/2
In my case the constants files end up being at least 500 lines of code, sometimes 1000.
Hope that helps. Welcome to the world of computer graphics and CAD modeling. I am sure that you will enjoy your stay. You can use the coffee machine over there if you need some stimulation. I hope you get inspired, and please bear in mind that there is not absolutely correct or absolutely wrong way of doing things; there is only better and worse, and usually it's a matter of opinion.