Creating B-Splines from imported ASC file

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
hooshsim
Posts: 108
Joined: Mon Nov 05, 2018 7:40 pm

Creating B-Splines from imported ASC file

Post by hooshsim »

Does FreeCAD have an option to convert points imported from ASC file into B-Splines automatically or we have to create them ourselves manually using B-Spline in draft WB?
Thanks - Hooshsim
User avatar
jnxd
Posts: 951
Joined: Mon Mar 30, 2015 2:30 pm
Contact:

Re: Creating B-Splines from imported ASC file

Post by jnxd »

Maybe my own ignorance: what is an ASC file? Juwt ASCII text?
My latest (or last) project: B-spline Construction Project.
User avatar
jnxd
Posts: 951
Joined: Mon Mar 30, 2015 2:30 pm
Contact:

Re: Creating B-Splines from imported ASC file

Post by jnxd »

@hooshsim forgot to tag you for above question. I don't know if it works if I edit.
My latest (or last) project: B-spline Construction Project.
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Creating B-Splines from imported ASC file

Post by wmayer »

jnxd wrote: Fri Jan 27, 2023 2:20 am Maybe my own ignorance: what is an ASC file? Just ASCII text?
It's a very simple format of a point cloud where in each line you have three coordinates:
Example:

Code: Select all

0.0000 0.0000 0.0000
0.1234 1.0345 2.6578
....
thschrader
Veteran
Posts: 3154
Joined: Sat May 20, 2017 12:06 pm
Location: Germany

Re: Creating B-Splines from imported ASC file

Post by thschrader »

hooshsim wrote: Thu Jan 26, 2023 11:53 pm Does FreeCAD have an option to convert points imported from ASC file into B-Splines automatically or we have to create them ourselves manually using B-Spline in draft WB?
Thanks - Hooshsim
As far as I know there is no automatic method to create B-Splines from the point cloud.
The cloud is represented as one object in the model tree.
See the example below from the Dehler-Yacht.
How should the algorithm know which points to connect?
Dehler.asc.txt
(5.21 KiB) Downloaded 16 times
Example taken from @hammax:
https://forum.freecadweb.org/viewtopic.php?f=13&t=74839
User avatar
onekk
Veteran
Posts: 6197
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Creating B-Splines from imported ASC file

Post by onekk »

It is not very complicated to convert such a file in something that FreeCAD can utilize to be passed to a BSPline method, already done for NACA airfoil profiles sone time ago, and more recently to scan some molecular Data from an ASCII file.

Sorry I have no computer at hand for some time to supply dome code. But probably earching for "airfoil" and my nickname probably will give some results.

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/
edwilliams16
Veteran
Posts: 3178
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Creating B-Splines from imported ASC file

Post by edwilliams16 »

This is very easy. Import your ascii file splinedat.asc using the Points workbench. In the python console:

Code: Select all

import Draft
doc = App.ActiveDocument
shp = doc.getObject("splinedat").Points
Draft.makeBSpline(shp.Points)
doc.recompute()
User avatar
Vincent B
Veteran
Posts: 4731
Joined: Sun Apr 05, 2015 9:02 am
Location: La Rochelle, France

Re: Creating B-Splines from imported ASC file

Post by Vincent B »

Surfaces can be made manually if points are not too many.

Code: Select all

import Draft
selobj = Gui.Selection.getSelection()
obj = selobj[0]
count = len(obj.Points.Points)
i = 0
comp = App.activeDocument().addObject("Part::Compound","Points_Compound")
for pt in obj.Points.Points:
    p = Draft.makePoint(pt)
    comp.Links += [p]
    i += 1
print ("Nb points = "+str(count))
App.ActiveDocument.recompute()
Attachments
Capture.JPG
Capture.JPG (41.95 KiB) Viewed 686 times
boat.FCStd
(244.6 KiB) Downloaded 11 times
hooshsim
Posts: 108
Joined: Mon Nov 05, 2018 7:40 pm

Re: Creating B-Splines from imported ASC file

Post by hooshsim »

Vincent,
What’s this code and how to use it. I’m not an expert on freecad. Please advice
Thanks-Hooshsim
Post Reply