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
Creating faces with holes
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Creating faces with holes
- Attachments
-
- face_test2a.py.zip
- script to show the problem
- (1.57 KiB) Downloaded 55 times
-
- Defect Face
- DefectFace.png (14.19 KiB) Viewed 1640 times
-
- Wanted Face
- WantedFace.png (10.11 KiB) Viewed 1640 times
- wandererfan
- Veteran
- Posts: 6265
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Creating faces with holes
The cutouts are supposed to have reversed Orientation compared to the OuterWire. The older versions likely didn't enforce this.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.
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)
Re: Creating faces with holes
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.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.
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
-
- Veteran
- Posts: 5505
- Joined: Thu Apr 05, 2018 1:53 am
Re: Creating faces with holes
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
Re: Creating faces with holes
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:"
Src: https://www.freecadweb.org/wiki/Topolog ... _scripting
Many greetings
Benjamin
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)])
Many greetings
Benjamin