selecting varient based on logic + reading usd primvar broken ?

   438   2   0
User Avatar
Member
193 posts
Joined: 12月 2016
Offline
Hello I`d like to edit variants programatically.


my apttemts are failing.

Vex:

In vex there aren`t even any prints happening
string @primpath; 

// Debugging message for variable definition
printf("Variables defined.");

// Retrieve variants
string models[] = usd_variants(0, @primpath, "model");

// Debugging message to check if variants are retrieved
printf("Number of variants: %d", len(models));

// Check if at least one variant is available
if (len(models) > 0) {
    // Set the desired variant
    usd_setvariantselection(0, @primpath, "model", models[1]);

    // Debugging message for variant selection
    printf("Variant selection set.");

    // Apply API to the variant
    usd_applyapi(0, @primpath, "GeomModelAPI");

    // Debugging message for API application
    printf("API applied.");
} else {
    // Debugging message if no variants are available
    printf("No variants available.");
}




Python:

It seems however that my python script isn`t working.
(ive also tried @TESTING wich didn`t work)

here is my script.

from pxr import UsdGeom

from pxr import UsdGeom

try:
    lopNode = hou.pwd().inputs()[0]
    stage = lopNode.stage()
    print(stage)

    node_base = "/instanced_variants1/Instance"
    variable_value = hou.node(".").parm("primnr").eval()
    node_base += str(variable_value)

    prim = stage.GetPrimAtPath(node_base)
    
    testing = prim.GetAttribute("primvars:TESTING").Get()
    
    
    pvAPI = UsdGeom.PrimvarsAPI(prim)
    primvar = pvAPI.FindPrimvarWithInheritance("TESTING")
    primvarValue = primvar.ComputeFlattened()
    return testing


except Exception as e:

    return 2

it returns 0 indicating that it cant find the attrib
although sometimes its all 2.

I`m at a loss here as it seems like this is a good workflow.
Edited by NicTanghe - 2024年4月26日 06:14:21

Attachments:
Help.hiplc (429.0 KB)
Screenshot from 2024-04-12 12-42-46.png (592.9 KB)

User Avatar
スタッフ
4441 posts
Joined: 7月 2005
Offline
In your VEX LOPs, the problem is that you set it to "run over elements of array", which is a mode used to alter values in array attribute values. Here you don't want that, you want to run the VEX code once per USD primitive, so you should turn off that checkbox. In your python code, the problem is that you are calling Attribute.Get() and primvar.ComputeFlattened() without passing in a UsdTimeCode argument. This causes these function to fetch their "Default" value, which is not set anywhere. All your primvars are time sampled values. You can fix this either by authoring the primvars as default value, or by passing Usd.TimeCode(0.0) to the functions that are pulling out the attribute values.

Also be aware that you are going to be getting back single-value arrays from these functions, so you'll need to index into the array to pull out the actual value of interest.

HTH.
User Avatar
Member
193 posts
Joined: 12月 2016
Offline
Ok, after figuring out how to do it, i c now you hinted at it in your answer.
Edited by NicTanghe - 2024年4月26日 15:30:55

Attachments:
usd_read_primvar.hiplc (437.9 KB)

  • Quick Links