Layer by height
-
Hey all! I've got a challenge...
I mill a lot of stuff on CNC, typically plywood and other sheet goods. I design all of it in SketchUp.
What I do is draw the parts, and lay them flat in SketchUp and then bring them into my milling program that drives the CNC.
When you get the parts into the milling program they are 2D. Right now I have to manually select each vector and tell the machine what to do with that vector. Sometimes it's cutting out a shape, making a pocket, or cutting a hole.
The milling software I use can automatically make toolpaths based on vectors being on a layer, which leads me to my question:
Does anyone know of an automatic way to put faces and lines on named layers based on their Z height? The trick here is that the height needs to be related to the thickness of the piece of wood that's being cut.. That means if I'm cutting a .25" deep pocket out of a 1" piece of plywood that pocket's Z depth is .75". Now if I wanted to mill a .25" pocket out of a .75" thick piece of plywood that pocket's Z height is .5"
Does anyone know of a plugin out there, or some other method that I could achieve this? Here's a mockup:
-
First collect all 'flat' faces to be reassigned to these layers:
model=Sketchup.active_model; faces = model.active_entities.grep(Sketchup::Face).find_all{|face| face.normal.parallel?(Z_AXIS) }
This example uses the '.active_entities
', but you could change it to work on a '.selection
' OR ALL faces in the model - even those that are nested inside groups or components, simply by iteratingmodel.entities
then all non-imagemodel.definitions.entities
for such faces... e.g.
faces=model.entities.grep(Sketchup::Face).find_all{|face| face.normal.parallel?(Z_AXIS) } model.definitions.find_all{|d| ! d.image? }.each{|d| faces << d.entities.grep(Sketchup::Face).find_all{|face| face.normal.parallel?(Z_AXIS) } } faces.flatten!; faces.compact!; faces.uniq!
Then iterate that collection of faces to set up a hash based on their 'heights'...
fs={}; faces.each{|f| z=f.bounds.min.z; fs[z]=[] unless fs[z]; fs[z]<<f }
Then it can make layers if needed, and change the equivalent faces to have those layers.
fs.each_key{|z| lay=model.layers.add(z.to_s); fs[z].each{|f| f.layer=lay; f.edges.each{|e| e.layer=lay } } }
If you want particular colors for depths it's probably best to set up your layers with colors beforehand [my 'Layers From List' plugin http://sketchucation.com/pluginstore?pln=TIG_LayersFromList will let you do that from a text list] -
All this code is a bit above my pay grade... If I get the gist it sounds like it is possible?
-
I'll PM you an example RBZ.
Watch fro it in a while...
Advertisement