Jump to content

string from relative path expression


csp

Recommended Posts

In a tool I have a string parameter where the user should type full path to parameter of any node. I want also to give the option to paste copied relative references and convert that expression to string with the full path. The following callback script does all that but it has as a result the red stripes warning on the node. The warning is: Unable to evalulate expression.

Why is this happening?

How can you avoid this error?

If not, is there another way to get the same result?

# Fix wedge channels and check if valid
def fixchan(parm):
    p = parm.getReferencedParm()
    value = parm.evalAsString()
    if value:
        if p.path() != parm.path():
            parm.setExpression('') # overwrite
            parm.deleteAllKeyframes() # clear parameter
            parm.set(p.path()) # set path tp parm
        else:
            if not p.node().parm(value):
                hou.ui.setStatusMessage('This parameter does not exist. Please check the path again or Paste Copied [Relative] Reference.', severity=hou.severityType.Warning)
                parm.set('')

Cheers,

Link to comment
Share on other sites

Have you looked at the docs?

 

 

Evalutes this parameter at the current frame and returns the result as a string.
 
If you want the string contents of the parameter before variable expansion and expression evaluation then call hou.Parm.unexpandedString.
 
Raises hou.TypeError if the value cannot be converted to a string.
 
Try placing the evalAsString inside a TRY/EXCEPT or unexpand the string as the docs suggest.
 
Edited by Atom
Link to comment
Share on other sites

Replacing value = parm.evalAsString() to value = parm.unexpandedString() will not solve the problem, I tried that. Also its hard to trace the error because when I am running the code line by line from Python Shell, will not error.

 

While writing the reply, I think I fixed it. I just change the order of the lines:

parm.deleteAllKeyframes() # clear parameter
parm.set(p.path()) # set path tp parm

to:

parm.set(p.path()) # set path tp parm
parm.deleteAllKeyframes() # clear parameter
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...