You’ll also need to take into account each post’s bounding box so you can size the cylinders accordingly.
HOWEVER… the tricky part you’re both forgetting is… how do you separate the two posts from one another? They both have the same material index.
You could do this using some mesh operators… off the top of my head I think it’s called ‘separate by material index’, then you’d select the resulting object, and do separate by loose parts… THEN you have your blue boxes as nice atomic pieces.
Would be more interesting, but more difficult to accomplish this solely in python… not using any of those silly mesh operators… feels so dirty using them…