Check to which object its locked

Is there a manner to check if an object is locked to another object?

Why?
I have a recess (an opening in the wall for pipes) and would like to fill a parameter of that recess with the system info of the locked pipe to that recess.