Wedge: Accessing string array items from string parameter

   521   6   1
User Avatar
Member
591 posts
Joined: Aug. 2014
Offline
Hello,
In the Wedge TOP (and other TOPs in general), what's the correct syntax for accessing a specific item from a string array attribute, in order to assign it to a new string attribute created by the Wedge?

I tried:
`P@my_str_array[@wedgeindex]`



But this generates warnings about missing @mand @yattributes (it treats first letters of my_str_arrayas attributes for some reason). The result is an empty attribute (object_namein this case) for each Work Item.

The following expressions do work, but they're static, while I need the index to change depending on current @wedgeindex.
`P@my_str_array.x`
`P@my_str_array.y`
(...)
`P@my_str_array.0`
`P@my_str_array.1`
(...)
Edited by ajz3d - Jan. 15, 2025 14:17:13

Attachments:
wedge_top_string.png (34.6 KB)

User Avatar
Staff
607 posts
Joined: May 2014
Offline
Array brackets don't work like that for PDG attributes. You should use the function version instead so you can pass in the index: https://www.sidefx.com/docs/houdini/expressions/pdgattrib.html [www.sidefx.com]
User Avatar
Member
591 posts
Joined: Aug. 2014
Offline
Thanks, @tpetrick.

Now I'm getting Unable to cast attribute '@my_str_arr' to a numeric valuewarnings. As a result, Wedge puts 0 into the new attribute (object_nameon screenshot) for each Work Item. Even though my_str_arris an array of strings.

Here's what I tried:

`pdgattrib("my_str_arr", @wedgeindex)`
`pdgattrib("my_str_arr", 0)`
`pdgattrib("my_str_arr", pdgattrib("wedgeindex", 0))`
User Avatar
Staff
607 posts
Joined: May 2014
Offline
Can you attach a .hip file?
User Avatar
Member
591 posts
Joined: Aug. 2014
Offline
Absolutely. Here it is.

Attachments:
tops_str_array.hiplc.tar.gz (267.4 KB)

User Avatar
Staff
607 posts
Joined: May 2014
Offline
If your attribute is a string, you need to use pdgattribs with an 's' on the end. The one without an 's' expects to retrieve the value of a numeric attribute.
User Avatar
Member
591 posts
Joined: Aug. 2014
Offline
Perfect! Many thanks for your help.
For some reason I assumed it was an overloaded function.
  • Quick Links