Convert VTK into JSON with a script - python

I need to convert a vtk file into json file in the back-end of a server (e.g subprocess). Therefore, I would like to create a script (e.g. python) I can call and run from remote. Are there any tutorial for that ?
Thank you !
Regards

Start by running blender from your script/process with the background mode argument --background. You can follow that with a python script with the --python <script.py> argument. You may find this question on how to pass arguments to a script interesting.
blender --background --python export_to_json.py
You already know where to get the info for importing VTK. If you don't know, the three.js project has a blender exporter that uses JSON.
The script you make would use the following two commands to do the import and export -
VTKBlender.PolyDataMapperToBlender.convert(pmapper, me=None)
bpy.ops.export.three(filepath=outfile)

Related

How to retrieve a filename and file created using a shell script that was called from a python script?

I have a python script that calls a shell script. The shell script captures an image, names the image using a timestamp, and then saves the image to directory. When the shell script finishes, I would like to access the image from the python script that called the shell script.
Here is my shell script capture.sh:
DATE=$(date +"%Y-%m-%d_%H%M%S")
fswebcam -r 1280x720 --no-banner /home/pi/app/images/$DATE.jpg
exit 0
This shell script is called from capture.py:
import os
import subprocess
# call script
subprocess.call(['/home/pi/app/capture.sh'])
#?how to retrieve and process image: /home/pi/app/images/$DATE.jpg
Any advice would be welcome! Thank you!
You can send the name of the file created by the bash script to standardout and capture that in the python script. Here is a similar SO question that I think will lead you in the right direction.
As the top answer to this question points out, it will depend on what version of python you're doing this work in. It looks like you're using subprocess.call. In terms of the current python docs for subprocess, that is the old API call. You can now use subprocess.run in versions 3.5 and newer, which is the recommended way to invoke child processes.
Running shell command and capturing the output

How to interface Python with Qlikview for data visualization?

I am using Scikit-Learn and Pandas libraries of Python for Data Analysis.
How to interface Python with data visualization tools such as Qlikview?
There's no straightforward route to calling Python from QlikView. I have used this:
Create a Python program that outputs CSV (or any file format that QlikView can read)
Invoke your Python program from the QlikView script: EXEC python3 my_program.py > my_output.csv
Read the output into QlikView: LOAD * FROM my_output.csv (...)
Note that the EXEC command requires the privilege "Can Execute External Programs" on the Settings tab of the script editor.
This link shows you how to integrate Qlikview and Python https://community.qlik.com/docs/DOC-14011

Blender2Ogre - Execute python script in command line

I would like to transform blender meshes into ogre meshes. I downloaded this add-on which is a python script that allows me to do it.
I already installed this extension in blender (user preferences - addons - Install) and works perfectly.
Now I would like to execute the same script in the command line so I can transform any mesh without opening the blender user interface.
Using cmd (I'm a windows user) I go to the folder where blender is installed and run the following command:
blender.exe --background --python ./2.76/scripts/addons/io_export_ogreDotScene.py box.blend
but nothing happens. I think it's because the script was written only to be used inside blender, not through the command line.
Is there a workaround to execute this script ?
I'm not really good in python, so reading the script is not helping me at all.
I'll appreciate any help I can get form you guys !!
I was able to decode the script and make it run from the command line. It converts a blender file sent as a parameter and converts it in a ogre mesh file.
If you need it, let me know.

How to run python script within the python interpreter in Bash

I am using python3.5 to learn how to scrape data from website. And I realize IDLE is slow when the input explodes (like when I using .text to check the contents of the web). So I use Bash to test my scraper.py script.
After I enter python in Bash:
154-76:~ FDSM_lhn$ python3.5
It's hard for me to open a .py file. The only way I know how to do that is:
import scraper.py
which is not convenient because the object I create isn't in that environment. During the test I need to check something in it from time to time.
Can anyone can help me fix this?
If you have a file called scraper.py, you should be able to execute it via python -i scraper.py. This will leave it interactive.

Running python script in Blender

I installed Blender 2.6 and I'm trying to run a script called drawcar.py (Which uses PyOpenGL)
I looked around the documentation for importing a script and could only access Blender's python console.
How do I run drawcar.py from the Linux terminal with Blender?
You can also execute the following code in the python console to execute an external script without opening it up in the text editor:
filename = "/full/path/to/myscript.py"
exec(compile(open(filename).read(), filename, 'exec'))
The above code comes from the following link:
Blender - Tips and Tricks
Open a Text Editor view in Blender.
Press Alt + O, or go to Text>Open Text Block and open the .py file
Then simply press Run script :D
P.s. Instead of opening a file in step 2, you can also hit the "+ New" button and create a new script instead.
Note : In newer versions the Run Script button label has been replaced with a Play icon :
this answer is too late, but to help anyone with the same problem
via the terminal:
blender yourblendfilenameorpath --python drawcar.py
from the man pages
-P or --python <filename>
Run the given Python script file.
To run a script by another script or from console:
import bpy
script = bpy.data.texts["script_name.py"]
exec(script.as_string())
It is likely that drawcar.py is trying to perform pyOpenGL commands inside Blender, and that won't work without modification. I suspect you are getting some import errors too (if you look at the command console). Blender has it's own internal python wrapper for opengl called bgl, which does include a lot of the opengl standards, but all prefixed by bgl.
If you have a link to drawcar.py I can have a look at it and tell you what's going on.

Categories