(1) When an action is commenced to recover the cost and expenses for draining a lode or mine, it is lawful for the plaintiff to apply to the court for an order to inspect and examine the lodes or mines claimed to have been drained by the plaintiff; or someone for him shall make affidavit that such inspection or examination is necessary for a proper preparation of the case for trial. The court shall grant an order for the underground inspection and examination of the lode or mines described in the petition. Such order shall designate the number of persons, not exceeding three, besides the plaintiff or his representative, to examine and inspect such lode and mines and take the measurement thereof, relating the amount of water drained from the lode or mine, or the number of fathoms of ground mined and worked out of the lode or mine claimed to have been drained, and the cost of such examination and inspection to be borne by the party applying therefor.
(2) The court has power to cause the removal of any rock, debris, or other obstacles in any lode or vein, when such removal is shown to be necessary to a just determination of the question involved. No such order for inspection and examination shall be made except in open court or at chambers, upon notice of application for such order of at least three days, and not then except by agreement of the parties, and not unless it appears that the plaintiff has been refused the privilege of making the inspection and examination by the defendant, his or their agent.