[solved]Non-solids (surface) boolean operations?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
xianyu
Posts: 66
Joined: Mon Jun 27, 2022 7:34 am

[solved]Non-solids (surface) boolean operations?

Post by xianyu »

hi,
I have a surface, generated by the following code (too many point data to list).

Code: Select all

import Part
point = [ FreeCAD.Vector(0,0,0), FreeCAD.Vector(1,0,0), ......]  # example
intSurf = Part.BSplineSurface()
intSurf.interpolate(point)
Part.show(intSurf.toShape())
I want to turn the surface into a solid.(similar to the first shape)
(The surface in the picture is generated from a sphere, a simple example)
03.png
03.png (14.58 KiB) Viewed 937 times
I think of two ways
1. By boolean operation? (I tried it, non-solids cannot boolean operations)
2. Use "Part.makeShell" and "Part.makeSolid", but I don't know how to get the arc of the surface to "Part.makeShell".(I only know how to use point to make)

Any help or suggestion is welcome,Thanks in advance :)

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Attachments
Non-solids boolean.FCStd
(9.81 KiB) Downloaded 20 times
Last edited by xianyu on Tue Sep 20, 2022 6:16 am, edited 2 times in total.
Freecad novice, A Python enthusiast
chrisb
Veteran
Posts: 54303
Joined: Tue Mar 17, 2015 9:14 am

Re: Non-solids (surface) boolean operations?

Post by chrisb »

What should a boolean do in the case of your Cube and Shape? The only sensible thing I can imagine right now is to cut the cube from the shape and that works well.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
xianyu
Posts: 66
Joined: Mon Jun 27, 2022 7:34 am

Re: Non-solids (surface) boolean operations?

Post by xianyu »

chrisb wrote: Mon Sep 19, 2022 9:29 am What should a boolean do in the case of your Cube and Shape? The only sensible thing I can imagine right now is to cut the cube from the shape and that works well.
You mean when they coincide, use "Part.Cut"? No matter if I use cube or surface cut, they disappear or give an error :(
04.png
04.png (10.22 KiB) Viewed 896 times
Freecad novice, A Python enthusiast
chrisb
Veteran
Posts: 54303
Joined: Tue Mar 17, 2015 9:14 am

Re: Non-solids (surface) boolean operations?

Post by chrisb »

xianyu wrote: Mon Sep 19, 2022 9:47 am You mean when they coincide, use "Part.Cut"? No matter if I use cube or surface cut, they disappear or give an error :(
04.png
If they coincide and I cut the cube from the shape, there is nothing left. Cutting a surface from something doesn't make sense, because it has no volume and thus doesn't take anything away.
I had looked at this:
SnipScreenshot-2a2e91.png
SnipScreenshot-2a2e91.png (15.35 KiB) Viewed 875 times
If I cut the cube, the remainder is this:
SnipScreenshot-ca64e8.png
SnipScreenshot-ca64e8.png (6.72 KiB) Viewed 875 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
xianyu
Posts: 66
Joined: Mon Jun 27, 2022 7:34 am

Re: Non-solids (surface) boolean operations?

Post by xianyu »

chrisb wrote: Mon Sep 19, 2022 10:28 am If I cut the cube, the remainder is this:
Yes, the cuts are valid, but, I want to compose a solid, similar to the first shape, have any idea?
02.png
02.png (8.13 KiB) Viewed 864 times
Freecad novice, A Python enthusiast
chrisb
Veteran
Posts: 54303
Joined: Tue Mar 17, 2015 9:14 am

Re: Non-solids (surface) boolean operations?

Post by chrisb »

You have to create the other surfaces too, combine them into one shape and make solid from that shape. If the height of the dome was determined by the cube, then you could use Slice apart.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Non-solids (surface) boolean operations?

Post by onekk »

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
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
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
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Non-solids (surface) boolean operations?

Post by onekk »

Maybe this thread could give you some ideas:

https://forum.freecadweb.org/viewtopic.php?f=3&t=30893

Not very clear, but maybe a starting point:

https://forum.freecadweb.org/viewtopic.php?f=3&t=60464

https://forum.freecadweb.org/viewtopic. ... im+surface

Hope it helps

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/
xianyu
Posts: 66
Joined: Mon Jun 27, 2022 7:34 am

Re: Non-solids (surface) boolean operations?

Post by xianyu »

Many thanks @chrisb @onekk
I saw something similar from thread, I think I need a little time to try it :lol:

edit: using Part WB SliceApart
Freecad novice, A Python enthusiast
Post Reply