[needed workaround for 0.20.0] Sketch placement is not working?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

[needed workaround for 0.20.0] Sketch placement is not working?

Post by dprojects »

This is continuation from this topic: Sketch vs Extrude - how sketch is working?

Currently I am testing @TheMarkster script and it looks like the Sketch is broken. I have similar problem with Sketch positioning in my code, and I was thinking it is bug only in my code but looks like other code samples also not working too. The face is created in the right place but the Sketch is somewhere, I don't understand.... is there any logic behind the Sketch positioning? looks like it is no matter if the Sketch is attached (by Support) or not it is always created in wrong place...?

Anyone know what is going on? is it normal? this is FreeCAD bug? are there any workaround for that?

Image
Last edited by dprojects on Mon Oct 03, 2022 2:46 pm, edited 2 times in total.

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
heron
Posts: 307
Joined: Mon Apr 20, 2020 5:32 pm

Re: Sketch placement is not working?

Post by heron »

dprojects wrote: Fri Sep 30, 2022 7:16 pm Anyone know what is going on? is it normal? this is FreeCAD bug? are there any workaround for that?
Hello Darek, I believe that in any case would be a bug of Draft.makeSketch(), in order to be a bit more specific.

Did you try changing the Map Reversed property of the sketch to True?

I was testing the macro with a simple cube of Part Wb and the results are:
- Face3 and Face6 -> the sketchs are placed in their correct position above the face
- Face1, Face2 and Face5 -> by changing the Map Reversed property of the sketchs, they are placed correctly
- Face4 -> the sketch position is outside the face whatever the Map Reversed property setting

Code: Select all

>>> help(Draft.makeSketch)
Help on function make_sketch in module draftmake.make_sketch:

make_sketch(objects_list, autoconstraints=False, addTo=None, delete=False, name='Sketch', radiusPrecision=-1, tol=0.001)
    make_sketch(objects_list, [autoconstraints], [addTo], [delete],
                   [name], [radiusPrecision], [tol])
    
    Makes a Sketch objects_list with the given Draft objects.
    
    Parameters
    ----------
    objects_list: can be single or list of objects of Draft type objects,
        Part::Feature, Part.Shape, or mix of them.
    
    autoconstraints(False): if True, constraints will be automatically added to
        wire nodes, rectangles and circles.
    
    addTo(None) : if set to an existing sketch, geometry will be added to it
        instead of creating a new one.
    
    delete(False): if True, the original object will be deleted.
        If set to a string 'all' the object and all its linked object will be
        deleted.
    
    name('Sketch'): the name for the new sketch object.
    
    radiusPrecision(-1): If <0, disable radius constraint. If =0, add individual
        radius constraint. If >0, the radius will be rounded according to this
        precision, and 'Equal' constraint will be added to curve with equal
        radius within precision.
    
    tol(1e-3): Tolerance used to check if the shapes are planar and coplanar.
        Consider change to tol=-1 for a more accurate analysis.

I can't be of any more help at the moment, I'll try to investigate further if I got time.
Attachments
test_draft_makeSketch.FCStd
(18.52 KiB) Downloaded 16 times
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Sketch placement is not working?

Post by dprojects »

heron wrote: Sat Oct 01, 2022 7:10 am Hello Darek, I believe that in any case would be a bug of Draft.makeSketch(), in order to be a bit more specific.
Did you try changing the Map Reversed property of the sketch to True?
Hi heron ;-) The Map Reversed may works for simple Cube but for other objects it only rotate the Sketch. see attached file face2sketch_testing.FCStd.
However, I believe this can be fixed somehow. This looks like problem with center of coordinate axes. If you edit the Sketch the center is in wrong position. but if try to set the center via AttachementOffset at Sketch, the Sketch has rotated axis vertices. They are adjusted to currently chosen plane not to the global placement. This is fine if the Sketch is attached to the straight plane but if it is attached to "rotated object" there is problem with the Sketch.

I believe this can be fixed somehow, I don't have knowledge about the Sketch. I want to do it with this way because Pad is more realistic in case of woodworking. See the attached file Extrude_Vs_Pad_difference.FCStd and gif below. It show the difference between normal face.extrude and the Pad on face. If you create face.extrude the objects is not like piece of wood, the edge has not 90 degree everywhere. If you make Pad at face the top face of the Pad preserves the angle of the face bottom, like in real-life while you create something from wood pieces.

I was reading that Part.extrude has some options for extrude to make it like in the Pad but Pad is in my opinion better option because it is editable, I will be able to use any tool on that ;-) even smart resize ;-) what would be epic ;-) I believe this is possible to do but I need to investigate the problem and learn little bit more.

But maybe someone already know how to deal with attached Sketch to the face (not straight, flat, but with angle, custom shape)? how to set the center of coordinate axes? I saw there is something like LCS but I didn't tested this yet... maybe this would force the Sketch into the right position?

Image
Attachments
Extrude_Vs_Pad_difference.FCStd
(19.74 KiB) Downloaded 14 times
face2sketch_testing.FCStd
(14.2 KiB) Downloaded 14 times

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Sketch placement is not working?

Post by Roy_043 »

There was an issue with Draft.make_sketch():
https://github.com/FreeCAD/FreeCAD/pull/7071
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Sketch placement is not working?

Post by dprojects »

Roy_043 wrote: Sat Oct 01, 2022 9:02 am There was an issue with Draft.make_sketch():
https://github.com/FreeCAD/FreeCAD/pull/7071
Holly cow ;-) Thanks Roy, this works at the latest 0.21_weekly build. However, I really like Draft developer, I think Draft is best workbench, has best API, written by intelligent developer. The worst is Sketch, IMHO.

No matter, but I have problem now, because I am not able to switch woodworking workbench to the newest weekly build. It is not possible to create anything reliable or stable based on weekly builds. Also I don't want to postpone this feature until the 0.21 version will be released. It would be best option because there will be also fix with pickedpoints, so I could even make single click feature just like that.

So I need to find some kind of workaround for that, to get it to work at 0.20 ;-) This might be hard but I will try and leave this topic open until I give up or find solution ;-)

Image

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: [needed workaround for 0.20] Sketch placement is not working?

Post by Roy_043 »

The PR was backported and is included in V0.20.1.
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: [needed workaround for 0.20] Sketch placement is not working?

Post by dprojects »

Roy_043 wrote: Sat Oct 01, 2022 3:27 pm The PR was backported and is included in V0.20.1.
I decided to create release 0.20: https://github.com/dprojects/Woodworking/releases and freeze it at this stage.
The master branch will be cutting edge features.... and maybe next release will be after FreeCAD 0.21 release.
This approach will be more convenient to me... and also people will be able to get this feature more quickly.

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
heron
Posts: 307
Joined: Mon Apr 20, 2020 5:32 pm

Re: [needed workaround for 0.20] Sketch placement is not working?

Post by heron »

Hello,
Then Draft.make_sketch() works fine, the problem is in macro when setting the Support and Map Mode properties of the sketch. Without setting this properties the sketch is located correctly by modifing its placement.
In fact, selecting the face in the 3d view, only these three lines are enough:

Code: Select all

sel = FreeCADGui.Selection.getSelectionEx()
face = sel[0].SubObjects[0]
sk = Draft.make_sketch(face, autoconstraints=True)       
Test_sketch_face.gif
Test_sketch_face.gif (438.07 KiB) Viewed 749 times
Here is the attached file with a text document where there are the necessary lines of code and the instructions to execute from the Python console without the need to execute any macro.
Attachments
face2sketch_testing_2.FCStd
(22.1 KiB) Downloaded 16 times
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: [needed workaround for 0.20] Sketch placement is not working?

Post by dprojects »

heron wrote: Sun Oct 02, 2022 5:04 pm Then Draft.make_sketch() works fine
For 0.20.0 no matter if you use Draft.make_sketch() or deprecated Draft.makeSketch(). Roy said it has been backported so this may work at 0.20.1. What FreeCAD version you use?

However I decided to release the feature at development master branch, and freeze 0.20 at this stage. Probably the answer is in the Roy's fix. Someday if I will find time I will look into that because it is good to know what caused this strange behavior of the Sketch.

phpBB [video]

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: [needed workaround for 0.20.0] Sketch placement is not working?

Post by onekk »

If you see in sources at least from what I know, the deprecated form is simply redirecting to the new make_sketch().

This is quite common in new Draft function code rewriting, only few functions are really different, many if them have function name changed and there is a redirection from the old writing to the new code to retain compatibility with older calls.

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