I'm glad you joined Jochem!
First off, you can't place defensive positions for a single kind of soldier. You can only place defensive positions for infantry (which include militia, axe fighters, sword fighters, barbarians, and warriors (TRP only)), ranged units (bowmen, crossbowmen, ballistae (TPR only) and catapults (TPR only), long weapon units (lance carriers, pike men and peasants (TPR only), and mounted units (scout, knight and vagabond (TPR only). The AI will place each type of soldier in the correct defensive position. For example, the AI will place militia in infantry defensive positions.
Secondly, KaM has only a one type AI for making troops. The AI always make the best quality unit it can make for that certain type of unit. Let me explain: the AI will go from making a infantry then it will make a long weapon soldier (pike man or lance carrier) then it will make a ranged unit (crossbowman or bowman) and then a mounted unit. (though that might not be in the correct order). If the AI can, they will make an iron armor version of that type of unit. If not, then they will make a wood type. For example. Let's say the AI want's to make a ranged unit. If it has 1 bow, 1 leather armor, 1 crossbow, 1 iron armor, and 1 recruit; it will make a crossbowman because crossbowmen are of better quality then bowmen.
So, to stop the AI from making bowmen, just don't give the AI any weapon workshops, or don't let it start with any bows in it's barracks/storehouses.
Your asking how to stop the AI from making militia. If the AI is making militia, then it's because it wants to make an infantry unit but it can't make a sword fighter or a axe fighter. So to stop the AI from making militia, give them a armory workshop, leather (so they can make leather armor) and enough woods to make wooden shields and axes. The AI will start making axe fighters instead of militia. Or you could give the AI the necessary buildings and resources to make sword fighters.
I hope you understand.
The soldiers of the second line, behind the defence position position themselves among the soldiers of the first line. How do I prevent this?
I don't understand what your trying to ask (sorry). I'll tell you the difference between first and second lines and hope that helps.
The first line are the soldiers that will guard the base. They will
NEVER be sent in AI attacks. The units in the second line will go on attacks if the attack includes that kind of unit. So, if you have and attack that sends a group of infantry and the AI has a group of infantry in it's second line, then they will send those.
Note that the AI doesn't need a first line to have a second line. A better name would be defenders and attackers.
Also note that the AI will fill up defensive positions in the same order you place them. This is because the AI reads the top of the code and reads down. So if you place your second line before your first line, they will fill up the second line first, understand?
Well I hope you do, and I hope this helps. If not, I'm sure Lewin will probably be able to help.