Howdy,
I'm editing a tool that is used to create, check out, and publish HDAs and update their contents. Currently the HDA Manager is pleasantly functional, but is running into one small frustrating issue. When Creating a new HDA, the tab submenu is not set correctly. When created, the HDA populates correctly in a tab named "Company Name," however, when I open a new session of Houdini, the HDA moves to the "Digital Assets" tab menu.
I had be working off of a modified version of this kind of code presented here in this forum:
https://www.sidefx.com/forum/topic/85634/?page=1#post-370498 [
www.sidefx.com]
My code at this moment looks something like this:
def createNewHDA(self, name, versionString):
node = self.translator.ensureNode(self.node)
if not name:
baseContainer.BaseContainer().showMessage(
msg="Please enter a name for the HDA and try again"
"\n Enter a name in the HDA Manager field, this will become the name of the created HDA",
title="Notice",
)
return self.translator.ensureNode(node)
cancelPrompt = baseContainer.BaseContainer().askOptions(
question=f"Convert selected subnet to a new Company Name HDA: {name}?"
"\n This will turn your subnet into a studio accessible HDA",
options=(Outcome.ok, Outcome.cancel),
title="Notice",
)
# Allow users to cancel HDA creation just in case
if cancelPrompt is Outcome.cancel:
print("Cancelled HDA creation")
return self.translator.ensureNode(node)
hdaName = self.buildHDAName(name, versionString)
print("created hdaName:", hdaName)
filePath = self.buildHDASavePath(name)
print("built filepath:", filePath)
nativeHDA = self.node.nativeNode().createDigitalAsset(
name=hdaName,
hda_file_name=filePath,
description=None,
min_num_inputs=1,
max_num_inputs=1,
compress_contents=False,
comment=None,
version=versionString,
save_as_embedded=False,
ignore_external_references=False,
change_node_type=True,
create_backup=True,
install_path=None,
)
hdaDef = nativeHDA.type().definition()
hdaDef.setDescription(name)
hdaDef.setIcon(ICON_PATH)
# copy spare parms to the definition
parmTemplate = nativeHDA.parmTemplateGroup()
typeDef = nativeHDA.type().definition()
typeDef.setParmTemplateGroup(parmTemplate)
typeDef.save(filePath)
nativeHDA.matchCurrentDefinition()
# all this b.s. below is just to set the location in the tab menu
nodeType = hdaDef.nodeType()
categoryName = nodeType.category().name().lower()
defaultToolName = hou.shelves.defaultToolName(categoryName, nodeType.name())
# try to find an existing tool of this name. When we copy
# the hda and it has a default, internal tool, that tool
# gets copied too. We need to delete it before we can
# create and embed it into the asset.
existingTool = hou.shelves.tools().get(defaultToolName)
if existingTool:
existingTool.destroy()
# construct a temp .shelf file path
tempFilePath = os.path.join("C:\\temp", "temp.shelf")
# create a temporary tool
tempTool = defaulttools.createDefaultHDATool(
shelffile=tempFilePath,
nodetype=nodeType,
toolname=defaultToolName,
locations=("Ingenuity",),
)
# set the HDA tool variables to the tool
defaulttools.setHDAToolVariables(tempTool, hdaDef)
# grab the contents of the tool file
print(f"tempFilePath: {tempFilePath}")
contents = hou.readFile(tempFilePath)
# store it in the asset definition.
hdaDef.addSection("Tools.shelf", tempTool)
# look for a tool named "$HDA_DEFAULT_TOOL"
defaultTool = hou.shelves.tools().get("$HDA_DEFAULT_TOOL")
# if it exists we need to destroy it or it will cause problems
if defaultTool is not None:
defaultTool.destroy()
# remove the temp file.
os.remove(tempFilePath)
# remove the spare parms now that they're saved in the HDA
nativeHDA.removeSpareParms()
# Display HDA creation success message
baseContainer.BaseContainer().askOptions(
question=f"New Company Name HDA created: {nativeHDA.type().name()}"
"\n Your subnet will be replaced by the new HDA",
options=(Outcome.ok, Outcome.cancel),
title="Notice",
)
# Create an entry in the HDAs version history to store its creation time and creator name
print("Logging HDA creation")
HDAVersionNotes().publishNotes(nativeHDA, f"HDA created by {getUserName()}")
# git commit changes
repositoryPath = "C:/ie4-otl"
commitOutput = None
try:
statusOutput = subprocess.check_output(
["git", "status", "--porcelain"], cwd=repositoryPath, shell=True
)
if statusOutput:
print("Running Git add .")
# Add the git add command
addCommand = ["git", "add", "."]
addOutput = subprocess.run(
addCommand,
cwd=repositoryPath,
check=True,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
print(f"statusOutput: {statusOutput}")
if addOutput.returncode == 0:
print("Git add successful")
commitMessage = f"{name} has been created by {getUserName()}"
commitCommand = ["git", "commit", "-am", commitMessage]
commitOutput = subprocess.run(
commitCommand,
cwd=repositoryPath,
check=True,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
if commitOutput.returncode == 0:
print(f"Git commit successful: {commitMessage}")
# Add the git push command
pushCommand = ["git", "push", "origin", "main"]
pushOutput = subprocess.run(
pushCommand,
cwd=repositoryPath,
check=True,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
if pushOutput.returncode == 0:
print("Git push successful.")
else:
print(f"Git push failed with error: {pushOutput.stderr}")
else:
print(f"Git add failed with error: {addOutput.stderr}")
else:
print("No changes to commit.")
except subprocess.CalledProcessError as e:
# print(f"Error running 'git commit': {e}: {commitOutput.stderr}")
print(f"Error running 'git commit': {e}")
return self.translator.ensureNode(nativeHDA)
When createNewHDA is called, i'm getting this error (attached image). It does just look like there just isn't a temp file actually being written at all. Perhaps this is just something i'm not understanding about the Houdini api. Any help would be massively appreciated!