TomRaynor Posted March 19, 2013 Share Posted March 19, 2013 Hi everyone, I have an hda which has a python module inside it that needs to access a '.json' (jscript) file. Basically there is a line of code in my python module that says something along the lines of: BLAH = 'C:\Users\Me\Desktop\blah.json' This string variable then gets passed to a function that does other shit... As is, this works fine, and executes correctly, however I want to have the '.json' file embedded in the extra files section of my otl instead of being loose on my desktop. My question is can anyone help me with the pythonic syntax to access the path to the file within the extra files section of the otl? I currently can't get it to work pick up the file. I have tried things like: BLAH = hou.readFile('opdef:./?client_secrets.json') and BLAH = hou.hscript('opdef:./?client_secrets.json') Either I have got these wrong syntactically or they don't work as I have expected. Any help would be much appreciated! Cheers -T Quote Link to comment Share on other sites More sharing options...
graham Posted March 20, 2013 Share Posted March 20, 2013 I'd access the it using the hou.HDADefintion's sections() method. definition = asset.type().definition() secrets = definition.sections()['client_secrets.json'].contents() The hou.readFile method does work, however it doesn't understand the relative '.' part for the opdef: call. You need to do the full operator name: hou.readFile("opdef:/Sop/something?client_secrets.json") hou.readFile("opdef:/{0}?client_secrets.json".format(asset.type().nameWithCategory())) Quote Link to comment Share on other sites More sharing options...
TomRaynor Posted March 20, 2013 Author Share Posted March 20, 2013 Hey Graham, Thanks for the reply, that is really great stuff. However I believe that the python method that I am using requires the path to the '.json' file rather than the actual contents of it to work... I believe this is why it worked when I used the explicit path: BLAH = 'C:\Users\Me\Desktop\blah.json' Is it possible to get some sort of path to the extra file within the otl so that I can feed it into this method? Thanks again! Quote Link to comment Share on other sites More sharing options...
graham Posted March 20, 2013 Share Posted March 20, 2013 I don't believe so. What module/method are you using with the file path? Quote Link to comment Share on other sites More sharing options...
TomRaynor Posted March 20, 2013 Author Share Posted March 20, 2013 (edited) I am working on a project where I access website data using the google AP. It is a method called: flow_from_clientsecrets() For which the docs can be found here: https://developers.g...m_clientsecrets Any thoughts? Edited March 20, 2013 by TomRaynor Quote Link to comment Share on other sites More sharing options...
TomRaynor Posted March 20, 2013 Author Share Posted March 20, 2013 Whilst you ponder on that one, I have a couple of another questions I was meaning to ask... It seems you can only have one "pythonModule" in the scripts section of your otl. Is this true or can we access and run multiple python modules from this location? If I have some extra python files in either the scripts section of my otl or the extra files section of my otl, is it possible for me to import those modules into the "pythonModule" within my scripts directory so that I can have access to the code contained within them? Cheers! Quote Link to comment Share on other sites More sharing options...
graham Posted March 20, 2013 Share Posted March 20, 2013 Not really. I suspect you'll have to come up with some sort of intermediate copy of the file that gets written out on load or something so that the API call can handle it. Quote Link to comment Share on other sites More sharing options...
graham Posted March 20, 2013 Share Posted March 20, 2013 You can store and access additional Python module sections like this http://www.sidefx.com/docs/houdini12.5/hom/assetscripts#multiple_python_modules Quote Link to comment Share on other sites More sharing options...
TomRaynor Posted March 21, 2013 Author Share Posted March 21, 2013 Great, thanks for all the info Graham. Much appreciated! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.