[solved] makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

[solved] makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Post by reox »

I want to create a macro to mesh some geometry automatically and need a BooleanFragment in there. I clicked through the process and copied the python commands to a new macro:

Code: Select all

import BOPTools.SplitFeatures
active = App.ActiveDocument

sphere = active.addObject("Part::Sphere", "Sphere")
sphere.Radius = 20 * App.Units.MilliMetre
sphere.Angle1 = 30 * App.Units.Degree
inner = active.addObject("Part::Sphere", "Sphere")
inner.Radius = 18 * App.Units.MilliMetre
cut = active.addObject("Part::Cut", "Cut")
cut.Base = sphere
cut.Tool = inner

cyl = active.addObject("Part::Cylinder", "Cylinder")
cyl.Radius = 10 * App.Units.MilliMetre
cyl.Height = 25 * App.Units.MilliMetre
cyl.Placement = App.Placement(App.Vector(0, 0, 0), App.Rotation(App.Vector(0, 1, 0), -20 * App.Units.Degree))

sph_sec = active.addObject("Part::Section", "Section")
sph_sec.Base = cut
sph_sec.Tool = cyl

fragment = BOPTools.SplitFeatures.makeBooleanFragments(name='BooleanFragments')
fragment.Objects = [cut, sph_sec]
fragment.Mode = 'Standard'
fragment.Proxy.execute(fragment)  # <-- Line 34
fragment.purgeTouched()
for obj in fragment.ViewObject.Proxy.claimChildren():
	obj.ViewObject.hide()

However it fails with this error message:

Code: Select all

08:29:18  Traceback (most recent call last):
  File "/home/reox/.FreeCAD/Macro/baztest.FCMacro", line 34, in <module>
    fragment.Proxy.execute(fragment)
  File "/tmp/.mount_FreeCADMFQ6K/usr/Mod/Part/BOPTools/SplitFeatures.py", line 93, in execute
    selfobj.Shape = SplitAPI.booleanFragments(shapes, selfobj.Mode, selfobj.Tolerance)
  File "/tmp/.mount_FreeCADMFQ6K/usr/Mod/Part/BOPTools/SplitAPI.py", line 45, in booleanFragments
    pieces, map = list_of_shapes[0].generalFuse(list_of_shapes[1:], tolerance)
<class 'Part.OCCError'>: Base shape is null
In the python window, I just see this if I do the operation manually:

Code: Select all

>>> ### Begin command Part_BooleanFragments
>>> j = BOPTools.SplitFeatures.makeBooleanFragments(name='BooleanFragments')
>>> j.Objects = [App.ActiveDocument.Cut, App.ActiveDocument.Section]
>>> j.Mode = 'Standard'
>>> j.Proxy.execute(j)
>>> j.purgeTouched()
>>> for obj in j.ViewObject.Proxy.claimChildren():
>>>     obj.ViewObject.hide()
>>> ### End command Part_BooleanFragments
where is the difference or what do I miss here?

Code: Select all

OS: CentOS Linux 7 (Core) (XFCE/xfce)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24291 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.19.2)
Hash: 7b5e18a0759de778b74d3a5c17eba9cb815035ac
Python version: 3.8.8
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: German/Germany (de_DE)
Last edited by reox on Wed Sep 29, 2021 9:16 am, edited 1 time in total.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Post by openBrain »

Why are you doing a section ? A Part/Section object is only wires, no face, no solid. So of course it cannot be used in a boolean operation.
Moreover your BooleanFragment is done between the section and an object that is Base of section. So there will be no fragments.

Do you achieve what you want if you remove the section and make the fragments between 'cut' and 'cyl' directly ?
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Post by reox »

I want to create a mesh region later on using the section. What I found so far is, that I need this Boolean Fragment and a Compound Filter to do that.
If I apply the compound filter directly, I can not select the circular section on the sphere's surface.
There are also threads where this is described that way (I can not find them right now, but I wrote this workflow in my notes and so far it worked very well)

If I click through it, it works perfectly. I select the Cut and the Section, Select the BooleanFragment and it works. However, it does not when run in a macro.
attached is an example of what I want to do with the macro.
MeshRegion.FCStd
(23.81 KiB) Downloaded 76 times
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Post by Chris_G »

In python scripts, the creation of document objects are often delayed to the next doc recompute.
So you need to explicitly recompute the doc before making the boolean fragment :

Code: Select all

...
sph_sec = active.addObject("Part::Section", "Section")
sph_sec.Base = cut
sph_sec.Tool = cyl

active.recompute()

fragment = BOPTools.SplitFeatures.makeBooleanFragments(name='BooleanFragments')
...
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Post by reox »

Chris_G wrote: Wed Sep 29, 2021 8:46 am So you need to explicitly recompute the doc before making the boolean fragment :
Ahhh okay! Thank you, that indeed solves the problem!
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Post by openBrain »

reox wrote: Wed Sep 29, 2021 9:16 am Ahhh okay! Thank you, that indeed solves the problem!
I though don't understand why you make so complex things :

Code: Select all

import BOPTools.SplitFeatures
active = App.ActiveDocument

sphere = active.addObject("Part::Sphere", "Sphere")
sphere.Radius = 20 * App.Units.MilliMetre
sphere.Angle1 = 30 * App.Units.Degree
inner = active.addObject("Part::Sphere", "Sphere")
inner.Radius = 18 * App.Units.MilliMetre
cut = active.addObject("Part::Cut", "Cut")
cut.Base = sphere
cut.Tool = inner

cyl = active.addObject("Part::Cylinder", "Cylinder")
cyl.Radius = 10 * App.Units.MilliMetre
cyl.Height = 25 * App.Units.MilliMetre
cyl.Placement = App.Placement(App.Vector(0, 0, 0), App.Rotation(App.Vector(0, 1, 0), -20 * App.Units.Degree))

sliced = BOPTools.SplitFeatures.makeSlice(name = "SlicedObject")
sliced.Base = cut
sliced.Tools = cyl
sliced.Mode = "CompSolid"
active.recompute()
sliced.Proxy.execute(sliced)
for obj in sliced.ViewObject.Proxy.claimChildren():
	obj.ViewObject.hide()

active.recompute()
Last edited by openBrain on Wed Sep 29, 2021 9:48 am, edited 2 times in total.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Post by reox »

openBrain wrote: Wed Sep 29, 2021 9:31 am I though don't understand why you make so complex things :
Because otherwise I can not use the circular face as a mesh region. Or is there another, simpler way to do that?
So far, the BooleanFragment -> CompoundFilter -> MeshRegion seemed to be the only way to achieve that.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Post by openBrain »

reox wrote: Wed Sep 29, 2021 9:35 am Because otherwise I can not use the circular face as a mesh region. Or is there another, simpler way to do that?
So far, the BooleanFragment -> CompoundFilter -> MeshRegion seemed to be the only way to achieve that.
Did you test the code I provided ?
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: [solved] makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Post by reox »

yes:
error_fc.png
error_fc.png (28.95 KiB) Viewed 1778 times
although, it seems to work for the meshing, in the FEM subforum, other methods were discussed already.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [solved] makeBooleanFragments fails with <class 'Part.OCCError'>: Base shape is null

Post by openBrain »

reox wrote: Wed Sep 29, 2021 9:39 am yes:
error_fc.png

although, it seems to work for the meshing, in the FEM subforum, other methods were discussed already.
My mistake. Didn't apply the correct Mode for the Slice in my snippet. It's fixed above in my previous message. Could you test again ?
Post Reply