Part Scripting: Geometry vs Topology

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

Part Scripting: Geometry vs Topology

Post by Aleks »

I am starting out with Part scripting but I am confused by what the differences are between geometry and topology. I have searched for explanations in the forum and wiki but could not find anything.

Also how do vectors relate to geometry and topology? I know what a vector is mathematically but how does it fit in in this context.

I would be thankful for any input.

Sincerely,
Aleksander
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
spanner888
Posts: 326
Joined: Tue May 28, 2019 10:51 am

Re: Part Scripting: Geometry vs Topology

Post by spanner888 »

This link is for Part WB, but I think is still relevant to introduce some of the concepts.
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

Re: Part Scripting: Geometry vs Topology

Post by Aleks »

There are 2 different groups of entities : geometry and topology.
Geometry entities are mathematical objects, like vectors, curves (bspline, bezier, circle, ellipse, line, etc) and surfaces (cone, cylinder, plane, bspline surface, etc)
They are invisible objects.
Part.Curve is the parent class of all the curves.

On the other hand, what you see in the 3D view are topology objects, like vertexes, edges, faces.
Vertexes, edges, faces are created on top of geometry objects.
The parent class of the topology objects is Shape.
There are also some aggregation of these 3 base types, like wires, compounds, shells, solids, compsolids.

Depending on your needs, you will work at the geometry level, or the topology level.
geom_object.toShape() is handy for converting a geometry obj to topology.
-Chris_G

I think this is a good explanation. Something like this should be added to the wiki on the part scriptng or the topology page.
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

Re: Part Scripting: Geometry vs Topology

Post by Aleks »

While
https://de.slideshare.net/adankevich/ca ... try-basics
explains what geometry and topology are, i still dont understand when you would use one or the other.

Or formulated differently:
Would it be possible to only use topology objects when creatig shapes?
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Part Scripting: Geometry vs Topology

Post by Chris_G »

Aleks wrote: Fri Nov 19, 2021 11:31 am Would it be possible to only use topology objects when creatig shapes?
The Part.makeSomething() functions will return a topological shape directly.

Code: Select all

[name for name in dir(Part) if "make" in name]
['makeBox', 'makeCircle', 'makeCompound', 'makeCone', 'makeCylinder', 'makeFace', 'makeFilledFace', 'makeHelix', 'makeLine', 'makeLoft', 'makeLongHelix', 'makePlane', 'makePolygon', 'makeRevolution', 'makeRuledSurface', 'makeShell', 'makeShellFromWires', 'makeSolid', 'makeSphere', 'makeSplitShape', 'makeSweepSurface', 'makeThread', 'makeTorus', 'makeTube', 'makeWedge', 'makeWireString']
You can try work with these ones, and you'll see if you need the more low-level geometry functions.
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

Re: Part Scripting: Geometry vs Topology

Post by Aleks »

Chris_G wrote: Fri Nov 19, 2021 1:31 pm
Thank you chris!
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Part Scripting: Geometry vs Topology

Post by onekk »

I'm using scripting very often, you will see that you will be using both costruct, as many times you have to access some low level information.

So better to know better both ways.

Part.make...

Are very useful, one of the most useful in my opinion is Part.makePolygon.


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