xianyu wrote: ↑Mon Sep 19, 2022 10:36 am
Yes, the cuts are valid, but, I want to compose a solid, similar to the first shape, have any idea?
02.png
This will not be achieved by simply transform the surface you provided, as you could even extrude (probably Pad in PartDesign WB), but it will not make the shape as in the figure.
Probably this code will do something similar.
Code: Select all
"""Sample code.
This code was written as an sample code
Author: Carlo Dormeletti
Copyright: 2022
Licence: CC BY-NC-ND 4.0 IT
"""
import math
import FreeCAD
from FreeCAD import Placement, Rotation, Vector
import Part
def setview():
"""Rearrange View."""
FreeCAD.Gui.SendMsgToActiveView("ViewFit")
FreeCAD.Gui.activeDocument().activeView().viewAxometric()
DOC_NAME = "calk"
if FreeCAD.ActiveDocument is not None:
if FreeCAD.ActiveDocument.Name== DOC_NAME:
FreeCAD.closeDocument(DOC_NAME)
DOC = FreeCAD.newDocument(DOC_NAME)
sh_dim = 8
sh_len = 15
sp_rad = math.sqrt(pow(sh_dim, 2) * 2.0) / 2.0
sph1 = Part.makeSphere(sp_rad)
#Part.show(sph1, "sphere")
box = Part.makeBox(sh_dim, sh_dim, sh_len)
box.Placement = Placement(Vector(sh_dim * -0.5, sh_dim * -0.5, 0), Rotation(0,0,0))
# Part.show(box, "box")
solid = box.fuse(sph1)
f1 = 1.1
f2 = 1.2
cb_dim = sp_rad * f1 * 2
cb_len = (sh_len + sp_rad)
box1 = Part.makeBox(cb_dim, cb_dim, cb_len * f1)
box2 = Part.makeBox(sh_dim, sh_dim, cb_len * f2)
box2.Placement = Placement(Vector((cb_dim - sh_dim) * 0.5, (cb_dim - sh_dim) * 0.5, cb_len * (f2 - f1) * -0.5), Rotation(0,0,0))
# Part.show(box1, "box1")
# Part.show(box2, "box2")
cut_obj = box1.cut(box2)
cut_obj.Placement = Placement(Vector(cb_dim * -0.5, cb_dim * -0.5, sp_rad * -1), Rotation(0,0,0))
#Part.show(cut_obj, "cut_obj")
end_solid = solid.cut(cut_obj).removeSplitter()
Part.show(end_solid, "end_solid")
setview()
I have tried to do something paramtetric.
- 20220919-calk.png (15.6 KiB) Viewed 781 times
EDIT:
It is difficult to be more generic as the surface is difficult to "inspect" you could extrude it and obtain something similar, but you have to find the boudbox to make a proper cut solid to obtain the face.
Tested on:
Code: Select all
OS: Artix Linux (openbox)
Word size of FreeCAD: 64-bit
Version: 0.20.1.29410 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.20.1)
Hash: f5d13554ecc7a456fb6e970568ae5c74ba727563
Python 3.10.5, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.2
Locale: Italian/Italy (it_IT)
Installed mods:
* Curves 0.5.7
Hope it helps
Regards