> [!abstract] Summary
> **Derive a material name (or group) from a USD `@path` attribute** — split the path on `/`, take the last segment, then split that on `_` and take the second-to-last token. Used to automatically read a per-prim "material name" embedded in the geometry path.
---
# The Snippet
**Attribute Wrangle** — Run Over: **Primitives**.
```c
// Derive a material name from the last segment of @path,
// splitting on "_" and taking the second-to-last token.
// Example: /scene/asset/spaceMarine_metal_blueArmor_MAT
// → segments split by "/", last = "spaceMarine_metal_blueArmor_MAT"
// → split by "_" → ["spaceMarine","metal","blueArmor","MAT"]
// → [-2] = "blueArmor"
s@description = split(split(s@path, "/")[-1], "_")[-2];
```
## Step-by-step
| Step | What it does |
|---|---|
| `split(s@path, "/")` | Split the full USD path into segments. |
| `[-1]` | Take the **last** segment (the prim name). |
| `split(..., "_")` | Split that segment by underscore. |
| `[-2]` | Take the **second-to-last** token (typically the material identifier in the OSMIUM naming convention). |
| `s@description` | Store the result in a string attribute for downstream use. |
---
# Visuals
![[2. M.O.R.P.H.E.U.S/Blue Pills/3D/SOFTWARES/Attachments/6.122 HOUDINI Wrangle/image-20230315.png]]
![[image-20230315 1.png]]
## Creating Material from the Attribute
![[image-20230315 2.png]]
Once you have `s@description`, drive a **Material Library** assign-by-attribute, or feed it into a switch / loop that creates the right shader per prim.
---
# 🔗 Related
- [[HOUDINI VEX|HOUDINI VEX]] — VEX hub.
- [[VEX Assign Material to Instances|Assign Material to Instances]] — companion snippet for LOPs.
- [[../../../PROTOCOL/FOUNDATION/PROTOCOL Naming Convention|PROTOCOL Naming Convention]] — why the path encodes the material name.