If I understood you correctly, this code might help you getting along: http://www.opserver.de/wiki/index.php/Plane-Line_Intersection

You can construct a ray/line through the mouse cursor with mouse_dir3d and mouse_pos3d. The grid acts as a plane. You can then place the cube at the intersection point.