Thanks for the replies so far. lol… I tried to simplify my problem by making a fake example, but I guess that was not helpful. Preferably I would like to use Python (my existing code is attached. I’m very new to Python, so go easy on me!) or out of the box nodes.
Explanations…
Bom List - This is a simple list of unique product types
Mat List - This is a list with product types, task numbers, ship to code, job number, etc
(For the first part of the script, I need to go through the Bom list 1 item at a time, and if the product type in the bom list matches the product type in the mat list, pull ship to code (index 5 of mat list) and task number (index 4 of mat list) from that sublist. The other values in the mat list, I don’t care about)
Main List - This is the final list I’m working with. I need to insert the two values pulled above (ship to code and task number) back into this list at the same place as it is in the bom list. (Index 0 in the Bom list is list #102 of the Mat List. Pull index 4 and 5 from the Mat List #102 (2355 and SVD) and insert them in list 0 of the Main List) then find the next match, do the same, and so on.
Ship Index (6) - The index in the Main List where I need to insert each ship to code pulled from the Mat list sublists (so in list 0 of the main list, insert 2355 in index 17)
Task Index (17) - The index in the Main List where I need to insert each task number pulled from the Mat list sublists (so in list 0 of the main list, insert SVD (Valders due to the replace in the python code) in index 6)
So for each sub list of the main list, I need to insert the values pulled from the Mat List into index 6 and 17
This is where the Python script is not working as intended, nothing happens and I’m not sure what to put here:
main_list[count][task_index] = task_value
main_list[count][ship_index] = ship_value
From what I’ve read, in Python it’s best to create a new list instead of trying to replace items like I’m attempting to do. But I’m kinda stuck at this point (hence my reaching out to you amazing ppl) and my Python skills are sorely lacking. But I’m trying to get better.
Hopefully that makes sense! I’m not always good at explaining things.
Python Code below.
Amber
Code:
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import the lists and indexes
bom_list = IN[0]
mat_list = IN[1]
main_list = IN[2]
ship_index = IN[3]
task_index = IN[4]
# Loop through bom list
for bom in bom_list:
# Begin counter
count = 0
# Loop through materal list
for mat_bom in mat_list:
# If items match
if bom in mat_bom:
# Get index 4 and 5
task_value = mat_list[count][4]
ship_value = mat_list[count][5]
# Replace ship value (org code)
if ship_value == "SVD":
ship_value = "Valders"
if ship_value == "SCL":
ship_value = "Crystal Lake"
main_list[count][task_index] = task_value
main_list[count][ship_index] = ship_value
# Increase counter by 1
count = count + 1
# DEBUG, uncomment lines below to use
stdsave = sys.stdout
fout = open(r'C:\Users\admin\desktop\output.txt','w')
sys.stdout = fout
print "Count: ",count
print "Task number: ",task_value
print "Ship to: ",ship_value
print "Task index: ",task_index
print "Ship index: ",ship_index
print "BOM: ",bom
sys.stdout = stdsave
fout.close()
# Output
OUT = main_list