Generating a cutting list for woodworking project, advise needed

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
johbo
Posts: 2
Joined: Mon Dec 06, 2021 12:16 pm

Generating a cutting list for woodworking project, advise needed

Post by johbo »

Hi!

I've used FreeCAD to design a piece of furniture. Now I am somewhat stuck while trying to generate a cutting list in a semi automatic fashion with a macro. It seems that I've put myself in a sort of trap due to the way how I flag the objects which I want to become part of the cutting list.

My approach is to flag each item which I'd like to be in the list by using a custom property "Tags", and adding the value "Cutlist". In my macro I am iterating through all objects of the document, and if the current object is flagged, then I print a line with it's label and the dimensions of it's bounding box.

Now I got a lot of extra entries due to objects of the type "App::Link". I've used those to cut grove, dadoes, miters out of other items and it seems that this is the "trap" I got into. The links do also have the value "Cutlist" in it's propery "Tags".

At this stage I am wondering how to approach the problem of distinguishing the wanted from the unwanted items in a way which does not interfere with the behavior of the link objects. Especially I think that I would soon run into a situation where I want some links of an object in the cutting list output, so simply ignoring all links would not work on the long run.

At the moment I have two thoughts how to approach this:

a) Try to find a way to flag objects which not inherited by the link object. Not sure though if something like this is possible.

b) Turn the approach around. Instead of flagging the individual objects, I would try to build an object which represents the cutting list, and then add a reference to every object which I would like to appear in the list.

I hope to find some advise about which direction to approach.

I am using a quite recent build of the 0.20 development line, it's 0.20-26306.

Cheers,

Johannes
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Generating a cutting list for woodworking project, advise needed

Post by TheMarkster »

Try this (untested):

Code: Select all

cutlist = [obj for obj in FreeCAD.ActiveDocument.Objects if hasattr(obj,"Tags") and obj.Tags == "CutList" and obj.TypeId != "App::Link" and obj.TypeId != "App::LinkElement"]
johbo
Posts: 2
Joined: Mon Dec 06, 2021 12:16 pm

Re: Generating a cutting list for woodworking project, advise needed

Post by johbo »

Yes, that's the first step I assume. I've got now as follows:

Code: Select all

# Fragment of my code which iterates all objects

    for obj in document.Objects:
        if is_in_cutlist(obj):
            csv_rows.append(create_csv_row(obj))

# Here I decide if I want to add the object or not
# Currently excluding the links is "good enough"
 
def is_in_cutlist(obj):
    return is_tagged(obj) and not is_link(obj)

def is_tagged(obj):
    return TAG_CUTLIST in get_tags(obj)

def is_link(obj):
    return obj.TypeId == TYPE_ID_APP_LINK

def get_tags(obj):
    return getattr(obj, 'Tags', [])
I guess for the other part of my question it would be best if I create a small example model, then it should be easier to show why I look for a way to distinguish links.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Generating a cutting list for woodworking project, advise needed

Post by onekk »

Yes a Minimal Working Example will be the best.

And maybe info about FreeCAD version taken from the about window like suggested in the forum first post.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply