Scott's trick is a method for constructing a set as a subset of a proper class. Specifically, let $A$ be a class (proper or otherwise), and let $$S(A)=\{x\in A:\forall y\in A,\operatorname{rank}(x)\le\operatorname{rank}(y)\}.$$
Then $S:\overline V\to V$ (where $\overline V$ represents the collection of all classes, a concept that cannot be formalized in ZF) satisfies three important properties: (1) $S(A)\subseteq A$, (2) $S(A)$ is a set, even if $A$ is not, and (3) $S(A)=\emptyset$ iff $A=\emptyset$.
I would like to generalize this construction to produce another function on $\overline V$ which satisfies the same properties, but does not require the Axiom of Regularity. The place where Regularity appears in the standard Scott's trick is in the proof of property (2), because assuming the negation of Regularity, there is a set $z$ with no rank, and a proper class of sets built from this set (say $z, \{z\}, \{\{z\}\}, \dots$ and continued by transfinite recursion), that also have no rank. Under the conventional definition of rank, $\operatorname{rank}(x)=\emptyset$ whenever $x$ has no rank, so if I take $A$ to be the class of sets containing $z$ described above, then all members of $A$ have the same rank, and thus $S(A)=A$ is also a proper class.
My question is if there is any way to construct a similar type of function that works even in such cases. Is it necessary to have a total order on all sets like $\operatorname{rank}$ in order for any such trickery to work? If so, I would guess that there is no way to do it without Regularity.