#错误:ImportError:没有名为的模块样品.光强度#

2024-10-04 05:28:43 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的剧本:

import maya.cmds as cmds

def changeLightIntensity(percentage=1.0):
    """
    Changes the intensity of each light the scene by percentage.

    Parameters:
        percentage - Percentage to change each light's intensity. Default value is 1.

    Returns:
        Nothing.
    """
    #The is command is the list command. It is used to list various nodes
    #in the  current scene. You can also use it to list selected nodes.
    lightInScene = cmds.ls(type='light')

    #If there are no lights in the scene, there is no point running this script
    if not lightInScene:
        raise RunTimeError, 'There are no lights in the scene!'

    #Loop through each light
    for light in lightInScene:
        #The getAttr command is used to get attribute values of a node
        currentIntensity = cmds.getAttr('%s.intensity' % light)
        #Calculate a new intensity
        newIntensity = currentIntensity * percentage
        #Change the lights intensity to the new intensity
        cmds.setAttr('%s.intensity' % light, newIntensity)
        #Report to the user what we just did
        print 'Changed the intensity of light %s from %.3f to %.3f' % (light, currentIntensity, newIntensity)


import samples.lightIntensity as lightIntensity
lightIntensity.changelightIntensity(1.2)

我的错误是:

ImportError: No module named samples.lightIntensity

怎么了?我能处理这个吗?解决办法是什么?在

谢谢!在


Tags: ofthetoinisscenecommandlist
1条回答
网友
1楼 · 发布于 2024-10-04 05:28:43

似乎您正在遵循this教程。您所误解的是,代码示例中的最后两行不应该是脚本的一部分,但它们应该在解释器中运行前面的代码。如果您再看一下教程,您将看到主代码示例上方有一个标题,上面写着光强度.py,而第二个较小的代码示例前面有“以运行此脚本,请在脚本编辑器中键入…

所以,这个:

import samples.lightIntensity as lightIntensity
lightIntensity.changelightIntensity(1.2)

不应该以那种形式出现在你的档案中。在

你可以做两件事。不过,我更希望你能轻松地使用第二个代码。在

  1. 将不带最后两行的代码保存为lightIntensity.py,并在pythonshell中(在命令行上启动python,使用IDLE,无论使用什么),在提示符后,键入import lightIntensity导入脚本,并lightIntensity.changelightIntensity(1.2)调用脚本中的函数。

  2. 或者,可以修复脚本,使其在不尝试导入自身的情况下运行。为此,请删除import行并将最后一行更改为changelightIntensity(1.2)

相关问题 更多 >