sweep along any path

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Posts: 1373
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii

Re: sweep along any path

Post by edwilliams16 »

onekk wrote: Tue Jun 07, 2022 11:48 am
down sampled my script or the points?

Sorry I'm confused with all these radii.
Down sampled the points on the spine within the script - took every fifth point.

Confusion was my fault:

Problem if the radius of curvature of the spine is less than the radius of the profile. If you turn in less than your own length there's massive self-intersection. I believe the code actually worked in that case, but the result wasn't what the OP had in mind.
Posts: 1373
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii

Re: sweep along any path

Post by edwilliams16 »

wwshunan wrote: Tue Jun 07, 2022 2:35 pm Thank you. But the software always crashes.

Code: Select all

points = create_points("/Users/ed/Downloads/v_pole.txt")
in the script to put in the path to your points file. Start FreeCAD, create a new Document, then paste the script into the Python console. If it crashes you have a problem with your installation.

EDIT: Are you using some obsolete version? In the User forums we request version information. I'm on

Code: Select all

OS: macOS High Sierra (10.13)
Word size of FreeCAD: 64-bit
Version: 0.20.28909 (Git)
Build type: Release
Branch: master
Hash: 6beef68ae1
Python 3.9.12, Qt 5.12.9, Coin 4.0.0, OCC 7.5.3
Locale: C/Default (C)
Installed mods: 
  * Curves 0.4.4
  * DynamicData 2.46.0
  * fasteners 0.3.41
  * fcgear 1.0.0
  * Help 1.0.0-alpha
  * lattice2 1.0.0
  * MeshRemodel 1.8919.0
  * toSketch

Since you were posting in a developer forum, the assumption was you knew how to run a script.
Posts: 5
Joined: Sun Jun 05, 2022 4:19 pm

Re: sweep along any path

Post by wwshunan »

My version is
OS: Windows 10 Version 2009
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24267 +148 (Git)
Build type: Release
Branch: Branch_0.19.4
Hash: 476ecf091941bead59b14e44afa6064d5a66afa3
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.3
Locale: Chinese/China (zh_CN)

I opened the dialog to execute a macro

Code: Select all

"""Sweep using a BSpline.

file: 20220606-sweep.py

Author: Carlo Dormeletti
Copyright: 2022
Licence: LGPL
import os

import FreeCAD
import FreeCADGui
from FreeCAD import Vector, Rotation, Placement# noqa

import Part  # noqa

DOC = FreeCAD.newDocument()

def create_points(filename):
    points = []

    with open(filename,'r') as f:
        data = f.readlines()

    for line in data:
        coords = [float(x) for x in line.split()]

    return points

def do_sweep(points):
    bs = Part.BSplineCurve()
    bs.buildFromPoles(points, False)

    path = DOC.addObject("Part::Feature", "path")
    path.Shape = bs.toShape()

    rad = 0.2

    circle = Part.Circle(Vector(0, 0, 0), Vector(0, 0, 1), rad)

    prof_dsp = Vector(0, 01.194835164932913862e+0, 0) #+ Vector(0, rad * 1, 0)

    profile = DOC.addObject("Part::Feature", "profile")
    profile.Shape = circle.toShape()
    profile.Placement = Placement(prof_dsp, Rotation(0, 0, 0))


    sw_solid = DOC.addObject("Part::Sweep", "sweep")
    sw_solid.Sections = (profile)
    sw_solid.Spine = path
    sw_solid.Solid = False
    sw_solid.Frenet = False


points = create_points(r"D:\Workspace\freeCAD\v_pole.asc")

print(f"From: {points[0]} to: {points[-1]}")
step = 40
points_s = points[::step]
I reinstalled FreeCAD and it works now. Many thanks
Post Reply