Jump to content

Change HDA file version with Python


kiryha

Recommended Posts

you can set it using 

hou.HDADefinition.setIsPreferred()

to get the list of all installed definitions for certain type do 

hou.NodeType.allInstalledDefinitions()

so overall you would do something like this:

import hou
node = hou.node('/obj/path/to/my/node')
type = node.type()
defs = type.allInstalledDefinitions()
# and then set whichever one you want
defs[1].setIsPreferred(True)

obviously you can use the list of definitions to find desired path in there by library path and if found then set it as preferred, or whatever you plan the logic to be

  • Like 1
Link to comment
Share on other sites

that all being said, you need to think twice if this is the workflow you want

all nodes of the same type are sourced only from your preferred library per hip file

so if you change the path to the type definition, it will switch this to all the nodes of that type (as they all share the same definition)

this can be dangerous and is not suitable for versioning tools that you want to keep multiple versions of in the same hip file

however it can be beneficial for the utility tools that you want to keep up to date all the time and don't really care that they may break backward compatibility (as it will change all existing nodes to preferred definition)

 

on the other hand, versioning by namespacing the type, will allow you to have multiple versions in the same hip file and even if you open the old scene with an older type it will be intact, so it's much safer workflow for that

Link to comment
Share on other sites

@anim
Thanks, Thomas, that's what I was looking for initially!
How can I get data from "defs" object? It is a list of other objects, containing strings paths, but can`t get string paths themselves (as well as their indexes)...

And now I am thinking about my workflow...

Currently, I use HDAs to transfer data between Houdini scenes, e.g. load environment asset into the render scene. Environment HDA itself is a simple container where all geometry caches of environment loaded and merged together (with some UI controls to switch something on or off etc). So I don't need multiple asset version in one scene, there should be only one asset of a particular type in one scene. If it`s a wrong (or wired) workflow for such task (data transfer, eg scene referencing) at this point, what alternatives do I have?

Namespace versioning option has one issue: all asset versions are stored in the same file. And If an asset is big enough (which is easy could be a case for assets like environment) it will multiply file size for each asset version and sooner or later file can become unusable.

Link to comment
Share on other sites

1 hour ago, kiryha said:

How can I get data from "defs" object? It is a list of other objects, containing strings paths, but can`t get string paths themselves (as well as their indexes)...

just extract the info you need to another list for example

defpaths = [d.libraryFilePath() for d in defs]

indices will match, so you can use index() method from python list object to get index of a specific path if you want and then use that to get definition from def list

or you can build dictionary directly

defdict = {d.libraryFilePath(): d for d in defs}

and then just get the definition based on the path key and set it to preferred if found

 

 

 

1 hour ago, kiryha said:

Namespace versioning option has one issue: all asset versions are stored in the same file. And If an asset is big enough (which is easy could be a case for assets like environment) it will multiply file size for each asset version and sooner or later file can become unusable.

you can have namespace versioned assets and still save each of them to different library

so you can have 1 library file per type definition if you want and since each type will be versioned, you can just change your node type and it will use it's preferred definition which is the only definition it has, so there will be need to change preferred definition

overall just try to get a good understanding of what namespaced type is, how it ties to definition and how definitions tie to libraries, then you can pick the workflow that suits your needs  

 

Edited by anim
  • Like 1
Link to comment
Share on other sites

Ok, now I understand that I need to learn way more about HDA... Is there any good explanation (tutorial, masterclass) which covers related topics?

Cos this is quite confusing for me:

1 hour ago, anim said:

what namespaced type is, how it ties to definition and how definitions tie to libraries

 

Edited by kiryha
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...