@Dunhou - Thanks so much for the sample code, it works brilliantly. Your Renderer lib looks incredible, I love how compact/accessible that version is. Unfortunately I'll need to share these scripts with a variety of external parners and I'm not sure I can trust they'll have Boghma installed.
@ferdinand - I'll avoid diary-style requests in the future. Thanks for pointing me to Graph Descriptions. I knew that something like this existed, but I couldn't track it down. Perhaps this would make a good SDK example?
@ferdinand - How would you query all nodes except the main Output node?
Here's a fully working script:
"""Name-en-US: Hide RS Material Node Previews
Description-en-US: Finds all previews in Redshift nodal materials except for their final Output node.
## References
- [Hiding Node Previews for all Redshift Nodes in Redshift Materials](https://developers.maxon.net/forum/topic/16119/hiding-node-previews-for-all-redshift-nodes-in-redshift-materials)
## Change Log
- v1.0.0: Converted to script and added undo support, documentation, and reference.
- v0.9.0: Initial working version by Dunhou.
- v0.1.0: Prototype by Donovan.
## Thanks
Special thanks to Dunhou and Ferdinand.
"""
__authors__ = [
"Dunhou (https://www.boghma.com/)",
"Donovan Keith <[email protected]> (https://www.maxon.net/en/capsules)",
]
__version__ = "1.0.0"
import c4d
import maxon
doc: c4d.documents.BaseDocument
def main():
global doc
if doc is None:
print("No active document.")
return
doc.StartUndo()
for mat in doc.GetMaterials():
doc.AddUndo(c4d.UNDOTYPE_CHANGE, mat)
nodeMaterial: c4d.NodeMaterial = mat.GetNodeMaterialReference()
if not nodeMaterial.HasSpace(maxon.NodeSpaceIdentifiers.RedshiftMaterial):
continue
graph: maxon.NodesGraphModelRef = nodeMaterial.GetGraph(
maxon.NodeSpaceIdentifiers.RedshiftMaterial
)
root: maxon.GraphNode = graph.GetViewRoot()
nimbusRef: maxon.NimbusBaseRef = mat.GetNimbusRef(
maxon.NodeSpaceIdentifiers.RedshiftMaterial
)
endNodePath: maxon.NodePath = nimbusRef.GetPath(
maxon.NIMBUS_PATH.MATERIALENDNODE
)
endNode: maxon.GraphNode = graph.GetNode(endNodePath)
with graph.BeginTransaction() as transaction:
node: maxon.GraphNode
for node in root.GetInnerNodes(
mask=maxon.NODE_KIND.NODE, includeThis=False
):
node.SetValue(maxon.NODE.BASE.DISPLAYPREVIEW, maxon.Bool(False))
endNode.SetValue(maxon.NODE.BASE.DISPLAYPREVIEW, maxon.Bool(True))
transaction.Commit()
doc.EndUndo()
c4d.EventAdd()
if __name__ == "__main__":
main()