BSPline to Sketch

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
leoheck
Posts: 95
Joined: Tue Mar 13, 2018 5:56 pm

BSPline to Sketch

Postby leoheck » Thu Aug 22, 2019 1:57 am

Is there any way to convert a BSPline to a sketch?
It will be also good to know it in python if possible.
openBrain
Posts: 1767
Joined: Fri Nov 09, 2018 5:38 pm

Re: BSPline to Sketch

Postby openBrain » Thu Aug 22, 2019 2:43 am

vocx
Posts: 921
Joined: Thu Oct 18, 2018 9:18 pm

Re: BSPline to Sketch

Postby vocx » Thu Aug 22, 2019 4:01 am

leoheck wrote:
Thu Aug 22, 2019 1:57 am
Is there any way to convert a BSPline to a sketch?
It will be also good to know it in python if possible.
Internally the Draft Draft2Sketch tool uses two methods to convert to Sketch, or to Draft.

Code: Select all

import Draft
Draft.makeSketch(objectslist, autoconstraints=False, addTo=None, delete=False, name="Sketch", radiusPrecision=-1)

Draft.draftify(objectslist, makeblock=False, delete=True)
leoheck
Posts: 95
Joined: Tue Mar 13, 2018 5:56 pm

Re: BSPline to Sketch

Postby leoheck » Thu Aug 22, 2019 12:22 pm

I am using a macro to generate a BSpline. But I was not able to generate a sketch with that @openBrain

@vocx thanks I will give it a try.
leoheck
Posts: 95
Joined: Tue Mar 13, 2018 5:56 pm

Re: BSPline to Sketch

Postby leoheck » Thu Aug 22, 2019 1:35 pm

The macro I am modifying is using these wirePoints to make a BSPline

Code: Select all

wirePoints.append(FreeCAD.Base.Vector(x,y,0))
Making a BSpline with this.

Code: Select all

Draft.makeBSpline(wirePoints)
I would like to convert this BSPline to a sketch so I can use/modify it with Part Design Workbench.
With the GUI it was not possible and using this didn't work.

All of this effort is because I have failed using BSplines manually directly in Sketch, I can't make the shape I want, I cant lock its features so I can move it freely on the plane.

Code: Select all

Draft.makeSketch(wirePoints, autoconstraints=False, addTo=None, delete=False, name="Sketch", radiusPrecision=-1)
The report view has this output

Code: Select all

Traceback (most recent call last):
  File "/home/lheck/.FreeCAD/Macro/squircle.FCMacro", line 35, in <module>
    Draft.makeSketch(wirePoints, autoconstraints=False, addTo=None, delete=False, name="Sketch", radiusPrecision=-1)
  File "/usr/share/freecad/Mod/Draft/Draft.py", line 2205, in makeSketch
    elif not obj.isDerivedFrom("Part::Feature"):
<class 'AttributeError'>: 'Base.Vector' object has no attribute 'isDerivedFrom'
Edit: Adding extra info from here.

I am using the macro given here https://forum.freecadweb.org/viewtopic.php?f=3&t=37604 as a starting point.
vocx
Posts: 921
Joined: Thu Oct 18, 2018 9:18 pm

Re: BSPline to Sketch

Postby vocx » Thu Aug 22, 2019 5:36 pm

leoheck wrote:
Thu Aug 22, 2019 1:35 pm

Code: Select all

Draft.makeSketch(wirePoints, autoconstraints=False, addTo=None, delete=False, name="Sketch", radiusPrecision=-1)
It seems that wirePoints is a list of points. You do not pass this to makeSketch(). First, create your BSpline object, and then pass it to makeSketch() to turn it into a Sketch.

Code: Select all

wirePoints = [FreeCAD.Vector(1,2,0), FreeCAD.Vector(4,5,0), ...]
object = Draft.makeBSpline(wirePoints)
new = Draft.makeSketch(object, autoconstraints=True)