Trying to set up an interface for a user.
On the parameter interface I have:
1) a parameter set up to retrieve a directory, example:
D:/MEGASCANS_LIBRARY/Downloaded/surface/ground_forest_vlzjadflw/
2) A multi string python expression that strips everything but the last phrase: vlzjadflw, it is a function that can be called via kwargs.
import hou
import os
def strip_dir_call(node):
# Get the current node
node = hou.pwd()
# Get the parameter (channel) object
parm = node.parm("mat_2_dir")
# Get the value of the parameter
value = parm.eval() if parm is not None else ""
# Extract the last folder name from the evaluated value
last_folder = os.path.basename(os.path.normpath(value))
# Split the last folder by underscore and get the last segment
last_phrase = last_folder.split('_')
# Print the last phrase
print(last_phrase)
# Call the function
strip_dir_call(kwargs)
3) This expression is being called on by another parameter celled execute, which is a simple toggle. When I look at the python console I can see the result that I am hoping for.
vlzjadflw
vlzjadflw
vlzjadflw
The issue is, I want to use this returned value elswhere, ideally as a relative reference in a file name path in a separate node. I'm not finding a logical way to do this last step though. H
Any help would be appreciated. Thank you!
Strip file path, return result as referenceable expression
287 1 1- jtk700cln
- Member
- 59 posts
- Joined: Jan. 2016
- Offline
- jtk700cln
- Member
- 59 posts
- Joined: Jan. 2016
- Offline
So I figured it out--
I made some changes to the pythons script:
the mains script now saves the value result as a new string parameter
i have this script running as a callback script whenever the user changes the file directory.
The file directory gets stripped. The result is added as the new string value for a parameter, and I can then copy and paste this as a reference where needed!
Woot!
I made some changes to the pythons script:
the mains script now saves the value result as a new string parameter
i have this script running as a callback script whenever the user changes the file directory.
The file directory gets stripped. The result is added as the new string value for a parameter, and I can then copy and paste this as a reference where needed!
Woot!
-
- Quick Links