is it possible to call a python script in a C++ program


In ParaView’s Catalyst, one can write a Python script and call it from a C++ context, I wonder if this feature can be achieved in pure VTK ?


You can call Python code from C (regardless of VTK) using Python C API functions, such as PyRun_String.

but is it possible to call my C++ VTK classes from the Python code ? or some wrapping is needed ?

Yes, all Python-wrapped classes can be called from Python. The process for wrapping your VTK code has completely changed in VTK-8.9 and I cannot find a good documentation, but you can use vtk-dicom as an example.

@ben.boeckel it would be great if first 5-10 pages that come up when googling “VTK Python wrapping” would contain current information or link to current information. It is extremely difficult to find relevant information about Python wrapping. I know that you added useful information to VTK api documentation, but it seems that server-side search was not enabled when this documentation was generated, so there is way to find information about Python wrapping macros.

I’m not fluent in how to get Google to pay attention and rank the information appropriately. It used to be that linking to it would be enough, but now you need to convince the neural networks. Here is an MR which enables client-side searching (I’m unsure of what we’d need to do to support the server-side searching).

1 Like