FreeCAD Python: Select all faces a a given depth Part 1. Macro programming

preview_player
Показать описание
Selecting multiple faces can be laborious. I teach you how to create a macro that will allow you to supply a depth to automatically select all faces at that depth. Great if you want to select all faces to add pocket paths on a CNC machine. This is a two part video. The first part you learn how to create a usable macro to select faces in your scenc, walking through all the objects in code and selecting only those at a given depth. In the next video we add a little gui to make it more usable allowing you to supply a depth and even an axis.

#FreeCAD #Python #Tutorial # CNC

Donate:

Subscribe:

Browse my Redbubble Shop:
Рекомендации по теме
Комментарии
Автор

For anyone trying to select multiple EDGES at a certain depth instead of faces (for the pocket function on a through-hole; took me a godd*m week to figure it out):

doc = App.ActiveDocument
body = doc.Body
shape = body.Shape
edges = shape.Edges
selectedEdges = []

for count, edge in enumerate(edges):
edgeName = "Edge" + str(count + 1)
position = edge.Vertexes[0].Z
if position == -3.1: # Change Value to whatever depth value you desire


Gui.Selection.addSelection(body, selectedEdges)

Thanks for the resource, MangoJelly!

MatthewBarber-pc
Автор

For anyone looking for a fast solution to select all faces:


for sh in shapes:
faces = ["Face%d" % (i+1) for i in range(len(sh.Shape.Faces))]
Gui.Selection.addSelection(sh, faces)

Wuetr
Автор

Thanks a lot! This helps ton! edit: well actually, for some reason it gives error "select faces from single solid" if macro is used before path pocket shape, and all comes non-selected. Using macro when pocket shape dialog is open, macro gives error about shapes not being planar...using version 0.21.1. But, pocket shape allows to select multiple faces "manually", so this is odd! Alright, found solution; the macro for me was selecting "stock" from job as well, so there was two solids in play. Edited first line bit and this seemingly fixed issue: shapes = App.ActiveDocument.findObjects("Part::Feature", "Body")

attepitkanen
Автор

Hi. Love your videos.
I’m using FreeCAD 0.22… When I run this macro and select a pocketing operation, I get the error, “Please select faces from a single solid. (The macro selects faces from original body and the body created with the job.) How can I modify the macro so it selects faces only form the Job->Model-Body in the tree?
Thanks!

wtcarterofgalway
Автор

Hi, if send you a sketch would you please make a video how to develop G code?

ellievyks
Автор

Is that a cut down version of python? There doesn't seem to be any rhyme or reason to variable types or names. I understand the code when you explain it but I'm used to c++ so python reminds me of visual basic haha

Cool video though. It's for cnc. I'm slow and it took me a while to catch on lol. I'm here for custom 3d prints but I'm still learning alot.

jstro-hobbytech
visit shbcf.ru