merge sketches

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
User avatar
pablogil
Posts: 861
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: merge sketches

Postby pablogil » Fri Jul 26, 2019 10:44 pm

cool!
thanks
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
krisky
Posts: 3
Joined: Mon Sep 13, 2021 2:28 am

Re: merge sketches

Postby krisky » Mon Sep 13, 2021 5:06 am

Hi,

I'm new to this forum, please be gentle on me.. Windows 10, FreeCAD 0.19

I am trying to automate the "Merge Sketches" functionality in a Python macro, but when I record the macro and run it again, it does not reproduce the merge (I select the sketches to merge before I run the macro, but it seems to just create a new empty sketch).

Code: Select all

# -*- coding: utf-8 -*-

# Macro Begin: C:\Users\...\AppData\Roaming\FreeCAD\Macro\merges4.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
import FreeCAD
import Sketcher

# Gui.runCommand('Std_DlgMacroRecord',0)
# Gui.Selection.addSelection('ninja','Body','Sketch.')
# Gui.Selection.addSelection('ninja','Body','Sketch018.')
### Begin command Sketcher_MergeSketches
App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch019')
App.activeDocument().ActiveObject.Placement = App.activeDocument().Sketch.Placement
App.activeDocument().recompute()
### End command Sketcher_MergeSketches
# Macro End: C:\Users\...\AppData\Roaming\FreeCAD\Macro\merges4.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
Any thoughts? Ideally I'd like to get to a situation where I don't have to select the sketches in the GUI in order to merge them, but instead reference them as objects from the script.

Thanks
Last edited by krisky on Mon Sep 13, 2021 6:13 am, edited 1 time in total.
chrisb
Posts: 37120
Joined: Tue Mar 17, 2015 9:14 am

Re: merge sketches

Postby chrisb » Mon Sep 13, 2021 6:28 am

In this case MergeSketches doesn't log everything in the console, so it is not enough to run the recorded macro. You would have to add the geometric elements to the list and the constraints. For the first sketch this is just a copy, but for the second you have to adapt the constraints to the new element numbers.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
krisky
Posts: 3
Joined: Mon Sep 13, 2021 2:28 am

Re: merge sketches

Postby krisky » Mon Sep 13, 2021 8:56 am

Thanks ChrisB! I suspected the recorded macro didn't capture everything, thanks for confirming.

As it happens, I am trying to do this as a workaround, I am trying to generate a sketch by using Python to add the geometry and constraints one by one. It slows down rapidly and grinds to a halt after not too long, and I'm not sure why.

However, I found that generating individual chunks of the sketch in different "sub-sketches" and then merging these is much faster, for some reason, but I can't seem to access the actual function to do this. My worry is that copying over the elements and adapted constraints one by one, from one sketch to another, will simply hit the same performance problem as it grows.

Is there anything about the way that the "Merge Sketches" function does this that is more efficient? For example, aggregate the elements into lists and add them all at once, or similar?

Thanks!
chrisb
Posts: 37120
Joined: Tue Mar 17, 2015 9:14 am

Re: merge sketches

Postby chrisb » Mon Sep 13, 2021 2:12 pm

I am not really familiar with Sketch scripting, but it sounds as if after each adding a recompute is performed. So it could be sensible to create all geometry at once and all constraints too.

It is in general not recommended to make sketches too complicated. 100 constraints are already a lot, and you may consider to create and use several sketches on purpose. FreeCAD can handle 100 or even 150 constraints still very well, but for the sake of clarity you shouldn't use many more.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
krisky
Posts: 3
Joined: Mon Sep 13, 2021 2:28 am

Re: merge sketches

Postby krisky » Tue Sep 14, 2021 12:30 am

Thanks, I'll try it. I also found what is probably a better way, since I am trying to create a fairly complex path with a number of spline sections, importing this as SVG into Draft and converting to a sketch works well (although I suspect I may still need to add some constraints after, as Part Design doesn't seem to recognise the edges somehow). Thanks for your help!
chrisb
Posts: 37120
Joined: Tue Mar 17, 2015 9:14 am

Re: merge sketches

Postby chrisb » Tue Sep 14, 2021 5:11 am

krisky wrote: Tue Sep 14, 2021 12:30 am Thanks, I'll try it. I also found what is probably a better way, since I am trying to create a fairly complex path with a number of spline sections, importing this as SVG into Draft and converting to a sketch works well (although I suspect I may still need to add some constraints after, as Part Design doesn't seem to recognise the edges somehow). Thanks for your help!
Adding constraints to B-splines may help with tangencies or coincidences on the endpoints, but note that you cannot use point-on-object or similar on the inner part of a spline.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.