Hello. I still suck at coding so I hope some kind blenderhead soul will help me. ![]()
I have a lot of xml files with code. Each xml file contains 900 classes for each NPC, basically it’s list of different values. I need to replace only few specific values in each class with some values from predefined list. Sounds not that complex but I still stuck.
I’ve tried Notepad++ with ToolBucket addon using regex to find lines in the code I need to replace while keeping other values untouched. I used (.+) regex function to find values as groups and ($1), ($2), ($3) etc. function to leave original values in groups untouched. And those values I need to replace I just replaced with specific value. This took a lot of time to understand how this all is working.
And it worked, but problem is that I need to replace value not with certain number but randomly from the list of values! Which seems is impossible to do with Notepad find\replace tool. So, I had weird idea, maybe python script could help me with that? Because manually replace 900 items in 32 files is crazy.
So here is example of text I need to find and replace:
<u8 name="mRomPawnJob" value="1"/>
<s16 name="mRomPawnAiNo" value="989"/>
<s16 name="mRomPawnCharaNo" value="515"/>
So I need python script to search string u8 name=“mRomPawnJob” value=“1” and replace only value in a third string - u8 name=“mRomPawnNameNo” value=“515” with random value from the list like (464, 774, 974, 752). I want all NPCs with “mRomPawnJob” = 1 randomly assigned “mRomPawnCharaNo” value from my list.
“mRomPawnJob” and “mRomPawnAiNo” should stay untouched.
So I wonder if it’s possible to find\replace these values in xml file using python script through blender?