Blender2Ogre - Execute python script in command line - python

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.

Related

Trying to run Python program from command prompt

Path must be messed up and I can't fix it.
In the command prompt I am trying to open and run a python program that I made in IDLE. I am running Python 3.8.5. According to Automate the Boring Stuff, I should just be able to do:
py birthdays.py
But when I do that I get:
C:\Users\name\AppData\Local\Programs\Python\Python38-32\python.exe: can't open file 'birtdays.py': [Errno 2] No such file or directory
All of my scripts are located in: C:\Users\henri\AppData\Local\Programs\Python\Python38-32.
The only thing that I could think of is that it is going one step too far and searching in python.exe instead of just Python38-32. But Ii'm not even sure it works like that.
I tried to add the exact path using:
set PATH=%PATH%;C:\Users\name\AppData\Local\Programs\Python\Python38-32
But when I do this and press enter nothing happens.
when I want to use CMD to run python scripts, I just use
cd\
to back the main root of drive C. then use
cd folderAddress
for several time until to reach the exact scrip containing folder. Finally, I type
python scriptName.py
In your command prompt type python.The output should be python 3.** (depending on your python version).
If you see the python version it's working fine. In command prompt navigate to the folder that you have your python file using cmd command. then type
python birtdays.py
Don't forget the space after python.

Convert VTK into JSON with a script

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)

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.

Running Python from the Windows Command Line

How do I run a Python file from the Windows Command Line (cmd.exe) so that I won't have to re-enter the code each time?
Wouldn't you simply save your Python code into a file, and then execute that file using Python?
Save your code into a file called Test.py.
And then run it?
$ C:\Python24\Python.exe C:\Temp\Test.py
If you don't want to install an IDE, you can also use IDLE which includes a Python editor and a console to test things out, this is part of the standard installation.
If you installed the python.org version, you will see an IDLE (Python GUI) in your start menu. I would recommend adding it to your Quick Launch or your desktop - whatever you are most familiar with. Then right-click on the shortcut you have created and change the "Start in" directory to your project directory or a place you can mess with, not the installation directory which is the default place and probably a bad idea.
When you double-click the shortcut it will launch IDLE, a console in which you can type in Python command and have history, completion, colours and so on. You can also start an editor to create a program file (like mentioned in the other posts). There is even a debugger.
If you saved your application in "test.py", you can start it from the editor itself. Or from the console with execfile("test.py"), import test (if that is a module), or finally from the debugger.
If you put the Python executable (python.exe) on your path, you can invoke your script using python script.py where script.py is the Python file that you want to execute.
Open a command prompt, by pressing Win+R and writing cmd in that , navigate to the script directory , and write : python script.py
A good tool to have is the IPython shell. Not only can it run your program (%run command), but it offers also many tools for using Python interactively in an efficient manner (automatic completion, syntax coloring, quick access to the documentation, good interaction with Matplotlib,…). After you install it, you'll have access to its shell in the Start menu.
You need to create environment variables. Follow the instructions here: http://www.voidspace.org.uk/python/articles/command_line.shtml#environment-variables
In DOS you can use edit to create/modify text files, then execute them by typing python [yourfile]

not able to start coding in python

i want to code in python and i know the syntax well.. but i have got no idea how to compile and run it ..!! i mean i am from ruby , java , c , c++ background and there after saving it in a file we go to command prompt and type the command and the file name to compile and run it .
then what about python ?
why does python filename.py doesnt work ?
and how to make a file run then ?
and which python books to follow for better understanding
i am using windows os .! and i dont want to run it line by line on the idle .. i want to write the whole code and then run it from windows command prompt
If you're using Windows, you'll need to add the path to your Python executable to the Path environment variable; on Linux, and I presume Mac, this should already be done.
Oh, and you don't compile python programs, they are interpreted at run time.
If you are from Ruby background, you should be able to handle another interpreted language, which is what python is too.
Good starter resource:
Dive into Python
what operating system are you using?... you dont need to compile python code its interprated. just invoke the command line interpreter followed by the name of your .py file

Categories