So i've tried replacing the code, but im not quite sure where to put it or what to delete
Am i even close or?
Stops at first ENTITY 
And yes i've also experinced the fault with the tool names, mainly because in my country we use "ÆØÅ" and when changed the tool name in the list it still couldnt save the image, but figured it out like 2 weeks ago
STRING $Fold=''
STRING $CFold=''
STRING $Sz="80p"
// build the expression
STRING $expr = "RootType=='nctoolpath'"
// get the list of tool (sorted in the NCProgram order)
STRING LIST $tl_list = extract(sort(filter(components(entity('ncprogram', $Selected_NCP)), $expr) ,'tool.number') , 'tool.name')
INT Nb=remove_duplicates($tl_list)
/// Liste tous les outils
FOREACH ToolName IN $tl_list {
ENTITY $tp=entity('Tool',$Tl)
$ToolName = $tp.name
ENTITY C_Tool = entity('Tool',$ToolName)
$Fold=dirname(Pathname($C_Tool))
IF $Fold != $CFold {
// MESSAGE INFO " $Fold $CFold "
$Ligne = "<TR><TD colspan=10 style='background:#4F81BD'><H3>"+ $Fold + "</H3></TD></TR>"
FILE WRITE $Ligne TO filename
$CFold=$Fold
}
// Depuis les Outils
$Ligne = "<TR>"
FILE WRITE $Ligne TO filename
// Image
$Ligne = "<TD>"
FILE WRITE $Ligne TO filename
$Ligne = '<div align="' + 'center"' + '>'
FILE WRITE $Ligne TO filename
// CREATION IMAGE
$ModiToolName=REPLACE($ToolName," ","_")
$ModiToolName=REPLACE($ModiToolName,"/","-") // Corrige les nom outils du type 1/4 Endmill
Kind regards
Marc W