Creating faces with holes

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Creating faces with holes

Post by ulrich1a »

The Part-module can make a face out of a list of wires, where the first wire is the outline and the following wires defining holes in the face. This method is more than ten times faster as to cut out the holes from an initial face. So I used this method in my scripts.

But it turned out that this method gives different results depending on the version of the CAD-kernel, if there are circles involved. The following picture shows the wanted face, based on a OCE-kernel with a hex-hole in a disk. With newer OCCT-kernels I get a circle with a hex-disk from the same code.


Can this be fixed inside of FreeCAD?
Or are there methods to detect the version of the CAD-kernel from Python?
Or is it not recommended to use the list method in Python scripts to generate faces with holes?
What is the recommended solution for this problem?

Ulrich
Attachments
face_test2a.py.zip
script to show the problem
(1.57 KiB) Downloaded 55 times
Defect Face
Defect Face
DefectFace.png (14.19 KiB) Viewed 1640 times
Wanted Face
Wanted Face
WantedFace.png (10.11 KiB) Viewed 1640 times
User avatar
wandererfan
Veteran
Posts: 6265
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Creating faces with holes

Post by wandererfan »

ulrich1a wrote: Sat May 19, 2018 12:49 pm The Part-module can make a face out of a list of wires, where the first wire is the outline and the following wires defining holes in the face. This method is more than ten times faster as to cut out the holes from an initial face. So I used this method in my scripts.

But it turned out that this method gives different results depending on the version of the CAD-kernel, if there are circles involved. The following picture shows the wanted face, based on a OCE-kernel with a hex-hole in a disk. With newer OCCT-kernels I get a circle with a hex-disk from the same code.
The cutouts are supposed to have reversed Orientation compared to the OuterWire. The older versions likely didn't enforce this.
ulrich1a_hexFace.png
ulrich1a_hexFace.png (4.29 KiB) Viewed 1630 times

Code: Select all

>>> h = App.ActiveDocument.Shape
>>> hs = h.Shape
>>> c = App.ActiveDocument.Shape001
>>> cs = c.Shape
>>> hs.Orientation
'Forward'
>>> cs.Orientation
'Forward'
>>> hsc = hs.copy()
>>> hsc.reverse()
>>> face=Part.Face([Part.Wire(cs),hsc])
>>> Part.show(face)
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Creating faces with holes

Post by ulrich1a »

wandererfan wrote: Sat May 19, 2018 1:54 pm The cutouts are supposed to have reversed Orientation compared to the OuterWire. The older versions likely didn't enforce this.
It does not seem to be the Orientation of the Wire. I get 'Forward' in FreeCAD 0.18 for both wires and also 'Forward' for both wires in FreeCAD 0.16. As these are the versions, I am actually testing this. But the code works only in one version of FreeCAD, actually in FreeCAD 0.16.

I can change the axis of the circle or the sequence of the hex-points, to make it work in the other version. The only hint I found so far is to make a face from the circular wire and compare its axis with the axis from the circle. Newer versions of the kernel have an identical axis for a circle and a face made from this circle, whereas older kernels have an opposite axis between a circle and its corresponding face. But is this the recommended way to make a check for this behavior?

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

Re: Creating faces with holes

Post by TheMarkster »

It wouldn't be difficult to check the current version of OCC being used if that will help you.

Code: Select all

import FreeCAD,Part
from distutils.version import LooseVersion as lsVer

FreeCAD.Console.PrintMessage("Current OCC Version: "+Part.OCC_VERSION+"\n")
#I get: Current OCC Version: 7.2.0

curVer = Part.OCC_VERSION
testVer = '7.2.1'

if lsVer(curVer) > lsVer(testVer):
    FreeCAD.Console.PrintMessage("current version is newer than "+testVer+"\n")
else:
    FreeCAD.Console.PrintMessage("current version is older than "+testVer+"\n")

testVer = '7.1.0'

if lsVer(curVer) > lsVer(testVer):
    FreeCAD.Console.PrintMessage("current version is newer than "+testVer+"\n")
else:
    FreeCAD.Console.PrintMessage("current version is older than "+testVer+"\n")

#if you want the individual int values
major,minor = lsVer('7.2').version
major,minor,revision = lsVer('7.2.1').version
major,minor,revision,subrevision = lsVer('7.2.1.3').version
User avatar
Gift
Posts: 769
Joined: Tue Aug 18, 2015 10:08 am
Location: Germany, Sauerland

Re: Creating faces with holes

Post by Gift »

Aloha Ulrich,

There are various face maker since 0.17.8573:. Read this: https://forum.freecadweb.org/viewtopic.php?t=17723 By the way: "Creating a polygon

A polygon is simply a wire with multiple straight edges. The makePolygon function takes a list of points and creates a wire along those points:"

Code: Select all

lshape_wire = Part.makePolygon([Base.Vector(0,5,0),Base.Vector(0,0,0),Base.Vector(5,0,0)])
Src: https://www.freecadweb.org/wiki/Topolog ... _scripting

Many greetings
Benjamin
Post Reply