我的Python脚本以什么方式获取当前在图像节点中选择的带有图像名称的文本字符串?我认为使用自定义节点标签是正确的,但无法找到描述方法的任何代码段。
即使没有选择任何节点,脚本也必须全局工作。
答案 0 :(得分:0)
希望这可以帮助你:
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”的节点并设置名称
编辑: 我看到你刚刚添加了一张图片,而你没有使用纹理,抱歉 与上面相同的原理适用于Image节点
bpy.data.scenes['Scene'].node_tree.nodes['Image'].image.name
答案 1 :(得分:0)
您可以在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: