Created
November 23, 2023 16:15
-
-
Save BigRoy/4e3f651c79e2b081ffbc85258d7e0238 to your computer and use it in GitHub Desktop.
USD simple print diff of dirty layer in memory to the original state on disk.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import difflib | |
from pxr import Sdf | |
# Purely as an example, say this `layer` is one that's currently already | |
# available and is dirty currently | |
identifier = r"C:\Users\User\Desktop\asset.usd" | |
layer = Sdf.Layer.FindOrOpen(identifier) | |
layer.Reload() # just so we can re-run this script | |
layer.subLayerPaths.append("./hello_world.usd") # making a change, making it dirty | |
# Now re-open the layer from disk (anonymous, as a copy) | |
# And then do a text-diff between the two | |
layer_as_original = Sdf.Layer.OpenAsAnonymous(identifier) | |
changed_ascii = layer.ExportToString() | |
original_ascii = layer_as_original.ExportToString() | |
# Print diff | |
for line in difflib.unified_diff( | |
original_ascii.splitlines(), | |
changed_ascii.splitlines(), | |
tofile=f"{layer.identifier} (changed)", | |
fromfile=f"{layer.identifier} (on disk)", | |
lineterm="" | |
): | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output to the above script: