Screw Maker

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Yan
Posts: 10
Joined: Sat May 14, 2016 6:43 am

Re: Screw Maker

Post by Yan »

Hi,
nice work, looks like very useful piece of code ;)

I've issue with screw-maker script. 4014, 4017, 4032,4033 and 4035 hex's looks like broken in my case (probably some boolean operation is inverted, attached image should be self-explanatory). Screws which are not "hex-based" work's fine for me.

I dont know what could cause the problem - tried version 1.7 and 2.0, both looks broken same-way.

Code: Select all

Freecad ver. 0.16 64-bit archlinux
Python 2 version: 2.7.11-3
Attachments
problem.jpg
problem.jpg (55.27 KiB) Viewed 3259 times
cox
Posts: 971
Joined: Wed Nov 26, 2014 11:37 pm

Re: Screw Maker

Post by cox »

Yan wrote:I dont know what could cause the problem - tried version 1.7 and 2.0, both looks broken same-way.
It is a known issue, https://github.com/shaise/FreeCAD_FastenersWB/issues/1
Need help? Feel free to ask, but please read the guidelines first
Yan
Posts: 10
Joined: Sat May 14, 2016 6:43 am

Re: Screw Maker

Post by Yan »

SOLVED

took me quite a while ..

Code: Select all

    def makeHextool(self,s_hex, k_hex, cir_hex):
    # makes a cylinder with an inner hex hole, used as cutting tool
    # create hexagon face
    mhex=Base.Matrix()
    mhex.rotateZ(math.radians(60.0))
    polygon = []
    vhex=Base.Vector(s_hex/math.sqrt(3.0),0.0,-k_hex*0.1)
    for i in range(6):
       polygon.append(vhex)
       vhex = mhex.multiply(vhex)
    polygon.append(vhex)
    hexagon = Part.makePolygon(polygon)
    hexagon = Part.Face(hexagon)

    # create circle face
    circ=Part.makeCircle(cir_hex/2.0,Base.Vector(0.0,0.0,-k_hex*0.1))
    circ=Part.Face(Part.Wire(circ))


    # Create the face with the circle as outline and the hexagon as hole
    face=circ.cut(hexagon)
    
    # Extrude in z to create the final cutting tool
    exHex=face.extrude(Base.Vector(0.0,0.0,k_hex*1.2))
    # Part.show(exHex)
    return exHex
    
lines in original code: 3982-4002 for version 2.0

Problem was that face creation from hexagon and circle failed, so there is need to create each of one manually an than cut them to obtain apropiate face.
cox
Posts: 971
Joined: Wed Nov 26, 2014 11:37 pm

Re: Screw Maker

Post by cox »

Nice going, Yan :D
Need help? Feel free to ask, but please read the guidelines first
User avatar
shaise
Posts: 470
Joined: Thu Jun 11, 2015 8:11 am

Re: Screw Maker

Post by shaise »

Nice work Yan!!

I have checked in your fix to github.
Can you guess why this problem occurred on some systems but not on others?

shai
Yan
Posts: 10
Joined: Sat May 14, 2016 6:43 am

Re: Screw Maker

Post by Yan »

Hi,
I have same OS as kkosvik. There is only one problem with that single operation where "cutting tool" for head is created. My personal guess is that problem is in different version of Python2, but it is only guess "based on absolutely nothing".

Operation which was wrong was making face from edges (Part.Face function) - I dont know in which language this function is written. Img - "correct" - what Part.Face function should do, "wrong" what it is doing with newer version of whatever it causes. My wokraround is longer by two commands so I think it is no big deal if it works for everybody. If it was something in "screw generating" part of code, that could be issue (as every command in this part is cycled many times i presume).

Code which acts obviously different with pasted results (line # in original screw_maker2_0.py macro):

Code: Select all

3997 face=Part.Face([Part.Wire(circ),hexagon])
I dont know which output authors of Part.Face intended to generate, but I think it one that is generated with older version of ***, or Part.Face isn't even meant to generate more complex geometries. (Only guess again)
result of Part.Face
result of Part.Face
fixing.jpg (14.01 KiB) Viewed 3211 times

Link to apropriate wiki entry where i found little more about that (and used as help for solution), but not much about source code/language: http://www.freecadweb.org/wiki/index.ph ... ing_a_Face
User avatar
shaise
Posts: 470
Joined: Thu Jun 11, 2015 8:11 am

Re: Screw Maker

Post by shaise »

Yan,

I think your solution is not a "workaround" but probably the correct way of doing it.
Anyway it seems to work good and, as said, I have implemented your fix in the Fasteners workbench.
However, my workbench is just a wrapper to ulrich1's screw_maker, so he need to fix it as well in his code for those who use the macro directly.

Thanks!

shai
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Screw Maker

Post by ulrich1a »

Yan wrote:Code which acts obviously different with pasted results (line # in original screw_maker2_0.py macro):

Code: Select all

3997 face=Part.Face([Part.Wire(circ),hexagon])
This may be related to this problem: viewtopic.php?f=22&t=13342

I will see, if it make sense to generate the hex-wire not with the polygon-function.

Ulrich
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Screw Maker

Post by ulrich1a »

Yan, can you test if the following code generates a valid hex-cutting-tool at your system? This could be another workaround.

For me it looks like, that the hexagon face is generated differently at some systems. But it could also be the circle. I would call it in both cases a bug.

Ulrich
Attachments
face_test.py.zip
test-macro to evaluate workaround
(1.23 KiB) Downloaded 96 times
Yan
Posts: 10
Joined: Sat May 14, 2016 6:43 am

Re: Screw Maker

Post by Yan »

Hi ulrich1a,
thx for your macro. ;)

About face_test.py:

Both (makeHextool, makeHextool2) gave me the "wrong" hex-cutting-tool - deformed same way as in original code.

Relation to problem you mentioned in previous msg looks very probably to me, but I'm not coder. From that link only thing I understood is that creating "multi bounded face" could be pretty tricky nowadays. :mrgreen:
Attachments
face_test_result.jpg
face_test_result.jpg (3.56 KiB) Viewed 3140 times
Post Reply