caskal Posted September 30, 2021 Share Posted September 30, 2021 Hi Magicians, I'm using some TOPs PDG to autogenerate stuff with data conmig from a CSV spreadsheet. I had the system working by having something like this: Where I used the "Hats_Type_Switch" to drive a Switch node (with Platinium / Gold / Brown) But the client is giving me a different format: I have imported this as CSV and I can read the attributes, I did a "Font" test with attribute "Mouth" that gives me the result "Carrot" My question is, how can I drive that switch with the attribute Mouth instead of 1, 2, 3? For example, if the attribute result for Mouth is Carrot, show the carrot, if the Mouth = Pipe, switch to Pipe Thanks! Quote Link to comment Share on other sites More sharing options...
Fenolis Posted October 1, 2021 Share Posted October 1, 2021 If only VEX had a switch() function that let you go case by case... You can implement your own, example here. The idea is to set up an enumerator (which is kind of like using integers anyway) that compares an input to a kind of key-value in a dictionary. Depending on which value is matched, a different output can be chosen, and a default for if no match is found. I'd still recommend converting/outputting integers as it's probably faster than comparing string values, and the Switch works with ints anyway. One thing to note is that the Switch SOP doesn't know what its inputs are, only that they are ordered by input index. It also has no way of ensuring that inputs are unique, so if you accidentally plugged 2 Carrots into it, it wouldn't be able to tell which one you wanted. Best to just stick with ints, imo. 1 Quote Link to comment Share on other sites More sharing options...
caskal Posted October 1, 2021 Author Share Posted October 1, 2021 Hey @Fenolis! thanks for the info. I made some progress but still trying to figure out something. I made this on a Wrangle to convert the attributes to interger: i@SwitchVal = 0; if(s@mouth == "Empty") @SwitchVal = 0; if(s@mouth == "Carrot") @SwitchVal = 1; if(s@mouth == "Pipe") @SwitchVal = 2; This works, but only if I set the attributes on SOPs. And I have the attributes coming from TOPs Not sure why the wrangle doens't look it, but when I put 'Mouth' on a Font node, it actually returns the value 'Pipe' on the viewport. Lets say I fix the issue on the wrangle and I can call the attribute from TOPs, next thing I'm trying is to use it on a switch node. point("../SWITCH_VAL/", @ptnum, "SwitchVal", 0) But this also don't work, @ptnum is giving me an error, if I use 1 or 2, it works, but I cant access that attribute number I set on the wrangle for some reason. Any thoughts? Thanks! CC Grandpa @f1480187 Quote Link to comment Share on other sites More sharing options...
Atom Posted October 1, 2021 Share Posted October 1, 2021 (edited) It depends upon what you're wedging over. If you are wedging over points, in a 1:1 ratio, you might be able to replace @ptnum with the back ticked variable `@pdg_index`. Or place your switched network inside a FOR/EACH running over points, then you can replace @ptnum with the constant 0. Edited October 1, 2021 by Atom 1 Quote Link to comment Share on other sites More sharing options...
caskal Posted October 1, 2021 Author Share Posted October 1, 2021 Hey @Atom Here's a sample pic ilustrating what I have to do, basically creating characters with accesories, with info coming from a CSV spreadsheet. I made it work when I did a test creating a cel with intergers for the switchs, but the client spreadsheet will be tricky since it has a 10k output with random order. Maybe worst case scenario, I can do a new excel with > Replace word > and do a "Carrot" gets replaced by "1" and I use that for the Switch interger selector. But would love to solve this without that manual work. Thanks! Quote Link to comment Share on other sites More sharing options...
Atom Posted October 1, 2021 Share Posted October 1, 2021 (edited) Can't you just write an IF statement inside a wrangle that generates a companion index for each expected variation? if (s@column_variation=="Carrot"){i@variation_index = 0;} if (s@column_variation=="Pipe"){i@variation_index = 1;} Quote Glasses, Red, Tiger, Sail, Carrot Glasses_Gold, Black, Disco, Golden, Pipe Here is a simple shelf tool that will read the data posted above, examine the forth column, analyze it for expected matches and generate a companion index. It will write the extended CSV file back to disk. csv_source_file = r"S:\Houdini_Scenes\temp_data_csv.csv" csv_target_file = r"S:\Houdini_Scenes\temp_data_csv_EXTENDED.csv" # Read the original source file. with open(csv_source_file, 'r') as f: lines = f.read().splitlines(True) # Remove slash n character at the end of each line. f.close() new_lines = [] for line in lines: ary = line.split(",") index = -1 #Unknown index default. # Extend this if list as needed. if ary[4].strip()=="Carrot": index = 0 if ary[4].strip()=="Pipe": index = 1 new_lines.append("%s,%s" % (line.strip(),index)) #Write the new extended CSV file. f = open(csv_target_file, 'w') for line in new_lines: f.write("%s\n" % line) f.close() Quote Glasses, Red, Tiger, Sail, Carrot,0 Glasses_Gold, Black, Disco, Golden, Pipe,1 You could supply the newly generated CSV to the TableImport node to fetch the fifth column associated switch index value for each line. Edited October 1, 2021 by Atom 1 Quote Link to comment Share on other sites More sharing options...
caskal Posted October 2, 2021 Author Share Posted October 2, 2021 Hey @Atom Thanks for the script! Wish I knew Phyton! Not sure if I'm doing something wrong, but I get this error: I'm using this: I tried changing if ary[4].strip()=="Carrot": index = 0 to this if ary[8].strip()=="Carrot": index = 0 since is on the column 8 but not sure if this is correct. Another question, trying to figure this PDG stuff, why when I call '@Mouth' on a "Font" it returns properly "Carrot" But I can't call it in a wrangle? If I could call s@Mouth in a wrangle and convert to 0, 1 like you said with: if (s@Mouth=="Carrot"){i@variation_index = 0;} if (s@Mouth=="Pipe"){i@variation_index = 1;} and then figure out the point hscript in a switch, that would be amazing, but I can't either call s@mouth to get an interger, and make the point(../path, value, attrib) work. Thanks! Quote Link to comment Share on other sites More sharing options...
caskal Posted October 2, 2021 Author Share Posted October 2, 2021 Got the data on SOPs working! yeah!, dropped this on a Wrangle (had to be in detail) s@Mouth = chs("value"); if (s@Mouth=="Pipe"){i@variation_index = 0;} if (s@Mouth=="Carrot"){i@variation_index = 1;} Next step, call that wrangle variation index in the switch! Thanks! Quote Link to comment Share on other sites More sharing options...
caskal Posted October 2, 2021 Author Share Posted October 2, 2021 YES!!!!!!!!!!!!!!!!!!!!! 1 Quote Link to comment Share on other sites More sharing options...
Atom Posted October 2, 2021 Share Posted October 2, 2021 The index is out of range because arrays are zero based. For the 8th column used the 7th index. ary[7]. 1 Quote Link to comment Share on other sites More sharing options...
caskal Posted October 2, 2021 Author Share Posted October 2, 2021 4 hours ago, Atom said: The index is out of range because arrays are zero based. For the 8th column used the 7th index. ary[7]. Ah stupid me, works now, million thanks sensei @Atom! Quote Link to comment Share on other sites More sharing options...
caskal Posted October 2, 2021 Author Share Posted October 2, 2021 Last question @Atom Got the extended CSV from your script working on tableimport. How can I drop those values in a switch? or use them to pick different geo? Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.