Jump to content

Install HDA from python module


saml

Recommended Posts

Hi,

I am developing a python script and have come across an issue with the hou.hda.installFile() module and I am wondering if anyone can shed some light on how I can resolve it. The following are two scenarios, one which works and the second which calls an exception and fails unfortunately I need the second one to work :(

==Scenario 1==

The following was executed in the python shell within houdini and works with no issues:

>>> path = "C:/Documents and Settings/Administrator/My Documents/RSL/rel/watermelon.otl"

>>> hou.hda.installFile(path)

==Scenario 2==

This is a snippet of the code I have used in my python module which I have imported into and run in houdini:

path = re.sub(r'\\', r'/', "\"" + self.shaderDir + '\\' + stringSelection.rstrip('slo') + 'otl' + "\"")

print path

hou.hda.installFile(path)

The path output in the console from the print command appears exactly the same as the first scenario

"C:/Documents and Settings/Administrator/My Documents/RSL/rel/watermelon.otl"

however, fails with the following exception appearing in the houdini console:

Traceback (most recent call last):

File "C:/DOCUME~1/ADMINI~1/MYDOCU~1/houdini9.5/scripts/python\hrsl.py", line 136, in OnImport

hou.hda.installFile(path)

File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.169/houdini/scripts/python\hou.py", line 11004, in installFile

return _hou.hda_installFile(*args)

TypeError: in method 'hda_installFile', argument 2 of type 'char const *'

When I substitute the "path = re.sub..." attribute with a direct path to the otl it works successfully even though the string appears exactly the same in the print statement of the path. It seems there is an issue with the type of attribute being generated but I am unaware of the best approach to solve this.

Any help would be much appreciated!!

Sam.

Link to comment
Share on other sites

Hi,

I am developing a python script and have come across an issue with the hou.hda.installFile() module and I am wondering if anyone can shed some light on how I can resolve it. The following are two scenarios, one which works and the second which calls an exception and fails unfortunately I need the second one to work :(

(...)

Any help would be much appreciated!!

Sam.

Did you try your path with os.path.isfile() call? It will check if system can see your file despite of Houdini. Another thing you might consider is using os.path.join() which will create a *correct system path from various chunks like: "c:\", "Documents and Settings//user", "houdini9.5/otls", "myfile.otl". Very convieniet.

The problem seems to be that your string created by regular expression consists with extra " " quotes around so path starts with "..., which is not a correct path for Python I think.

Edited by SYmek
Link to comment
Share on other sites

Thanks for the speedy reply SYmek!

I hadn't thought to use those os module commands too, they are very useful. When testing isfile against the path it returned a false boolean. I got rid of the extra quotes and isfile now returns a True result, but the same initial error arises, so there must still be an underlying problem with the path string...

Code:

path = os.path.join(self.shaderDir, stringSelection.rstrip('slo') + "otl")

path = re.sub(r'\\', r'/', path)

print "Path: " + path

print os.path.isfile(path)

##TEST##

explicitPath = "C:/Documents and Settings/Administrator/My Documents/RSL/rel/watermelon.otl"

print "Path: " + explicitPath

print os.path.isfile(explicitPath)

Output:

Path: C:/Documents and Settings/Administrator/My Documents/RSL/rel/watermelon.otl

True

Path: C:/Documents and Settings/Administrator/My Documents/RSL/rel/watermelon.otl

True

As a test I tried to force the path to be a string using:

path = "".join("%s" % path)

This still resulted in the same initial error. Maybe there is some kind of other string conversion I need to do? Thanks again for your direction.

Link to comment
Share on other sites

Thanks again for the assistance! I have now resolved the problem. Although the strings both appeared to be identical yet only the explicitly defined string worked with the hou.hda.installFile() method, using the type() function on the path variable I discovered it was of <type 'unicode'>.

I converted the path variable to a string using the path = str(path) command and now it executes successfully!

Cheers,

Sam.

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...