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!
Post Reply
leoheck
Veteran
Posts: 1223
Joined: Tue Mar 13, 2018 5:56 pm
Location: Coffee shop

BSPline to Sketch

Post by leoheck »

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

Re: BSPline to Sketch

Post by openBrain »

vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: BSPline to Sketch

Post by vocx »

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)
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
leoheck
Veteran
Posts: 1223
Joined: Tue Mar 13, 2018 5:56 pm
Location: Coffee shop

Re: BSPline to Sketch

Post by leoheck »

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
Veteran
Posts: 1223
Joined: Tue Mar 13, 2018 5:56 pm
Location: Coffee shop

Re: BSPline to Sketch

Post by leoheck »

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
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: BSPline to Sketch

Post by vocx »

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)
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Post Reply