BWoods Posted August 17, 2021 Share Posted August 17, 2021 Hey, bit of a specific use case here, but has anyone successfully used the .asCode() Python function with the SOP solver? I can't seem to get it to save and recreate the nodes inside of the sop level solver node. I spent some time researching it but haven't found anyone even mentioning this problem. Everything else seems to work fine with the function even the DOP level SOP solver. It's just the SOP level solver that has this issue. I'm kind of at my wit's end trying to figure this out. I might be missing something super simple or obvious here, but I'm hoping someone else has encountered this and figured out what is happening. I suppose it could also be a bug, I haven't taken the time to dig through all the change logs on the SideFX website. I'm currently encountering this in Houdini 18.0.348 (which has known issues with the .asCode() function) as well 18.0.597 (where those issues have supposedly been resolved). If anyone has any insight I'd really appreciate a nudge in the right direction. Cheers, Brandon Quote Link to comment Share on other sites More sharing options...
ikoon Posted August 17, 2021 Share Posted August 17, 2021 Hi Brandon, what code do you use? I tried this and it prints the contents of the sop solver. Important thing is, that the editable part of the sop solver is in the /d/s sub network. I am on version 18.5.408 node = hou.node('/obj/geo1/solver1/d/s') node.asCode(recurse = True, brief = True) Quote Link to comment Share on other sites More sharing options...
BWoods Posted August 17, 2021 Author Share Posted August 17, 2021 (edited) Ahh I see thanks ikoon! This is part of a larger tool that loops over all the contents of a scene for creating templates and/or sharing smaller node networks. Just need to find a way to account for this in the loop somehow. EDIT: I can't share the code for the larger tool but this is the simplified version I was using to test out saving the sop solver. I had a geo object selected at obj level and the geo object had a simple setup with a sop solver transferring @Cd based on distance each frame. import hou import os def save_script(): # Create our script selected = hou.selectedNodes() script = "" for node in selected: script += node.asCode(recurse=True) filepath = "$HIP/test_script.txt" filepath = hou.expandString(filepath) with open(filepath, "w") as output: output.write(script) save_script(); Edited August 17, 2021 by BWoods Adding example Quote Link to comment Share on other sites More sharing options...
BWoods Posted August 21, 2021 Author Share Posted August 21, 2021 Just to update this, I was not able to get ikoons solution working for some reason, but I did figure out why the sop solver wasn't saving correctly with our existing code. As it turns out, the .asCode function will not output script for the creation of nodes inside of locked assets, which the sop solver is. It seems like an obvious answer in retrospect but I still think it is something that should be explicitly stated in the method definition for the hou.Node class. Regardless, the answer is to use the allowEditingOfContents function on your solver before saving it with .asCode and then loop over it after it is recreated and lock it again. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted August 23, 2021 Share Posted August 23, 2021 (edited) I had issues with .asCode in the past not being able to correctly export node contents in full, but hscript opscript -rVG /path/to/operator worked great for me. Edited August 23, 2021 by Stalkerx777 1 Quote Link to comment Share on other sites More sharing options...
BWoods Posted April 20, 2022 Author Share Posted April 20, 2022 Hey Alex, sorry I didn't see your reply back in August. Thank-you for this! I was just revisiting this thread to see if there were any comments that would help me resolve some issues with the previous .asCode() method that I encountered when running our tool on things like the new SOP level pyro solver. The hscript method you posted circumvents the problem nicely! Definitely going to be switching to this going forward! 1 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.