Scripting example and scripting challenge.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Scripting example and scripting challenge.

Post by onekk »

Some advancement and first problem.

New code with some improvement.
engine_wheel-v4.py
(14.1 KiB) Downloaded 24 times
But the problem is sprockets, fillets.

I have thought of making sections and enlarging them via makeOffset2D.

the code is active in the new file.

I correctly obtain the sections at different height, using some trick:

Code: Select all

def test_spr_sec():
    """Test sectioning."""
    # make hub for cutting
    #c_hub = mk_hub(fuse_play)

    spkts = mk_sprockets(0.40, 0.75)

    spkts_c = Part.makeCompound(spkts)

    Part.show(spkts_c, "sprockets")

    # try to define a "law" to make hub sprockets fillets
    cen_rad_min = hu_rad
    cen_rad_max = hu_lv_rad + hu_lv_ia

    print("center radii, min: {0} max: {1}".format(cen_rad_min, cen_rad_max))

    # hub side fillets
    hu_fi_dim = (rim_nrad - cen_rad_max) / hu_fi_fac

    # same as above for rim fillets
    # rim_fi_dim = (rim_nrad - cen_rad_max) / hu_rim_fac

    rec_fac = hu_fi_dim / 5

    plays = (
        fuse_play * 0.5,
        rec_fac * -1,
        rec_fac * -2,
        rec_fac * -3,
        rec_fac * -4,
        rec_fac * -5,
    )

    print(plays)

    enlarg = 10
    enl_fact = enlarg / len(plays)

    for s_idx, play in enumerate(plays):

        sect_t = section_sprockets(play)

        Part.show(sect_t, "section{}".format(s_idx))

        shapes = []
        for idx, spkt in enumerate(spkts_c.Solids):
            result = sect_t.common(spkt)
            wire = result.Faces[0].Wires[0]
            #comp_wire = wire.makeOffset2D(enlarg - enl_fact * s_idx)
            Part.show(wire, "section{}_{}".format(s_idx, idx))
            shapes.append(result)

Not so elegant, I've hardcoded some distance from the "hub cut solids" and created enlarged extruded wires to obtain section at different heights.

We could not model a single sprocket as the hub is not circular, so many sprockets have different position for the fillet.

I have thought of making these sections, enlarging them using makeOffset2D and then loft the profiles to obtain a solid and fuse to each sprocket in the correct place.

We could determine a different law using maybe two diameter for enlarging and obtain properly spaced sections.

But "sections are not planar" and makeOffset2D raise an error.
eng_whhel_sect1.png
eng_whhel_sect1.png (8.09 KiB) Viewed 351 times
eng_wheel_sect2.png
eng_wheel_sect2.png (2.34 KiB) Viewed 351 times
EDIT:
Strange enough a little problem, see the image below
eng_wheel_sect3.png
eng_wheel_sect3.png (5.74 KiB) Viewed 330 times
Image above is with the actual code

EDIT2: for a couple of minute I have posted here a wrong version, sorry for any inconvenience, and for my english too.

Section is not working perfectly when at the tangent point of the wire, probably there are some calculations that use some length like tangent that is infinite at this point, resulting in a distorted shape. Probably using a plane problem will not occur.

There is a way to obtain some data and make a plane to cut the sprocket and obtain a planar section?.

Problem is automating things, based on existing shapes I have though of using sprocket axis and determine a position and the orthogonal line to sprocket axis.

As usual some Vector math is involved.

TIA and Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply