This short python script is crashing FreeCAD 0.17

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
nmt
Posts: 29
Joined: Sun Feb 19, 2017 2:45 pm

This short python script is crashing FreeCAD 0.17

Post by nmt »

Can someone please tell me why the following python script is crashing FreeCAD 0.17? Thanks.

Code: Select all

import FreeCAD
import Part
from FreeCAD import Base

doc = FreeCAD.newDocument('Slice')
Gui.activeDocument().activeView().viewAxonometric()
b = Part.makeBox(10,10,10,Base.Vector(0,0,0),Base.Vector(0,0,1))
box = doc.addObject("Part::Box","Box")
box.Shape = b
box.ViewObject.Transparency=50
planes = [box]
for i in range(2,10,2):
	p = Part.makePlane(14,14, Base.Vector(-2,-2,i), Base.Vector(0,0,1))
	plane = doc.addObject("Part::Plane",("Plane%s" % (i)))
	plane.Shape = p
	plane.ViewObject.Transparency=50
	planes.append(plane)

Gui.SendMsgToActiveView("ViewFit")

r = Part.BOPTools.SplitFeatures.makeBooleanFragments(name= 'BoolFrag')
r.Objects = planes
r.Mode = 'Standard'
r.ViewObject.Transparency = 60
children = r.Shape.childShapes()
for child in children:
	Part.show(child)
	child.ViewObject.Transparency=50

doc.recompute()
Gui.SendMsgToActiveView("ViewFit")
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: This short python script is crashing FreeCAD 0.17

Post by DeepSOIC »

Hi!
It crashes upon calling childShapes() of a null shape:

Code: Select all

Part.Shape().childShapes()
Please write a bug report to tracker.

In the meantime. To fix your script, add doc.recompute() before accessing childShapes of BooleanFragments
User avatar
nmt
Posts: 29
Joined: Sun Feb 19, 2017 2:45 pm

Re: This short python script is crashing FreeCAD 0.17

Post by nmt »

This fragment works, but the cube is not yet sliced

Code: Select all

import FreeCAD
import Part
from FreeCAD import Base

doc = FreeCAD.newDocument('Slice')
Gui.activeDocument().activeView().viewAxonometric()
b = Part.makeBox(10,10,10,Base.Vector(0,0,0),Base.Vector(0,0,1))
box = doc.addObject("Part::Box","Box")
box.Shape = b
box.ViewObject.Transparency=50
planes = [box]
for i in range(2,10,2):
   p = Part.makePlane(14,14, Base.Vector(-2,-2,i), Base.Vector(0,0,1))
   plane = doc.addObject("Part::Plane",("Plane%s" % (i)))
   plane.Shape = p
   plane.ViewObject.Transparency=50
   planes.append(plane)

Gui.SendMsgToActiveView("ViewFit")
If I put a doc.recompute(), then the result is not what I expected. The cube sliced by planes is replaced with a cube and one big plane at (0,0,0).

Code: Select all


import FreeCAD
import Part
from FreeCAD import Base

doc = FreeCAD.newDocument('Slice')
Gui.activeDocument().activeView().viewAxonometric()
b = Part.makeBox(10,10,10,Base.Vector(0,0,0),Base.Vector(0,0,1))
box = doc.addObject("Part::Box","Box")
box.Shape = b
box.ViewObject.Transparency=50
planes = [box]
for i in range(2,10,2):
   p = Part.makePlane(14,14, Base.Vector(-2,-2,i), Base.Vector(0,0,1))
   plane = doc.addObject("Part::Plane",("Plane%s" % (i)))
   plane.Shape = p
   plane.ViewObject.Transparency=50
   planes.append(plane)


r = Part.BOPTools.SplitFeatures.makeBooleanFragments(name= 'BoolFrag')
r.Objects = planes
r.Mode = 'Standard'
r.ViewObject.Transparency = 60
doc.recompute()
Gui.SendMsgToActiveView("ViewFit")
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: This short python script is crashing FreeCAD 0.17

Post by DeepSOIC »

nmt wrote:This fragment works, but the cube is not yet sliced
I didn't mean to fix the actual functioning of your script, all I meant to do was to avoid the crash so you can get busy with finishing it.

I don't quite understand what your script is supposed to do, so please explain what you want to achieve if you want help.

EDIT: I see you already created a thread about a few days ago: https://forum.freecadweb.org/viewtopic. ... 90#p161490
User avatar
nmt
Posts: 29
Joined: Sun Feb 19, 2017 2:45 pm

Re: This short python script is crashing FreeCAD 0.17

Post by nmt »

Thank you for your help. I am trying to create a cube, then create a few horizontal planes that intersect it/slice through it, then I want to create a non-manifold out of them (cube with several internal surfaces and cells/volumes) as one entity. Finally, I want to extract each cell as a solid out of that non-manifold topology. Think a simplified building and floors. Thanks again.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: This short python script is crashing FreeCAD 0.17

Post by Kunda1 »

Crash bug is in tracker as issue #2926
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply