Это мой сценарий:# Ошибка: ImportError: Нет модуль с именем samples.lightIntensity #
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
В чем проблема? Могу я сделать с этим? Какое решение?
Спасибо!
я снова что-то пропустил. Потому что я сохранил сценарий как lightIntensity.py тогда я побежал две строки: импорт samples.lightIntensity как lightIntensity lightIntensity.changelightIntensity (1.2) И я получил ошибку: ImportError: нет модуль с именем образцов. lightIntensity Что пошло не так (опять же)? – Oldran
Ах, справа. Фактически, 'import samples.lightIntensity' будет работать, только если lightIntensity.py находится в пакете под названием' samples'. Просто «импортируйте lightIntensity». – Junuxx
Спасибо! Отлично! – Oldran