That’s not what’s happening though. None of that deals with studs, so how does the wall width determine which studs are part of that wall? You need to get all stud instances and check to see which wall instances they intersect with. That will tell you the wall type and therefore the wall width.
Again, I’d suggest you search the forum for similar topics that deal with location of elements. You won’t be able to search for your specific case, but there are plenty of discussions on workflows that deal with locating elements in walls or rooms or other “hosts”. You need to do the same kind of analysis to determine your “grouping”.