In a similar situation I made a two part tool to clamp round the D shape shaft from, I think, aluminium alloy bar giving something to hold to stop things rotating whilst the nut was undone.
Basically I drilled a hole close to one edge of a suitable length of bar and milled off the edge until the hole was reduced to a D shape of the correct depth. I suspect I had to work on the edges to make it U shaped so it could pass around the shaft. I then drilled and tapped two holes, one each side of the recess, to clamp a second short piece of bar across the flat holding the shaft securely whilst undoing the nut with a suitable spanner.
Hardest part was probably scheming things out so the tool could be fitted in the space availiable.
Overkill engineering really but going direct to something that would work is frequently faster than escalating improvisations.
Where there is sufficient space a Mole or similar self locking plier with wooden protectors on the jaws can work well. Some creativity with a similar protector on one side of a self locking adjustable spanner, recently discussed, might also be promising.
Clive