I don't think this is what he meant to ask.
Currently, when you are trying to set tiles via code, you have to manually specify a vector representing a bitmask index required to select a sprite corresponding to autotile.
There is no way to put a sprite in the valid fashion from the very start, but what you can do, is to put all the sprites in the corresponding positions and call updatebitmaskregion after that.
Here is an example from my code:
private void InstanciateTilemap(Node scene)
{
var set = GD.Load<TileSet>("res://TileSets/Default.tres");
var map =
new TileMap
{
TileSet = set,
CellSize = new Vector2(32, 32),
CellQuadrantSize = 16
};
var size = OS.WindowSize;
for(var horizontalIndex = 0; horizontalIndex < 16; horizontalIndex++)
for(var verticalIndex = 0; verticalIndex < 16; verticalIndex++)
map.SetCell(
horizontalIndex,
verticalIndex,
1
);
map.UpdateBitmaskRegion(
new Vector2(),
size
);
scene.AddChild(map);
}
}
Source: https://github.com/godotengine/godot/issues/13960