[topologic] topologicpy - an independent python API for topologic
Hi everyone,
As you may know, I have embarked on an effort to port all the capabilities of Topologic + TopologicSverchok into a host-independent, GUI-independent, and platform-agnostic API. The result is topologicpy and it can be installed with a simple command on Windows and Linux:
> pip install topologicpy
I would like to use this forum to collect your feedback on this effort and to make sure that this API is robust and useful for you. You can comment on anything regarding this project including its direction, the quality of the code, the quality of the documentation, suggestions for the future, among other issues.
- The github repository is at: https://github.com/wassimj/topologicpy
- You can find a description of the topologicpy project at pypi: https://pypi.org/search/?q=topologicpy
- You can find the direct link to the documentation at: https://topologic.app/topologicpy_pdoc/
At the moment, topologicpy implements the complete API for topologic (Core). So it is useful in its current state. Additionally, most of the relevant classes of TopologicSverchok have also been ported, but they have not yet been fully tested. The code is being refactored where needed and documented using docstrings. The documentation is being auto-generated using pdoc3 https://pdoc3.github.io/pdoc/. This is ongoing work and any help is more than welcome.
As a user of topologicpy, you have a choice to access topologic directly using:
from topologicpy import topologic
v = topologic.Vertex.ByCoordinates(0,0,0)
print(v)
>>> <topologic.Vertex object at 0x00000211E0205C30>
or access topologic through topologicpy classes:
from topologicpy.Vertex import Vertex
v = Vertex.ByCoordinates(0,0,0)
print(v)
>>> <topologic.Vertex object at 0x000001DF2B3B2C70>
Please do test topologicpy and go through the code and documentation, report any issues, and ask for features and improvements. I hope you will enjoy topologicpy and I hope this discussion topic will be as active and rich as the original discussion topic for Topologic.
Comments
This is awesome! So TopologicSverchok now uses TopologyPy under the hood, is TopologicFreeCAD (I recall seeing an implementation there) also ported? I assume the Dynamo/Grasshopper implementations share a TopologicC# or similar under the hood?
No sorry TopologicSverchok has not yet migrated to topologicpy, but that will be the next step once all the methods in topologicpy have been refactored and tested. It will make TopologicSverchok nodes have far less code in them.
I do have the start of a TopologicFC workbench on GitHub that decomposes a CellComplex, but I need help with that. I don’t know how to implement numeric input, checkboxes etc and how to pass to topologic multiple selections of FreeCAD scene objects.
TopologicDynamo and TopologicGH share the same but much older C# and C++ code base. This will be deprecated. If I ever have time, these nodes will be recreated to also use topologicpy. This will keep all platforms synced. The new nodes will be nothing more than custom python nodes wrapping around topologicpy classes and methods.
Another aspect is that once topologicpy is ready, Streamlit can just pip install it and it will be available to topologic-based web apps. We have already proven that with our work connecting Speckle and Pollination (we being myself and Jake Staub).
And finally, there is a need to migrate topologicpy methods down to the C++ level so we increase performance. For now it is easier for me not to mess with the C++ code base and implement new functionality in topologicpy in python.
Still sounds pretty amazing! Do you think it's appropriate to write a ~300 word article about it on osarch.org?
Sure. Will also include a diagram of the architecture and the ecosystem.
Nice!
Do you have any examples?
Could it be used to create space meshes from bounded walls, slabs, celings, to create IfcSpaces?
Hi @Coen this is a good place to start:
I used @brunopostle 's rpm for use in FreeCAD on Fedora 36.
Any difference with topologicpy ? Thanks :)
Hi @paullee yes big difference. If I am not mistaken, what you are using is only Topologic (Core). topologicpy is the sum total of core plus all the functionality of TopologicSverchok nodes made headless. So things like machine learning, advanced graph functionality, energy analysis etc etc
@paullee I need to rearrange my rpms to match this new code split
Just to note that topologicpy is a few weeks from being complete. The Core is complete. I am working my way through all the topologicsverchok classes and methods to streamline. There will be some API differences between sverchok and py (not to Core). These will be brought back to sverchok eventually.
Link is broken
Yes sorry. It was changed. It is now
https://topologic.app/topologicpy_doc/topologic_pdoc
Hi, i am trying to make a topology by using a shape from Open Cascade. I am using the method
I'm passing the argument newShape, which is an OCC.Core.TopoDS.TopoDS_Shape from PythonOCC module and getting the following error:
Is there a way to convert a OCC.Core.TopoDS.TopoDS_Shape to topologic.TopoDS_Shape ?
Thanks for any info.
Hi @ArchProgrammer
PythonOCC is probably wrapping the TopoDS_Shape which Topologic knows nothing about. Instead, the easiest way is to produce the BREP string from your TopoDS_Shape and feed it to myTopology = Topology.ByString(brepString)
Thanks, it worked!
Great. Please share visual results if you can! :)
Also. If PythonOCC can create entities from a BREP string, you can use brepString = Topology.String(aTopology, version=1)
Hope the topologicpy can work in FreeCAD 0.21, as it works in 0.20 :D
Sadly no :(
I don't know why. It loads perfectly well under python3.8 and it works perfectly with FreeCAD 0.20. What did they change in 0.21 to make it fail??
import topologicpy
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\FreeCAD 0.21\bin\Lib\site-packages\shiboken2\files.dir\shibokensupport__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
File "C:\Program Files\FreeCAD 0.21\bin\lib\site-packages\topologicpy__init__.py", line 19, in
import topologic
File "C:\Program Files\FreeCAD 0.21\bin\Lib\site-packages\shiboken2\files.dir\shibokensupport__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
ImportError: DLL load failed while importing topologic: The specified procedure could not be found.
I posted this as an issue on FreeCAD's github: https://github.com/FreeCAD/FreeCAD/issues/8703
@yorik Any idea? Thanks.
Discussion about test on Fedora 36 -
https://community.osarch.org/discussion/131/topologic-redefining-bim-through-spatial-topology-information-and-grammars#latest
SOLVED!

It turns out, I had my old Topologic Workbench in my C:\Users[username]\Appdata\Roaming\FreeCAD\Mod\ folder which was incompatible with FreeCAD 0.21.0 This was being loaded first before the newer topologic included in topologicpy.
It is now working fine on Windows.
yes i was going to say, version mismatch :)
Thankfully, with the DLL mangling step when building Topologic, DLL version mismatch should not be an issue moving forward.
Congratulation! Hope RPM (or whatever) would be available on Linux (Fedora) so I can tes :D
@paullee the fedora Topologic packages are compatible with the fedora freecad packages, but they don't yet include the topologicpy API, you need to install this separately.
Thanks Brunopostle, re-visiting previous posts :)
Just note that topologicpy is compatible with the newer version of topologic. The main difference is in ExportToBRep and Topology.String where I implemented OCCT’s recommended versioning to be backward compatible with older builds of OCCT
@topologic @brunopostle, I have checked my previous post what I did for FC0.20 (xxx FC0.21 xxx ) which works :-
(All Brunopostle packages rpm were uninstalled.)
So now, I need to 'update' the pip topologicpy packages so it may works as @topologic now ?
Thanks for the pointer :)
Hi @paullee , not sure what you mean. If topologicpy is functional, you should use it instead of calling topologic directly. It is streamlined and has new methods and bug fixes not available in topologic. The API is cleaner and far better documented.
@topologic My fault, I should have meant it worked for 0.20 (typo corrected in my post now) and I listed out the procedure.
So the Q is, as it seems you have resolved the problem for 0.21, what on my side needs to do (on Fedora Linux) ?
Hope I make myself clear this time :)
Thanks