Script to place desired object with left click


I wonder how can I make a python script to use blender as a tile-map editor.

I found sprytile which works well, but I wanted to made something simpler.

For example, I create 3d tiles named 1,2,3,4… and then I set a script to place “1” every time I click with the mouse.

I think I’ll read the sprytile source and see if I get this.

There is this little problem with the screen being 2d and the work space 3d. It works with the 3d cursor so one could use that, but the same problems that are there with the placement of the 3d cursor would remain. It might not be a very easy and precise way to do it. What result are you after, could you share some screenshots? Maybe there is another approach. I think one could go for distributing the tiles automatically. I can help with the script, but I would not wish to be wasting my time on something that might not be useful at the end of the day.

Let’s say you could run a script that takes all the selected objects and places them at the location of the 3d cursor every time it changes untill all of the selected objects are placed one by one in alphabetical order of their names. Would that be what you are after?

Yes, This is a 3d tileset:

And a sample map:

I made it using the snapping function, but placing all tiles is a bit slow this way. So I thought using something similar to sprytile that places tiles in x,y,z planes, could be awesome to make maps faster.

I cannot think of anything faster than snapping. Nothing will be faster than snapping if the parts need to align to each other precisely. Blender has a lot of really advanced snapping features, I suspect that it might be that you are not using them to the full if you are struggling with them. It might be useful to have a more thorough look at what tools are available. You can use increment snapping for example. I honestly cannot think of any Python code that I could improve that with.

Yeah, maybe you are right, I just imagined porting some 2d maps to blender with this, but it would be very slow to adapt it to 3d, so I think it is faster to use the snapping tools.