How can I create an image from a STEP file in python - python

I currently have a python script using the freecad API to read a step file and send some data to an excel file (volume, dimensions, etc.) with xlwings. I would like to also add a view of the STEP file. Is there a way using python to get an image from step file?
I've seen in the freeCAD docs that you can use something like this:
FreeCADGui.ActiveDocument.ActiveView.saveImage(filePath)
But I am not running the GUI, so this option currently does not work for me.

Related

ACIIDOC to PDF in Python without need for files

So I am generating reports with Python and Ninja in the ASCIIDoc format.
But from within my app I need to convert them into PDF and upload them to another system.
I have seen that there are multiple HowTo for command line that involve ASCIIDoctor or other tools, but they always are invoked at OS level by starting a program or running a docker container and writing the output to a file.
Isn't there a way to perform those action within my app and get the PDF as a string that I can use for the upload?
You can certainly use the available tools to generate a PDF, which you could then read into memory as an opaque string that could be uploaded as needed.
If your question is: how do I generate and upload a PDF without installing any other tools?
Then the answer is that you'd have to implement the PDF generation logic yourself, rather than using tested tooling.

Script for post-processing vtu or pvd files

I am pretty new to post-processing using python scripts. But all these days I used ParaView to look at my results(images at different time steps). But as my mesh resolution increases the image of the next time step takes forever to load. Therefore, I would like to create a python script which can save the results at every timestep in image formats (png or jpeg) and also maybe merge the images as a video file.
I have a folder SavingsforParaview which contains a single .pvd file and 217 .vtu files, one for each time step. In ParaView, we load the pvd file and then visualize everything. Now, I would like to build a script to do the same. I don't want to use the inbuilt python script in ParaView, but create a separate file that I can run in a terminal using python commands.
The files can be found here.
https://filesender.renater.fr/?s=download&token=6aad92fb-dde3-41e0-966d-92284aa5884e
You can use the Python Trace, in Tool menu.
Usage:
start trace
use PV as usual (load files, setup filters and views, take screenshot ...)
stop trace
It generates the python version of your actions and display it. Then you can save it as a python file and manually modify it.
For instance, you can do the visu for the first 2 timesteps and then edit the trace file to add a loop and cover each timesteps.

How can I open cytoscape file via cyrest in python?

I'm currently working with cytoscape and created some session file.
Then I'd like to access this file in python and get its result as an image - I'd especially like to sort it with some particular shared name when I'm requesting a result, meaning the result changes upto sorting word. Thanks.
There is a python library that faciliatates working with CyREST in Python. You should be able to do just about anything you can do in Cytoscape from Python. Here's the manual: https://py2cytoscape.readthedocs.io/en/latest/
And here are some of the steps you are looking for:
cyclient.session.open()
cyclient.network.list()
cyclient.view.export()

Using python to build a latex document

I have a script I have written in python which pulls data from a bunch of files on my computer which change daily. I want to insert the results into a latex template so that I can review the summary.
What is the best way to open a file and insert text into it at a specific point?
Preferably using a python, but I'm open to other tools if there is something better.
Thanks
Russ
You could also do it all from within python using the pylatex library.
https://github.com/JelteF/PyLaTeX
This way you only have to run the python file every day.
I figured out how to do it.
It seems to me the best way is to have python output low level latex code, then use latex's command \input to pull that code into a larger document.
https://en.wikibooks.org/wiki/LaTeX/Modular_Documents

Can I output a mayavi plot as .vtk file to embed in a web app?

Okay, a little background here. I made a script that plots a dataset as 3d line plots using mlab.plot3d(), multiple times in Mayavi, after reading it from an xlsx file.
Now, I am trying to make a web app to see the created 3d models in a web browser interactively.
After some search, I found xtk and thought about saving the Mayavi output as a .vtk file, and viewing it online using xtk.
Question 1: is it a stupid plan? are there easier ways?
Question 2: if it's feasible, how do I output all the components of a mlab scene into a single vtk file?
I searched and found the save_output() function from the mayavi pipeline children using record, but that only seems to work for single objects. Any idea how to do it for the whole scene?
If you have installed mayavi, then you'll have included the tvtk python library, which is one of its dependencies. The documentation gives some examples how you can write your structures to a vtk file using the write_data function.

Categories