Skip to content

show_usdview

ShowInUsdview

Bases: HoudiniLoader

Open USD file in usdview

Source code in client/ayon_houdini/plugins/load/show_usdview.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class ShowInUsdview(plugin.HoudiniLoader):
    """Open USD file in usdview"""

    label = "Show in usdview"
    representations = {"*"}
    product_types = {"*"}
    extensions = {"usd", "usda", "usdlc", "usdnc", "abc"}
    order = 15

    icon = "code-fork"
    color = "white"

    def load(self, context, name=None, namespace=None, data=None):
        from pathlib import Path

        if platform.system() == "Windows":
            if hou.applicationVersion()[0] >= 20:
                executable = "usdview.cmd"
            else:
                executable = "usdview.bat"
        else:
            executable = "usdview"

        usdview = find_executable(executable)
        if not usdview:
            raise RuntimeError("Unable to find usdview")

        # For some reason Windows can return the path like:
        # C:/PROGRA~1/SIDEEF~1/HOUDIN~1.435/bin/usdview
        # convert to resolved path so `subprocess` can take it
        usdview = str(Path(usdview).resolve().as_posix())

        filepath = self.filepath_from_context(context)
        filepath = os.path.normpath(filepath)
        filepath = filepath.replace("\\", "/")

        if not os.path.exists(filepath):
            self.log.error("File does not exist: %s" % filepath)
            return

        self.log.info("Start houdini variant of usdview...")

        subprocess.Popen([usdview, filepath, "--renderer", "GL"])