How to get material by line trace

Here is a similar question. Hope you find your answer there!