如何获得Blender Compositor Image Node选择的图像名称?
我的Python脚本可以通过什么方式获得当前在图像节点中选择的具有图像名称的文本字符串?我想是使用自定义节点标签的权利,但无法找到任何代码段,它描述了方法。如何获得Blender Compositor Image Node选择的图像名称?
脚本必须在全球开展工作,即使没有任何节点选择,如果可能的话。
希望这可以帮助你:
nodes = material_slot.material.node_tree.nodes
texture_node = nodes.get('Image Texture')
if texture_node is None:
texture_node = nodes.new(type='ShaderNodeTexImage')
#texture_node.image = image
# Get the image name
texture_name = texture_node.image.name
# Set the node name/label to image name
texture_node.name = texture_name
texture_node.label = texture_name
,如果你想获得一个现有的节点,但你有多个纹理节点,你很可能迭代槽的所有节点,找到类型为“TEX_IMAGE”的所有节点,并设置名称
编辑: 我已经看到您刚才添加的图片,你不与纹理的工作,有关 相同的原则对不起如上无二图像节点虽然
bpy.data.scenes['Scene'].node_tree.nodes['Image'].image.name
谢谢,这正是我所需要的 - 在你的编辑: bpy.data.scenes ['Scene']。node_tree.nodes ['Image']。image.name – maxdudik
很高兴它解决了!我以为你想以编程方式重新命名基于图像名称的节点(这就是为什么我建议迭代通过所有节点),但如果你知道你想要定位哪个节点,那么它更容易! –
您可以在bpy.context.scene.node_tree.nodes
中找到合成器节点,然后遍历它们并检查类型是否为IMAGE
。
import bpy
for n in bpy.context.scene.node_tree.nodes:
if n.type == 'IMAGE':
# check that there is an image selected
if n.image is not None:
print(n.image.name)
如果你只是想所选图像节点,添加if n.select:
所以,你选择的NodeTree或NodeSocket图像节点,并希望得到的文件名? –