Parsing selection strings in Python

   3702   3   0
User Avatar
Member
228 posts
Joined: Dec. 2012
Offline
Hey,

Sorry if this has been asked but I can't find an answer -

I'm writing some Python code inside of a Python SOP and I want to get the current point/prim selection. When querying the sceneViewer to see what primitives or points are selected, the only option I see is to use the function mergedSelectionString(). I then need to convert this into a list of selected prims or points by writing the following code:

def parseSelectionString(str):
# Separate the string at each space
a = str.split(' ')

# Parse the list of strings into list of integers
b = [range(int(x.split('-')), int(x.split('-'))+1) if ‘-’ in x else for x in a]

# Flatten the list
c =
return c

Then I would need to loop through the geo's prims/points and grab the right ones based on this converted list.

This seems archaic. Is there an easier way to do this?
www.kmcnamara.com
User Avatar
Member
1908 posts
Joined: Nov. 2006
Online
Try hou.Geometry.glob(Points/Prims).
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
228 posts
Joined: Dec. 2012
Offline
Perfect, thanks graham.
www.kmcnamara.com
User Avatar
Member
1 posts
Joined: Feb. 2019
Offline
try…Python split string [net-informations.com]
  • Quick Links