Difficulties with the Manual Python example.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
ruchg
Posts: 26
Joined: Wed Nov 02, 2016 11:26 am

Difficulties with the Manual Python example.

Post by ruchg »

Working thru the manual:
https://www.freecadweb.org/wiki/Manual: ... g_geometry

Working thru the part to make the pill shape.
http://www.freecadweb.org/wiki/images/9 ... hon_03.jpg

Manual says that
Once we have a series of Edges, we can now form a Wire, by giving it a list of Edges. We don't need to take care of the order. OpenCasCade, the geometry "engine" of FreeCAD, is extraordinarily tolerant to unordered geometry. It will sort out what to do:
I'm not finding that to be true, if we put in the Wire per the manual, we fail to get closed geometry. However if we put the Wire together in a clockwise rotation the part closes. OpenCasCade is not as intolerant of unordered geometry as the author thought.

Extract of the manual commands entered into the Python console of a new document:

Code: Select all

import Part

V1 = FreeCAD.Vector(0,10,0)
V2 = FreeCAD.Vector(30,10,0)
V3 = FreeCAD.Vector(30,-10,0)
V4 = FreeCAD.Vector(0,-10,0)

L1 = Part.Line(V1,V2)
L2 = Part.Line(V4,V3)

VC1 = FreeCAD.Vector(-10,0,0)
C1 = Part.Arc(V1,VC1,V4)
VC2 = FreeCAD.Vector(40,0,0)
C2 = Part.Arc(V2,VC2,V3)

E1 = Part.Edge(L1)
E2 = Part.Edge(L2)
E3 = Part.Edge(C1)
E4 = Part.Edge(C2)

W = Part.Wire([E1,E2,E3,E4])

print( W.isClosed() )

F = Part.Face(W)

P = F.extrude(FreeCAD.Vector(0,0,10))

myObj2 = FreeCAD.ActiveDocument.addObject("Part::Feature","My_Strange_Solid")
myObj2.Shape = P
FreeCAD.ActiveDocument.recompute()
However if the wire is changed to

Code: Select all

W = Part.Wire([E1,E4,E2,E3])
Part completes as intended

OS: Linux
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.Unknown
Build type: Unknown
Python version: 2.7.11
Qt version: 4.8.7
Coin version: 3.1.3
OCC version: 6.8.0.oce-0.17
Linux 4.9.9-200.fc25.x86_64 #1 SMP Thu Feb 9 17:28:13 UTC 2017 x86_64 GNU/Linux
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Difficulties with the Manual Python example.

Post by DeepSOIC »

ruchg wrote:Manual says that
Once we have a series of Edges, we can now form a Wire, by giving it a list of Edges. We don't need to take care of the order. OpenCasCade, the geometry "engine" of FreeCAD, is extraordinarily tolerant to unordered geometry. It will sort out what to do:
I'm not finding that to be true,...
Hi! The manual is wrong. The edges must be supplied in correct order, and in right orientation. It must have been tolerant in some older OCC, and apparently this has changed.

Part.getSortedClusters, I think, is supposed to help you order the edges, but it seems to not work properly in some cases. In 0.17, a new function was written/exposed, I haven't tried it yet.
!
Let me update the manual... ...updated! thanks for reporting!
ruchg
Posts: 26
Joined: Wed Nov 02, 2016 11:26 am

Re: Difficulties with the Manual Python example.

Post by ruchg »

I'm confused at how fast you've updated the manual.

I've forked the manual from GitHub:
https://github.com/yorikvanhavre/FreeCAD-manual/

I believe there are 11 files waiting on Yorik to pull in.

Regards.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Difficulties with the Manual Python example.

Post by DeepSOIC »

ruchg wrote:I'm confused at how fast you've updated the manual.
Well, I actually updated only the wiki page, not the Yorik's Manual. So I'm not sure if what I did is right :oops: because I didn't notice it's a part of Yorik's Manual when editing it :oops: .
User avatar
yorik
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Difficulties with the Manual Python example.

Post by yorik »

I'm not planning to do any more updates on the github repo, because there would be no way to keep adding al the changes of the wiki manually, and there is no point in having two different versions, each fixing half of the problems...

So now the one and only "official" version is the one on the wiki (there is a note that says so on the github repo). Ideally later on we'll find a way to generate proper pdf/ebook files directly from the wiki version...
User avatar
kkremitzki
Veteran
Posts: 2515
Joined: Thu Mar 03, 2016 9:52 pm
Location: Illinois

Re: Difficulties with the Manual Python example.

Post by kkremitzki »

yorik wrote:I'm not planning to do any more updates on the github repo, because there would be no way to keep adding al the changes of the wiki manually, and there is no point in having two different versions, each fixing half of the problems...

So now the one and only "official" version is the one on the wiki (there is a note that says so on the github repo). Ideally later on we'll find a way to generate proper pdf/ebook files directly from the wiki version...
So that git-mediawiki thing I was talking about a while ago fails when trying to clone the whole wiki, but it works pretty well with single, small categories. The following command can be used to get a snapshot of all the manual pages from the wiki:

Code: Select all

git clone -c remote.origin.shallow=true -c remote.origin.categories='Manual' mediawiki::http://freecadweb.org/wiki
Then you can remove all the translation copies:

Code: Select all

cd wiki && rm *%F*
Then once you have the .mw files you can use pandoc to convert them to the appropriate markdown format with something like this:

Code: Select all

for f in *.mw; do pandoc -f mediawiki $f -t markdown_github -o $f.md; done
Personally I think the gitbook looks extremely slick, so getting rid of it completely would be a shame. Hopefully with these tools it's possible for someone to come up with a way to update the git repo for the manual.
Like my FreeCAD work? I'd appreciate any level of support via Patreon, Liberapay, or PayPal! Read more about what I do at my blog.
User avatar
yorik
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Difficulties with the Manual Python example.

Post by yorik »

Yes, gitbook itself is really good, I agree. Thanks for these tips, this could indeed work... I'll play with it when i have a little time
Post Reply