Get Part.Wire data from Cut

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Tom28
Posts: 6
Joined: Sun Aug 13, 2017 10:56 am

Get Part.Wire data from Cut

Post by Tom28 »

Hello @ all,

I am having the folowing script, where I do a cut of a shape:

Code: Select all

        # cut shape with cutting box
        doc.addObject('Part::Cut', 'cut')
        doc.cut.Base = doc.shape
        doc.cut.Tool = doc.cut_box
        doc.recompute()

        # create cutting surface
        cut_surf_wires = list()
        for i in doc.cut.Shape.slice(App.Vector(0, 0, 1), 0):
            cut_surf_wires.append(i)
        cut_surf = Part.Compound(cut_surf_wires) 
        add_cut_surf = doc.addObject('Part::Feature', 'cut_surf')
        add_cut_surf.Shape = cut_surf
Now I want to access the path datas of this cutting surface, I tried a lot but have no clue so far how to access these data.

Any hint would be appreciated

Tom
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Get Part.Wire data from Cut

Post by onekk »

If you add a compound (remember compound has no intersecting edges), you have a sort of container, so you have to dig more deep into the tree to obtain primitives (surfaces, wires and so on).

you could try to do get some interesting info simply using:

Code: Select all

print(dir(add_cut_surf))
and see what properties and methods are exposed.

Maybe not the more clean way, but it usually works.

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/
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Get Part.Wire data from Cut

Post by openBrain »

It's a bit hard to help as a Cut doesn't result in a surface, but in a solid with multiple surfaces.
How would you identify the face that was "born" from the Cut ?
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Get Part.Wire data from Cut

Post by ebrahim raeyat »

openBrain wrote: Wed Dec 01, 2021 10:56 am It's a bit hard to help as a Cut doesn't result in a surface, but in a solid with multiple surfaces.
How would you identify the face that was "born" from the Cut ?
may be this can help?

https://github.com/ebrahimraeyat/Civil/ ... om.py#L144
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Get Part.Wire data from Cut

Post by onekk »

OK.

you have this object that is a "list of faces".

Try with a generic solid, you will obtain the wire simply doing:

Code: Select all

Part.show(solid.Faces[0].OuterWire, "wire")
But if faces has "holes" Outerwire is generally hold the external wire, while Wires will hold even holes, a simple loop will traverse things.

Hope it helps

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/
Tom28
Posts: 6
Joined: Sun Aug 13, 2017 10:56 am

Re: Get Part.Wire data from Cut

Post by Tom28 »

Many thanks, I will try and give you feedback here..

Tom
Post Reply