Save USD to external Nucleus from Python

Hi,

this is related to How can I write a file to nucleus?

I am trying to write to Nucleus using omni.client.write_file() (seehttps://docs.omniverse.nvidia.com/kit/docs/client_library/latest/docs/python.html). I want to do this from within the Omniverse Kit Docker container. I have only enabled one extension: omni.client.

This is the code:

from omni.client import write_file
from pxr import Usd, UsdGeom
import os
stage = Usd.Stage.CreateNew("/tmp/nucleus_test.usda")
xformPrim = UsdGeom.Xform.Define(stage, "/hello")
spherePrim = UsdGeom.Sphere.Define(stage, "/hello/world")
stage.Save()
with open("/tmp/nucleus_test.usda", "rb") as in_file:
    buffer = in_file.read()
    write_file("omniverse://nucleus.dsdlab.db.de:443/Users/brunovetter/kit_test/nucleus_test.usda", buffer)

This is what happens:

The container complains that xdg-open is not available (does write_file really use xdg-open??). So I install it into the container. Now I get this message:

/usr/bin/xdg-open: 851: /usr/bin/xdg-open: www-browser: not found
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: links2: not found
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: elinks: not found
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: links: not found
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: lynx: not found
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: w3m: not found
xdg-open: no method available for opening 'https://nucleus.dsdlab.db.de:443/omni/auth/login/?server=nucleus.dsdlab.db.de&nonce=e367590e9204432592bc7b02d252d5c565bd1cd494ad471d8426a3004095fa16'

Also, how can I set the Nucleus credentials when using write_file?

Thanks a lot
Bruno

Hi Bruno. I moved this to the Nucleus forum.

I think I have found a solution.

Firstly, it seems I can write a USD file to Nucleus using pxr.Usd.Stage.Save(). I was not aware of this, because my idea was that the Pixar USD library should not know how to save to a filename starting with “omniverse://”, but it is actually possible.

The xdg-open messages only come when there is no authenticated user, so Omniverse tries to open a web dialog for authentication. When I set OMNI_USER and OMNI_PASS, this does not happen.

This is the correct steps you should follow.

@bruno.vetter For those of us playing along at home, could you post an example of the code you got working? I’m looking in to saving USD files on the Nucleus server as well but I’ve noticed that Usd.Stage.CreateNew(usd_file_name) is what creates the file. I’d like to avoid creating a file in one place and then saving a second file in another place. Do you specify the nucleus server in the path on CreateNew or do you do that in pxr.Usd.Stage.Save()?

@archer-kgraves I specify the nucleus server in the CreateNew command like omniverse://servername/…

As far as I know Stage.Save() will save the stage in the same place. Optionally you could create a stage in memory and then use Export to save it in an arbitrary place.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.