'How to export NetLogo 6.2 View when you have multiple turtle profiles?

I'm trying to implement an output which is an export from the View. I got help from this link: How to export the world of NetLogo 6.2 coloring only the patches that were born turtles? I greatly appreciate Luke C's help, as I managed to implement part of what I want.

However, I still haven't managed to generate the images by turtle profile. I have 16 turtle profiles (see ValidHabs).

I would like for example to export an image for each of the 16 turtle profiles.

For example, turtle profile 1 (can only born and hatch in habitatcover 1), so:

At tick 0, the world started with: 1 turtle no (patch 15 -4),
At tick 1, there are 2 turtles in patches (patch 15 -4) and (patch 14 -8) and
At tick 2, there are 4 turtles in patches (patch 15 -4), (patch 14 -8), (patch 12 -5) and (patch 17 -1).

So for the turtle profile 1 you would have a white exported image with the patches (patch 15 -4), (patch 14 -8), (patch 12 -5) and (patch 17 -1) painted magenta. Then I would export an image to the profile of turtle 2 etc... until I get to the profile of turtle 16 that can only spawn in habitatcovers 4 and 5.

I tried to use a foreach to export the image to each profile, but what happens is that opens a single .png file and generates the results in that single file (“overwriting”). And what I would like is to generate 1 file in .png format for each turtle profile. I thought that using foreach and carefully I could generate the files. But so far I haven't been able to. If anyone can help me I would be very grateful :)

Thanks in advance

The code:

globals [ ListProfiles ]
patches-own [ turtle-born-here ]
turtles-own [ all-code  metabolism reproduction code-metabolism code-reproduction ]

to setup
  ca
  set ListProfiles [ [1] [2] [3] [4] [5] ]
  ask patches [ set turtle-born-here false ]
  ask n-of 5 patches [
    sprout 1
    setup-turtles    
    set turtle-born-here true
  ]  
  reset-ticks
end

to go
  ask turtles [
    rt random 60 - 30
    fd 1
    if random-float 1 < 0.05 [
      hatch 1
      ask patch-here [ set turtle-born-here true]
    ]
  ]
end

to setup-turtles 
  ask turtles [
    (
      ifelse
      metabolism = 2 [set code-metabolism "M1"]
    )
    (
      ifelse
      reproduction = 5 [set code-reproduction "R1"]
    )
    set all-code ( word code-metabolism code-reproduction )
  ]
end

to example-export-image
  setup
  ; Some example go runs
  repeat 50 [ go ]

  ; This is the export-view component
  cd
  ask turtles [
    ht
  ]
  ask patches [
    ifelse turtle-born-here
    [ set pcolor magenta ]
    [ set pcolor white ]
  ] 
  carefully
  [ file-delete ( "View.png" ) ]
  [ ]
  foreach ListProfiles
    [
      y ->
      let k turtles with [ all-code = y ]
      ask k [
      export-view ( "View.png" )
      ]
    ] 
end


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source