Sofia Vergara's ex Nick Loeb on Monday lost his final appeal in Los Angeles to gaining custody of frozen pre-embryos the former couple created while they dated.

Vergara, 48, and Loeb, 45, ended their engagement in 2014 after undergoing in vitro fertilization. They have been locked in a court battle over the embryos for years. In 2017, the "Modern Family" alum filed court documents to block Loeb from having access to the embryos without her written consent.

Last month, a judge ruled in Vergara's favor by granting a permanent injunction, which blocks Loeb from creating a child "without the explicit written permission of the other person." The judge also sided with Vergara over the "Form Directive" the exes signed at a fertility clinic. The directive stipulated that the two have to agree on matters involving the embryos.

In a filing obtained by Fox News, the judge on Monday ruled against Loeb's challenges to the Form Directive.

SOFIA VERGARA’S EX NICK LOEB CANNOT USE EMBRYOS WITHOUT HER CONSENT, JUDGE RULES

Sofia Vergara has successfully blocked her pre-embryos from being used without her written consent. 

Sofia Vergara has successfully blocked her pre-embryos from being used without her written consent.  (Stefanie Keenan/Getty Images for Hammer Museum)

"In accordance with the express terms of the Form Directive, any unilateral action undertaken by Loeb that seeks to cause the implantation of the Embryos in a surrogate, or by other means of gestation, constitutes a violation of the Form Directive," the docs state.

Furthermore, the judge ruled that Loeb's past defense of being under "duress" when he signed the Form Directive "is not void or voidable."

The judge's injunctive relief also rules that Loeb is prohibited from using the embryos or suing on behalf of them. Vergara's ex-fiance was also found to have "materially breached" the Form Directive by setting up a trust for the embryos under Louisiana law, suing on behalf of the embryos, and attempting to create juridical persons from the embryos, the judge states, among other examples.

CLICK HERE TO SIGN UP FOR OUR ENTERTAINMENT NEWSLETTER

Attorneys for Loeb and Vergara did not immediately respond to Fox News' requests for comment.

Sofia Vergara (left) has won a court battle against her ex, Nick Loeb (right), over frozen pre-embryos made by the two before their split.

Sofia Vergara (left) has won a court battle against her ex, Nick Loeb (right), over frozen pre-embryos made by the two before their split. (Getty Images)

Last month, however, Loeb accused the judge of being influenced by Hollywood following the outcome in Vergara's favor.

"The judge was clearly influenced by Hollywood, which is a pattern I expose in my upcoming film Roe v. Wade on April 2nd," Loeb said in a statement to Fox News. "It’s sad that Sofia, a devout Catholic, would intentionally create babies just to kill them."

CLICK HERE TO GET THE FOX NEWS APP

Loeb's case in Louisana court was dismissed in January.

Vergara is now married to actor Joe Manganiello, whom she wed in late 2015. She has a 28-year-old son, Manolo, from a previous relationship.