Create custom properties for an object and write them to a text file

Can I make a script in a blender that will set a custom property to an object and use a command (operator) to create a text file and write the values of these properties there?

In 3ds max, this is done like this.
I created a checkbox that writes text to the properties of an object.
Which I marked red.
I also created a list of surface properties that, when selected, writes its number.
surfaceproperty=1 (surfaceproperty=0 - 27).
After that, I press 1 button which creates a text file and writes there the names of all the meshes and all the properties that I set.

The text of the file itself.
How can I do the same in a blender?


there’s a lot to unpack in this question, and I’m not at my computer so I am not able to go into too much depth, but you need to know how to do the following:

1.) read and write custom properties from blender data blocks
2.) write data to a file using basic python file I/O

for the first one, i’d suggest reading up on custom properties from a non-scripting standpoint:

Once you understand how custom properties in Blender work, you can dive into the python side of custom properties:

And probably the easiest of all (since it’s just basic python and doesn’t really have anything to do with Blender), writing to a file: