Manipulate objects in Editor mode via Script

I want to manipulate an object in editor mode via script. For example, i have an object with a cube as snappoint for other objects and some cylinders. So if i select the cube and move it in the scene (movement should be districted to the main axies), the editor script shall measure the distance between 2 cylinders, duplicate the last cylinder, add it to the object and set the position next to the last cylinder by using the distance offset. I want use it to deform objects in the editor via special roles in the script. How can i solve the problem?

How about check ECS?