Help me with create a script?

Hi, i’m really lazy to read the books and learning by videos because i’ve not so much time to that. That’s why I’d like to make one script which can export Camera’s location and rotation properties to the binary file. So, how to do that? Please, help me.Thanks,Best regards.

The camera location and rotation information is contained in the “matrix_world”.
So just run this script in the text editor.

import bpy

class WM_OT_camera_info(bpy.types.Operator):
    """Save a text file with the camera matrix info"""

    bl_idname = "wm.camera_info"
    bl_label = "Save Camera Matrix Info"

    filepath = bpy.props.StringProperty(

    def execute(self, context):
        mat =

        with open(self.filepath, "w", encoding="utf-8") as file:

        return {'FINISHED'}

    def invoke(self, context, event):
        if not self.filepath:
            import os
            self.filepath = os.path.join(os.path.expanduser("~"), "camera_info.txt")

        wm = context.window_manager
        return {'RUNNING_MODAL'}

def register():

def unregister():

if __name__ == "__main__":

    # test call

How to export as already has got files like “export with binary code-pasted file”? P.s.: i’ve a file with binary format and i must assign new code line to this existing file with changed codes?

Coders are in a extreme demand because nowadays a very large part of our economy is based on software and yet we cannot produce enough new coders, even bad ones, to cover the very high demand.

Thus its its extremely difficult to find people to code for you. Especially for free.

I am afraid if your really want to heavily increase your productivity coding is a must know. Because nothing else comes remotely close in efficiently automating tasks. Which in turn means the red line between coders and users is non existent.

Python is a language that was never meant to be used as a programming language but rather as a scripting language used by users with limited knowledge. Hence why Python nowadays is so beginner friendly.

Blender Python API is way more challenging but again with thousands of addons around and such an active community it’s very hard not to find the information you need.

Coding is is not hard , just time consuming. If you invest the time you will acquire the very valuable skill of automation. The choice is yours.

And and yes we are all lazy, that is no excuse.

Yeah, i know this. But how to understand all Python FAQ if high-level coders are still learning much more than us?! I’m really want to understand all of this things, but so sadly.

Python is not that difficult. The Blender API is also straight forward. A script structure is a bit more complex in order to fully integrate with Blender’s workflow. The most difficult part of programming a script is to define the problem, how to solve it and how to use the results…

In this particular case, camera’s location and rotation are stored in a 4x4 matrix (the world-matrix, as mano-wii explained above).
Matrixes are quite usefull mathematical entities that can store translation, scale, and rotation, that can be used to transform a coordinate system into another. For a camera, we only need to do this for the origin; and for meshes, we just apply the transformation to all vertices…

Getting that matrix was already explained by mano-wii also.

Now, the second part of the problem is: What is the structure of the binary file that you need to store that info?
A file is just a collection of bytes. They start with the byte[0], followed by the byte[1], etc.
But a byte can only represent an integer number between 0 and 255, which is not very usefull for storing other numbers, specially the ones that compose the matrix. So you need to define how do you want them to be stored, and more important: how are you going to use them in the end.

More specifically, you’ll going to need floating point numbers (which are a trick of storing values of any kind into bytes). As a 4x4 matrix is composed of 16 different components ( 4 rows and 4 columns), you can easily just store them in a simple sequence.

Now, do you really need to store them in a binary format? Because a simple ascii file can serve this purpose very well. They are faster to edit, easy to read, and for storing a 4x4 matrix it will result in a very small file (probably far less than 400bytes).

So, in the end, you’ll need to answer this questions in order to proceed into the programming part (and to recieve a better help from the forum).

First of all, thanks for quick reply.:)Take me chance to explain:1. I’m modder of the simulator game and want to create the script which can export the special file directly from Blender itself; 2. The simulator game is a soccer game. It has some cut scenes like in TV translation camera shows up atmosphere of the stadium from the tribunes. And this cameras properties(locs,rots) included in special file format (*.fdc);3. So, I understood the hex codes of the their locs and properties in that files, BUT still didn’t understood all over the *.fdc file structure(header and etc. as mentioned HEX codders). Just I know create camera in Blender and paste these Locations and Rotations props (Quaternion XYZ values in this case) to the FDC camera file usin FlexHEX software;4. So, how to create the script which can automatically export those values of the camera from Blender as FDC file?Thank you guys!

Knowing the file structure is important. Without it, there’s nothing we can do (and I don’t know anything about that specification).

Anyway, writing into the file is fairly easy either by using the file.write(repr(data)) or something like this:

For the fdc structure, you can adapt mano-wii’s script to write it…

Can you post the fdc specs?

Here that FDC file: Can you take a look?

Those are not the specifications of the fdc file. Only fdc files alone. That means that I’ll need to decode whatever is there and that alone will take a week of my free time alone (or more), and even so, some data may not work at all.

If you need it urgently you’ll need to post the specs. Otherwise, you’ll need to wait.

here’s an example of what a file specs might be:

You might need to contact the development team in order to get it.

I saw your link, but still don’t understand without screenshots-based examples of the hex file.What is the next steps?

The fdc file structure must have a definition; for example:
the 4 first bytes represent something, the second 8 bytes represent something else, and so on until the end of the file.
Each byte has a different meaning depending on its location in the file structure. And this is what is needed to know.

Imagine a file where the first byte may be 0, the second 120, the third 10… This is what you can read from the file alone. But if the specification of the file says that the first 32 bytes represent a floating point number, and you don’t know this, then all your work is just a guess work. And worst, if you write something there that the software that will read it cannot interpret?

For now, the fdc structure is unknown. Creating a fdc file, is like translating information into some language. But if you don’t know the structure and the grammar of that language, there’s not much you can do… and probably everything you write in that file can be tottally misunderstood by the software that will read the file afterwards.

You need to contact the development team that are making the game and ask them for the specifications of that file type. With specifications I mean, how it’s organized, structured, if singles and doubles are big or little endians, how the header is composed, and how is the Toc represented, etc. In sum, the grammar of the file!
When the grammar is known, then writing a file that means something to the software wich will read it, is simple. Without it is like trying to comunicate with a martian (without knowing martian language).

This what my friend is made:

That doesn’t help. it’s of no use, and it doesn’t have any information at all about the file structure…

Please take your time to contact the development team.(the one that are creating the software that will read the file)

(I seriously doubt that anyone asked you to write data into a file, without telling you how the data is structured)

Remember that binary files are just bytes in sequence. But what these bytes represent is something that is not included it the file. It’s something that the writer and the reader must have established apriori. Right now, the writer doesn’t know the language to communicate with the reader (most like I’ve been failing to communicate with you).

If he can’t help me to understand the file for not break the license of the game, so what? :frowning:

If this works in game why not just automate overwriting this file location with your camera values? Leave everything else untouched.
Investigate reading and splitting the FDC file (into header, overwrite_target, footer), recombining it (into a string, list, array, whatever works) and writing that out with the appropriate encoding (one that reads the same in FlexHex, some testing likely required).

Note: Don’t double encode (footer and header).

Can u explain to me?

Sure. Just ask about what part needs explaining. If you mean code it for you, I can’t.

Does pasting manually through FlexHEX work (is the mod functioning)?

@secrop, i can’t contacting with the devs. Exactly, don’t know an email of their.@LoboTommy, which part is header and which is footer in that my file?

If the file specs are unavailable, then creating a good script will be difficult. When you do it manually with your hex editor, what are exactly the steps you perform?