Help offset B-spline

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
Viper8
Posts: 3
Joined: Wed Dec 08, 2021 3:30 am

Help offset B-spline

Post by Viper8 »

Hello,

I'm trying to offset a B-spline in a sketch (see image) in order to close it and Pad the shape. The remainder of my part has been built using PartDesign (so I'm trying to avoid the Part offset tool). Is this possible? I have attempted using the Draft workbench offset tool and cannot get it to work.

Thanks!

FreeCAD .19
Windows OSX
Image
Attachments
Capture.PNG
Capture.PNG (165.64 KiB) Viewed 1303 times
Last edited by Viper8 on Thu Dec 09, 2021 2:16 am, edited 1 time in total.
User avatar
thomas-neemann
Veteran
Posts: 11801
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE 🇩🇪
Contact:

Re: Help offset B-spline

Post by thomas-neemann »

Viper8 wrote: Wed Dec 08, 2021 3:41 am

is that a solution for you?
833.FCStd
(11.61 KiB) Downloaded 16 times
https://www.youtube.com/watch?v=uE9D0Mc2A1Y

phpBB [video]


OS: Ubuntu 20.04.1 LTS (XFCE/xubuntu)
Word size of FreeCAD: 64-bit
Version: 0.20.26554 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 817c14b)
Hash: 817c14b16af681b06aec7d8c79f744c7a88fa3c3
Python version: 3.9.7
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.3
Locale: German/Germany (de_DE)
Gruß Dipl.-Ing. (FH) Thomas Neemann

https://www.youtube.com/@thomasneemann5 ... ry=freecad
Viper8
Posts: 3
Joined: Wed Dec 08, 2021 3:30 am

Re: Help offset B-spline

Post by Viper8 »

Thomas,

Thanks for the reply! That absolutely is a solution and the end geometry I'm looking for, but I'm trying to avoid using the part bench as the rest of the model was built in part design (and I typically run into issues when I attempt to combine the two...). So I was seeing if there's another way to accomplish that same geometry, but without the part workbench?
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: Help offset B-spline

Post by chrisb »

Viper8 wrote: Thu Dec 09, 2021 2:20 am I'm trying to avoid using the part bench as the rest of the model was built in part design (and I typically run into issues when I attempt to combine the two
It is not illegal, you just have to do it right, and starting in one workbench and continuing in another is manageable:

- Create your B-spline outside of a PartDesign body in Sketcher workbench
- create the offset
- create a PartDesign body
- select the offset object and create a ShapeBinder.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Help offset B-spline

Post by onekk »

Viper8 wrote: Thu Dec 09, 2021 2:20 am I'm trying to avoid using the part bench as the rest of the model was built in part design (and I typically run into issues when I attempt to combine the two...)
Part WB is "FreeCAD core library" as it is the "direct interface" with OCCT engine, so ho harm could happen if you use some "low level" thing in "high level" WB like PartDesign.

each PartDesign Object at the very end is using "Part" in a way or another.

The point is "how you are mixing things", maybe some actions are wrong.

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/
User avatar
thomas-neemann
Veteran
Posts: 11801
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE 🇩🇪
Contact:

Re: Help offset B-spline

Post by thomas-neemann »

onekk wrote: Thu Dec 09, 2021 7:44 am .The point is "how you are mixing things".
very good info. Can i look that up somewhere?
Gruß Dipl.-Ing. (FH) Thomas Neemann

https://www.youtube.com/@thomasneemann5 ... ry=freecad
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Help offset B-spline

Post by onekk »

thomas-neemann wrote: Thu Dec 09, 2021 8:01 am
onekk wrote: Thu Dec 09, 2021 7:44 am .The point is "how you are mixing things".
very good info. Can i look that up somewhere?
In what sense:

https://wiki.freecadweb.org/Topological_data_scripting

https://wiki.freecadweb.org/Part_and_PartDesign

Last sentence seem to say that.

But, sadly there is not PartDesign scripting around, let me try to put together something.

But as a proof of concept you could see this links, from the PartDesign source code:

https://github.com/FreeCAD/FreeCAD/blob ... ts/Gear.py

From a simple:

Code: Select all

print(dir(PartDesign))
it seems that not many things are exposed.

For now using some test code in sources I've put together something :

Code: Select all

"""partdesign_example.py

   This code was written as an sample code 
     
   Author: Carlo Dormeletti
   Copyright: 2021
   Licence: CC BY-NC-ND 4.0 IT 
"""

import os
import os.path
import math

import FreeCAD
from FreeCAD import Placement, Rotation, Vector
import Part
import Path
import Draft

import PartDesign


DOC_NAME = "partdesign_example"
    
DOC = FreeCAD.activeDocument()


def clear_doc():
    """
    Clear the active document deleting all the objects
    """
    for obj in DOC.Objects:
        try:
            DOC.removeObject(obj.Name)
        except Exception:
            pass

def create_doc(doc_name):
    obj = FreeCAD.newDocument(doc_name)
    return obj.Name

def setview():
    """Rearrange View"""
    DOC.recompute()
    VIEW.viewAxometric()
    VIEW.setAxisCross(True)
    VIEW.fitAll()

print(DOC)

if DOC is None:
    obj = create_doc(DOC_NAME)
    FreeCAD.setActiveDocument(obj)
    DOC = FreeCAD.activeDocument()
    VIEW = FreeCAD.Gui.ActiveDocument.ActiveView

else:
    if DOC.Name != DOC_NAME:
        obj = create_doc(DOC_NAME)
        FreeCAD.setActiveDocument(obj)
        DOC = FreeCAD.activeDocument()
        VIEW = FreeCAD.Gui.ActiveDocument.ActiveView
    else:
        DOC = FreeCAD.activeDocument()
        clear_doc()
        VIEW = FreeCAD.Gui.ActiveDocument.ActiveView


EPS = 0.10
EPS_C = EPS * -0.5

VZOR = Vector(0,0,0)
ROT0 = Rotation(0, 0, 0)


body = DOC.addObject('PartDesign::Body','Body')

box = DOC.addObject('PartDesign::AdditiveBox','Box')

body.addObject(box)
 
box.Length=10.00
box.Width=10.00
box.Height=10.00

DOC.recompute()


DatumPlane = DOC.addObject('PartDesign::Plane','DatumPlane')
DatumPlane.Support = [(DOC.YZ_Plane,'')]
DatumPlane.MapMode = 'FlatFace'

body.addObject(DatumPlane)

DOC.recompute()

DatumLine = DOC.addObject('PartDesign::Line','DatumLine')
DatumLine.Support = [(DOC.X_Axis,'')]
DatumLine.MapMode = 'TwoPointLine'

body.addObject(DatumLine)

DOC.recompute()

draft = DOC.addObject("PartDesign::Draft","Draft")
# Draft.Base needs to be top face
faces = box.Shape.Faces
# Grab the two faces with Z-normals and find the higher one
ZFaceIndexes = [i for i in range(len(faces)) if faces[i].Surface.Axis == Vector(0,0,1)]
if faces[ZFaceIndexes[0]].CenterOfMass.z > faces[ZFaceIndexes[1]].CenterOfMass.z:
    TopFaceIndex = ZFaceIndexes[0]
else:
   TopFaceIndex = ZFaceIndexes[1]
   draft.Base = (box, ["Face"+str(TopFaceIndex+1)])
   draft.NeutralPlane = (DatumPlane, [''])
   draft.PullDirection = (DatumLine, [''])
   draft.Angle = 45.0
   draft.Reversed = 1

   body.addObject(draft)

DOC.recompute()

if 'Invalid' in draft.State:
    draft.Reversed = 0
    DOC.recompute()

setview()

print("--- done ---")


Not very constructive as this is simple "/PartDesign/PartDesignTests/TestDraft.py" (badly) transformed as a standalone script.

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/
User avatar
thomas-neemann
Veteran
Posts: 11801
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE 🇩🇪
Contact:

Re: Help offset B-spline

Post by thomas-neemann »

onekk wrote: Thu Dec 09, 2021 8:54 am
thank you carlo. this is very helpful at the moment

https://wiki.freecadweb.org/Part_and_PartDesign

Greetings Thomas
Gruß Dipl.-Ing. (FH) Thomas Neemann

https://www.youtube.com/@thomasneemann5 ... ry=freecad
Viper8
Posts: 3
Joined: Wed Dec 08, 2021 3:30 am

Re: Help offset B-spline

Post by Viper8 »

Thanks everyone for the help! I'll plan on using the part WB to offset in my part design with shapebinders. Much appreciation to everyone who contributed anwers.
Post Reply