[topologic] topologicpy - an independent python API for topologic

edited March 2023 in General

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.

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.

Tagged:
CoenbasweinvpajicpaulleebitacovirMoultJesusbilljsdbroughton
«1

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?

    paullee
  • 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.

    Moultpaullee
  • Still sounds pretty amazing! Do you think it's appropriate to write a ~300 word article about it on osarch.org?

    topologic
  • @Moult said:
    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.

    Moult
  • Nice!

    Do you have any examples?
    Could it be used to create space meshes from bounded walls, slabs, celings, to create IfcSpaces?

    topologicpeperibera
  • Hi @Coen this is a good place to start:

    Coen
  • 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
  • @paullee I need to rearrange my rpms to match this new code split

    paullee
  • 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.

    paulleeAce
  • Hi, i am trying to make a topology by using a shape from Open Cascade. I am using the method

    topologicpy.topologic.TopologyByOcctShape(newShape) 
    

    I'm passing the argument newShape, which is an OCC.Core.TopoDS.TopoDS_Shape from PythonOCC module and getting the following error:

     TypeError: ByOcctShape(): incompatible function arguments. The following argument types are supported:
        1. (rkOcctShape: topologic.TopoDS_Shape, rkInstanceGuid: str = '') -> topologic.Topology
    

    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)

    Moult
  • @topologic said:
    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!

    topologic
  • @ArchProgrammer said:

    @topologic said:
    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

    topologic
  • edited February 2023

    @paullee said:
    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

    paullee
  • edited March 2023

    @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

    import sys
    sys.path.append("/home/paullee/.local/lib/python3.10/site-packages")
    import topologicpy
    
    Traceback (most recent call last):
    File "", line 1, in
    File "/home/paullee/Downloads/FreeCAD_weekly-builds-31391-2022-12-22-conda-Linux-x86_64-py310/squashfs-root/usr/lib/python3.10/site-packages/shiboken2/files.dir/shibokensupport/feature.py", line 139, in _import
    return original_import(name, *args, **kwargs)
    File "/home/paullee/.local/lib/python3.10/site-packages/topologicpy/__init__.py", line 16, in
    import topologic
    File "/home/paullee/Downloads/FreeCAD_weekly-builds-31391-2022-12-22-conda-Linux-x86_64-py310/squashfs-root/usr/lib/python3.10> /site-packages/shiboken2/files.dir/shibokensupport/feature.py", line 139, in _import
    return original_import(name, *args, **kwargs)
    ImportError: /home/paullee/.local/lib/python3.10/site-packages/topologicpy/bin/linux/topologic/./libTopologicCore.so.0: undefined symbol: _ZN24BRepBuilderAPI_MakeShape5BuildEv
    
  • 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.

    paullee
  • yes i was going to say, version mismatch :)

    topologicpaullee
  • Thankfully, with the DLL mangling step when building Topologic, DLL version mismatch should not be an issue moving forward.

    paullee
  • @topologic said:
    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

  • edited March 2023

    @topologic @brunopostle, I have checked my previous post what I did for FC0.20 (xxx FC0.21 xxx ) which works :-

    • pip install topologicpy
    • In FC0.20_ even though it is python 3.9, force it to look into 3.10 site-packages -
    • in FreeCAD 0.20 : sys.path.append("/home/paullee/.local/lib/python3.10/site-packages")

    (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 :)

    topologic
  • So now, I need to 'update' the pip topologicpy packages so it may works as @topologic now ?

    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.

  • edited March 2023

    @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

Sign In or Register to comment.