Jump to content

[Python] .asCode() function and the SOP level solver node


BWoods

Recommended Posts

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

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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 by BWoods
Adding example
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 7 months later...

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!

  • Like 1
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...