dxf splines with ezdxf (python)

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!
amka
Posts: 63
Joined: Thu Sep 03, 2015 6:28 pm

Re: dxf splines with ezdxf (python)

Post by amka »

Hi,

In some weeks I will need this fix, so I wonder if :

1. I have to do ALL this : http://www.freecadweb.org/wiki/CompileOnUnix (with the bug fix in the source).
2. Is it perhaps possible to do more simple ? Will the 0.17 come please soon ?

Best regards :)

amka
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: dxf splines with ezdxf (python)

Post by Kunda1 »

amka wrote:Hi,

In some weeks I will need this fix, so I wonder if :

1. I have to do ALL this : http://www.freecadweb.org/wiki/CompileOnUnix (with the bug fix in the source).
2. Is it perhaps possible to do more simple ? Will the 0.17 come please soon ?

Best regards :)

amka
1. yes (when you pull from the FreeCAD git repo the fix is already in the source
2. give it a try first. 0.17 is not slated for anytime soon.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: dxf splines with ezdxf (python)

Post by sgrogan »

amka wrote:Have I then please to compile FreeCad if I want to open my dxf ?
yorik wrote:Yes, or, wait for someone to compile for you :)
FreeCAD now offers occasional appimages for the development version.
Download the latest appimage (currently FreeCAD-0.17.git201703220057.glibc2.17-x86_64.AppImage) make the file executable and run FreeCAD.
https://github.com/FreeCAD/FreeCAD/rele ... g/0.17_pre
"fight the good fight"
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: dxf splines with ezdxf (python)

Post by chakkree »

Before run code, install ezdxf package to FreeCAD.
use PowerShell and change directort(cd) to ..\FreeCAD_0.17.10698_x64_dev_win\bin
and type

Code: Select all

./python -m easy_install ezdxf
Double-Click to open FreeCAD and run code.
But I'm not sure spline in dxf and BSpline in FreeCAD are the same curve.

Code: Select all

import os
import Draft
import ezdxf
from FreeCAD import Vector


filePath, fileName = os.path.split(__file__)
drawing = ezdxf.readfile(filePath+os.sep+"ezdxf_spline.dxf")

modelspace = drawing.modelspace()

splines = modelspace.query('SPLINE')
Msg('n=%d\n'% len(splines))

points=splines[0].get_fit_points()
points2 = []
for i in points:
    points2.append(Vector(i))

line = Draft.makeWire(points2,closed=False,face=False,support=None)
spline = Draft.makeBSpline(points2,closed=False,face=False,support=None)
bez = Draft.makeBezCurve(points2,closed=False,support=None)
#list(drawing.entities)

Msg('Done!\n\n')

Output.PNG
Output.PNG (28.92 KiB) Viewed 2158 times
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.10698 (Git)
Build type: Release
Branch: master
Hash: ac2f9f8902b67143ea081fedc9ffed86fc1a1bd3
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0
Last edited by chakkree on Tue May 23, 2017 4:59 am, edited 1 time in total.
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: dxf splines with ezdxf (python)

Post by Chris_G »

But I'm not sure spline in dxf and BSpline in FreeCAD are the same curve.
Draft.makeBSpline( PTS ) creates an interpolating BSpline curve that goes through the PTS.
So, in that case, PTS are not the control points of the BSplineCurve.
If you want to create a BSplineCurve from its control points, you should use :

Code: Select all

bs = Part.BSplineCurve(pts)
Part.show(bs.toShape())
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: dxf splines with ezdxf (python)

Post by chakkree »

Dashed Line is made from Part.BSplineCurve.
It's the same makeBSpline().

Code: Select all

import os
import ezdxf
import Part
import Draft
from FreeCAD import Vector


filePath, fileName = os.path.split(__file__)
drawing = ezdxf.readfile(filePath+os.sep+"ezdxf_spline.dxf")

modelspace = drawing.modelspace()

splines = modelspace.query('SPLINE')
Msg('n=%d\n'% len(splines))

points=splines[0].get_fit_points()


line = Draft.makeWire(points,closed=False,face=False,support=None)
spline = Draft.makeBSpline(points,closed=False,face=False,support=None)
bez = Draft.makeBezCurve(points,closed=False,support=None)

bs = Part.BSplineCurve()
bs.interpolate(points,False)
Part.show(bs.toShape())

#list(drawing.entities)

Msg('Done!\n\n')

Output2.PNG
Output2.PNG (32.97 KiB) Viewed 2140 times
Last edited by chakkree on Tue May 23, 2017 4:59 am, edited 1 time in total.
amka
Posts: 63
Joined: Thu Sep 03, 2015 6:28 pm

Re: dxf splines with ezdxf (python)

Post by amka »

Thanks you all :) and
sgrogan wrote: FreeCAD now offers occasional appimages for the development version.
Download the latest appimage (currently FreeCAD-0.17.git201703220057.glibc2.17-x86_64.AppImage) make the file executable and run FreeCAD.
https://github.com/FreeCAD/FreeCAD/rele ... g/0.17_pre
Do you please know where I can find such a freecad for linux ?
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: dxf splines with ezdxf (python)

Post by sgrogan »

amka wrote:Do you please know where I can find such a freecad for linux ?
From my previous link this, file Direct Link to .AppImage Download

Code: Select all

https://github.com/FreeCAD/FreeCAD/releases/download/0.17_pre/FreeCAD-0.17.git201703220057.glibc2.17-x86_64.AppImage
"fight the good fight"
amka
Posts: 63
Joined: Thu Sep 03, 2015 6:28 pm

Re: dxf splines with ezdxf (python)

Post by amka »

Thanks, this Freecad works !
amka
Posts: 63
Joined: Thu Sep 03, 2015 6:28 pm

Re: dxf splines with ezdxf (python)

Post by amka »

Thank you a lot for these informations !
chakkree wrote:Before run code, install ezdxf package to FreeCAD.
use PowerShell and change directort(cd) to ..\FreeCAD_0.17.10698_x64_dev_win\bin
and type

Code: Select all

./python -m easy_install ezdxf
And where have I to do this ? I did :

Code: Select all

root@debian:/usr/lib/freecad/bin# ls -l
total 48
-rwxr-xr-x 1 root root 28368 mai 22  2016 FreeCAD
-rwxr-xr-x 1 root root 17256 mai 22  2016 FreeCADCmd
root@debian:/usr/lib/freecad/bin# python -m easy_install ezdxf
Searching for ezdxf
Best match: ezdxf 0.8.1
Adding ezdxf 0.8.1 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Processing dependencies for ezdxf
Finished processing dependencies for ezdxf
My FreeCAD version is 0.16. Perhaps it is possible to do the same with the appimage (version 0.17) of the post before ?
chakkree wrote: Double-Click to open FreeCAD and run code.
But I'm not sure spline in dxf and BSpline in FreeCAD are the same curve.

Code: Select all

import os
import ezdxf
from FreeCAD import Vector


filePath, fileName = os.path.split(__file__)
drawing = ezdxf.readfile(filePath+os.sep+"ezdxf_spline.dxf")

modelspace = drawing.modelspace()

splines = modelspace.query('SPLINE')
Msg('n=%d\n'% len(splines))

points=splines[0].get_fit_points()
points2 = []
for i in points:
    points2.append(Vector(i))

line = Draft.makeWire(points2,closed=False,face=False,support=None)
spline = Draft.makeBSpline(points2,closed=False,face=False,support=None)
bez = Draft.makeBezCurve(points2,closed=False,support=None)
#list(drawing.entities)

Msg('Done!\n\n')

Can you please explain me where to put this code ? I don't understand.

Regards :)
Post Reply