Part Slicing for Foam-Padded Case

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!
Spida
Posts: 5
Joined: Wed Aug 17, 2016 8:22 pm
Location: Germany
Contact:

Part Slicing for Foam-Padded Case

Post by Spida »

I am looking for a special way to create slices of a 3-dimensional object. I want to create cutting schemes for foam mats to create a layered foam padding for a case, similar to what is shown on http://www.mycasebuilder.com. Since my part has many rounded features and is rather heavy, I have decided to deviate from the common choice of slicing horizontally, parallel to the X-Y-plane, but instead to have full contact between part and foam by stacking the individual foam mats vertically. This results in two constraints that I need to satisfy, and haven't found a way to implement in freecad:
  • Since the cutting process I will use is a 2D waterjet, every cut will go straight from one side of the foam to the other. As the foam mats have a thickness, and my part has features smaller than the thickness, I need to consider the maximum extension of my part for any given layer of foam for a slice of the thickness of the foam.
  • I want to insert my part into the case, so the foam mats need to be open to one side.
Is there a way to do this in freecad?

Part:
Image

Slice:
Image

Code: Select all

OS: Debian GNU/Linux 8.5 (jessie)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.
Build type: None
Python version: 2.7.9
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Part Slicing for Foam-Padded Case

Post by DeepSOIC »

Interesting challenge!
Can I have the shape please?

My current idea is:
1. Slice the shape with planes
2. extrude all the planes, then fuse them
3. slice the result of extrusion, again. This gives the actual profiles of openings.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Part Slicing for Foam-Padded Case

Post by DeepSOIC »

Got the model in PM, will try something. Stay tuned ;)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Part Slicing for Foam-Padded Case

Post by DeepSOIC »

Here's the key idea I wanted to try.
foam-approach.png
foam-approach.png (49.01 KiB) Viewed 3355 times
(and then use the solid on the right to cut the foam sheet)

In this simple test case, the method worked. But on your model, it didn't. Slicing was not reliable (even in this test case, there are problems - there should have been only one vertex on the right side of the slot). And even when it did work, the final fusion failed.

So I will try to use a simpler method, which will give rectangular-ish cutouts for the foam. This is probably not what you want, but I think it's going to be good enough to be practical.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Part Slicing for Foam-Padded Case

Post by DeepSOIC »

Sorry, I couldn't get any usable result :|
User avatar
quick61
Veteran
Posts: 3803
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Part Slicing for Foam-Padded Case

Post by quick61 »

Wouldn't it be better for the foam to be laying the other way, (horizontal), than what you show in your second pic? You do know that you can attach the FreeCAD file to your post and that would make it easier for us to come up with a solution.

How thick are the foam pieces? 25 mm, 50? Give me a little time and I'll post back a simple example.

Oh, and welcome to FreeCAD and the forum. :)

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Part Slicing for Foam-Padded Case

Post by ickby »

Indeed a nice challenge. I only tested on a much simpler Part, but this script should work and hold all your constraints. Select the part and run it.
Note: You likely need to rotate your part. The foam mats in my script have their opening always in z direction. So if this is wrong for your part just rotate it.

Code: Select all

import Part

#get the shape to slice
shape = Gui.Selection.getSelection()[0].Shape

#parameters
thickness = 2; #thickness of foam
slices = 11;   #number of slices 

#needed boiler plate: Bounding box and side faces
bbox = shape.BoundBox;
extbox = Part.makeBox(bbox.XLength*1.2, bbox.YLength*1.2, bbox.ZLength*1.2)
extbox.translate(bbox.Center - extbox.CenterOfMass);
rightFace = extbox.Faces[2]
leftFace = extbox.Faces[3]

for x in range(0, slices):
		
	#build the foam slice we want to use
	foam = Part.makeBox(thickness, bbox.YLength*1.2, bbox.ZLength*1.2);
	foam.translate(App.Vector(bbox.XMin + bbox.XLength/slices*x, bbox.Center.y - foam.CenterOfMass.y, bbox.Center.z - foam.CenterOfMass.z));
	bface = foam.Faces[0];
	
	#get the part sections that needs to be handled by that slice
	section = foam.common(shape);
	
	
	#we need to handle each solid seperate
	for solid in section.Solids:
	
		#get the needed largest needed outline by projecting all faces
		projections = [];
		for face in solid.Faces:
			edges = bface.project([face]);
			face = Part.Face(Part.Wire(edges.Edges));
			projections.append(face);
	
		projection = projections[0].multiFuse(projections);
		projection = projection.removeSplitter();
		outline = projection.Faces[0].OuterWire;
	
		#find the left- and rightmost points in the outline and ensure that we have verices there
		
		def splitEdges ( outline, dist ):
			if dist[2][0][3] == 'Edge':
				e = outline.Edges[dist[2][0][4]];
				edges = outline.Edges;
				del edges[dist[2][0][4]]
				split = e.split(dist[2][0][5]);
				edges += split.Edges;
				vertex = split.Vertexes[1];
				return (Part.Wire(edges), vertex);
			
			return (outline, outline.Vertexes[dist[2][0][4]])
	
		res = splitEdges(outline, rightFace.distToShape(outline));
		v1 = res[1];
		res = splitEdges(res[0], leftFace.distToShape(res[0]));
		v2 = res[1];
		outline = res[0];
	
		#build extension lines to ensure we cut out the whole foam
		e = [];
		e.append( Part.Edge(Part.Line(v1.Point, v1.Point + App.Vector(0,0,bbox.ZLength))) );
		e.append( Part.Edge(Part.Line(v1.Point + App.Vector(0,0,bbox.ZLength), v2.Point + App.Vector(0,0,bbox.ZLength))) );
		e.append( Part.Edge(Part.Line(v2.Point + App.Vector(0,0,bbox.ZLength), v2.Point)) );
	
		#find a set of outline edges between the vertices: it doesnt matter which path of the two possibles
		def getNextEdge(edges, vertex):
			for edge in edges:	
				if (edge.Vertexes[0].Point - vertex.Point).Length < 1e-4:
					edges.remove(edge);
					return (edge, edge.Vertexes[1]);
				if (edge.Vertexes[1].Point - vertex.Point).Length < 1e-4:
					edges.remove(edge);
					return (edge, edge.Vertexes[0]);
	
		edges = outline.Edges;
		res = getNextEdge(edges, v2);
		e.append(res[0]);
		while edge and ((res[1].Point - v1.Point).Length > 1e-4):
			res = getNextEdge(edges, res[1]);
			e.append(res[0]);
	
		#we are not sure we have build the real outer wire, we could have followed the wrong edge... brute forece again!
		face = Part.Face(outline).fuse(Part.Face(Part.Wire(e)));
		
		#build the cut shape and finaly cut the foam
		hole = face.extrude(App.Vector(thickness, 0 ,0));
		foam = foam.cut(hole).removeSplitter();
	
	Part.show(foam)
s.png
s.png (52.97 KiB) Viewed 3305 times
s2.png
s2.png (8.71 KiB) Viewed 3305 times
s3.png
s3.png (57.27 KiB) Viewed 3305 times
Spida
Posts: 5
Joined: Wed Aug 17, 2016 8:22 pm
Location: Germany
Contact:

Re: Part Slicing for Foam-Padded Case

Post by Spida »

Thank you for the feedback,
quick61 wrote:Wouldn't it be better for the foam to be laying the other way, (horizontal),
I would certainly be easier. I assume it would be safer for the part to have them vertical, since the part is relatively heavy (8 kg) and with the foam mats standing upright I could have rounded cuts, so the load on each unit of surface would be lower, resulting in better damping.
quick61 wrote:How thick are the foam pieces? 25 mm, 50? Give me a little time and I'll post back a simple example.
I have the choice of 10, 20, 30, 40, 50mm thick foam sheets.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Part Slicing for Foam-Padded Case

Post by DeepSOIC »

ickby wrote:script
Interesting. Tried by copy-pasting to console.
Traceback (most recent call last):
File "<input>", line 65, in <module>
NameError: name 'edge' is not defined
Not sure how to fix, so I post here.

I read quickly through the code, and it looks like you are multifusing faces, then removeSplitter. That doesn't work in OCC7, unfortunately - the result of multifuse is a compound of faces, not a shell.
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Part Slicing for Foam-Padded Case

Post by ickby »

DeepSOIC wrote:
ickby wrote:script
Interesting. Tried by copy-pasting to console.
Traceback (most recent call last):
File "<input>", line 65, in <module>
NameError: name 'edge' is not defined
Not sure how to fix, so I post here.

I read quickly through the code, and it looks like you are multifusing faces, then removeSplitter. That doesn't work in OCC7, unfortunately - the result of multifuse is a compound of faces, not a shell.
I tested, worked as macro and pasted into console for me. Thanks for the multifuse hints, I used:
OS: Ubuntu 16.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.7966 (Git)
Build type: Debug
Branch: Extensions
Hash: 86915b87c0bfebbb9348be361f54c4528635d196
Python version: 2.7.11+
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17


But I did only test a simple part, I'm quite sure that the script is not very robust.
Post Reply