simply script

I am wondering if it is possible to simply this script using a repeat loop…


	
	tell application "Adobe InDesign CC 2018"
		activate
		set amountTemperature to {"1", "2", "3", "4"}
		set emissionList to {"75/65", "65/55", "55/45", "45/40", "45/38", "38/33", "35/30"}
		
		set amountTemperatureNumber to choose from list amountTemperature with prompt "How many emissions do you want to calculate?" default items {"3"} OK button name "Update document"
		if amountTemperatureNumber is false then return
		
		-- selection: 1 emission
		if item 1 of amountTemperatureNumber is equal to "1" then
			set Emission1 to (choose from list emissionList with prompt "Select emission 1" default items {"75/65"} without multiple selections allowed) as string
			set Flow1 to characters 1 thru 2 of Emission1 as string
			set Return1 to characters 4 thru 5 of Emission1 as string
		end if
		
		-- selection: 2 emissions
		if item 1 of amountTemperatureNumber is equal to "2" then
			set Emission to (choose from list emissionList with prompt "Select emission 1" default items {"75/65"} without multiple selections allowed) as string
			set Flow1 to characters 1 thru 2 of Emission as string
			set Return1 to characters 4 thru 5 of Emission as string
			
			set emissionList2 to {}
			repeat with x from 1 to count of items of emissionList
				set emissionItem to item x of emissionList
				if emissionItem is not in Emission then set end of emissionList2 to emissionItem
			end repeat
			
			set Emission2 to (choose from list emissionList2 with prompt "Select emission 2" default items {"55/45"} without multiple selections allowed) as string
			set Flow2 to characters 1 thru 2 of Emission2 as string
			set Return2 to characters 4 thru 5 of Emission2 as string
		end if
		
		--selection: 3 emissions
		if item 1 of amountTemperatureNumber is equal to "3" then
			set Emission to (choose from list emissionList with prompt "Select emission 1" default items {"75/65"} without multiple selections allowed) as string
			set Flow1 to characters 1 thru 2 of Emission as string
			set Return1 to characters 4 thru 5 of Emission as string
			
			set emissionList2 to {}
			repeat with x from 1 to count of items of emissionList
				set emissionItem to item x of emissionList
				if emissionItem is not in Emission then set end of emissionList2 to emissionItem
			end repeat
			
			set Emission2 to (choose from list emissionList2 with prompt "Select emission 2" default items {"55/45"} without multiple selections allowed) as string
			set Flow2 to characters 1 thru 2 of Emission2 as string
			set Return2 to characters 4 thru 5 of Emission2 as string
			
			set emissionList3 to {}
			repeat with z from 1 to count of items of emissionList2
				set emissionItem to item z of emissionList2
				if emissionItem is not in Emission2 then set end of emissionList3 to emissionItem
			end repeat
			
			set Emission3 to (choose from list emissionList3 with prompt "Select emission 3" default items {"45/40"} without multiple selections allowed) as string
			set Flow3 to characters 1 thru 2 of Emission3 as string
			set Return3 to characters 4 thru 5 of Emission3 as string
		end if
		
		
		--selection: 4 emissions
		if item 1 of amountTemperatureNumber is equal to "4" then
			set Emission to (choose from list emissionList with prompt "Select emission 1" default items {"75/65"} without multiple selections allowed) as string
			set Flow1 to characters 1 thru 2 of Emission as string
			set Return1 to characters 4 thru 5 of Emission as string
			
			set emissionList2 to {}
			repeat with x from 1 to count of items of emissionList
				set emissionItem to item x of emissionList
				if emissionItem is not in Emission then set end of emissionList2 to emissionItem
			end repeat
			
			set Emission2 to (choose from list emissionList2 with prompt "Select emission 2" default items {"55/45"} without multiple selections allowed) as string
			set Flow2 to characters 1 thru 2 of Emission2 as string
			set Return2 to characters 4 thru 5 of Emission2 as string
			
			set emissionList3 to {}
			repeat with z from 1 to count of items of emissionList2
				set emissionItem to item z of emissionList2
				if emissionItem is not in Emission2 then set end of emissionList3 to emissionItem
			end repeat
			
			set Emission3 to (choose from list emissionList3 with prompt "Select emission 3" default items {"45/40"} without multiple selections allowed) as string
			set Flow3 to characters 1 thru 2 of Emission3 as string
			set Return3 to characters 4 thru 5 of Emission3 as string
			
			set emissionList4 to {}
			repeat with p from 1 to count of items of emissionList3
				set emissionItem to item p of emissionList3
				if emissionItem is not in Emission3 then set end of emissionList4 to emissionItem
			end repeat
			
			set Emission4 to (choose from list emissionList4 with prompt "Select emission 4" default items {"35/30"} without multiple selections allowed) as string
			set Flow4 to characters 1 thru 2 of Emission4 as string
			set Return4 to characters 4 thru 5 of Emission4 as string
		end if
		
	end tell

Here is my example of a repeat version.
I took it out of the tell block for testing.
There were no commands in there that the ‘tell Application “Adobe InDesign CC 2018”’ was needed.


-- set amountTemperature to {"1", "2", "3", "4"} -- not needed since only used once
set emissionList to {"75/65", "65/55", "55/45", "45/40", "45/38", "38/33", "35/30"}
set amountTemperatureNumber to choose from list {"1", "2", "3", "4"} with prompt "How many emissions do you want to calculate?" default items {"3"} OK button name "Update document"
if amountTemperatureNumber is false then return

set emission to {} -- emission1 is now item 1 of emission, emission2 is item 2 of emission, etc...
set Flow to {} -- Flow1 is now item 1 of Flow, Flow2 is item 2 of Flow, etc...
set Returns to {} -- naming this variable return is a bad idea (i added an s so as not to conflict with the "return" command)
repeat with i from 1 to amountTemperatureNumber
	set end of emission to item 1 of (choose from list emissionList with prompt ("Select emission " & i) default items {item i of emissionList}) -- "without multiple selections allowed" not needed
	set text item delimiters to "/"
	set end of Flow to text item 1 of item i of emission
	set end of Returns to text item 2 of item i of emission
	set text item delimiters to return -- used to get offset of an item in a list
	set itemOffset to count of paragraphs of (text 1 thru ((offset of (item i of emission) in (emissionList as text)) + 4) of (emissionList as text))
	if itemOffset = 1 then
		set emissionList to items 2 thru -1 of emissionList
	else if itemOffset = (count of emissionList) then
		set emissionList to items 1 thru -2 of emissionList
	else
		set emissionList to items 1 thru (itemOffset - 1) of emissionList & items (itemOffset + 1) thru -1 of emissionList
	end if
end repeat

Many thanks!!!