- Wed Apr 17, 2019 12:11 pm
#398155
Hi everyone.
Trying to run a script and I get this error message:
File "<string>", line 6, in <module>
NameError: name 'mxs_dir' is not defined
This script changes the Emitter wattage in an Animation sequence from 0 to 25 Watts. I had it runnig in 2017 but since then I guess pymaxwell module was renamed to pymaxwel4, so I changed that and the script now gets hung up on the above mentioned error.
What is he Looking for exactly ANY IDEAS?
THANKS Q!
here's the script:
#============== CHANGE THESE VARIABLES AS REQUIRED ==============
mxs_dir = 'C:/Users/<carsten quilitz>/Desktop/mxsfiles'
mat_name = 'Emitter'
watts_min = 0
watts_max = 25
#================= DON'T CHANGE ANYTHING ELSE =================
import os
import sys
from pymaxwell4 import *
mxs_dir = os.path.normpath(mxs_dir)
if not os.path.isdir(mxs_dir):
print('ERROR: input dir not found: %s' % mxs_dir)
sys.exit(1)
mxs_files = getFilesFromPath(mxs_dir, '.mxs')
if not len(mxs_files):
print('ERROR: no MXS files found: %s' % mxs_dir)
sys.exit(1)
mxs_files.sort()
incr = (watts_max - watts_min) / float(len(mxs_files))
watts = watts_min
def read_emitter(mxs_path):
mw = Cmaxwell(mwcallback)
if not mw.readMXS(mxs_path):
print('ERROR: Failed to read %s.' % mxs_path)
mw.freeScene()
return None,None,None
material = mw.getMaterial(mat_name)
if material.isNull():
print('ERROR: Failed to find "emitter" material in %s.' % mxs_path)
mw.freeScene()
return None,None,None
layer = material.getLayer(0)
if layer.isNull():
print('ERROR: Failed to find layer 0 for "emitter" material in %s.' % mxs_path)
mw.freeScene()
return None,None,None
emitter = layer.getEmitter()
if emitter.isNull():
print('ERROR: Failed to find emitter for layer 0 in %s.' % mxs_path)
mw.freeScene()
return None,None,None
pair,ok = emitter.getPair()
if not ok or emitter.isNull():
print('ERROR: Failed to get emitter pair for layer 0 in %s.' % mxs_path)
mw.freeScene()
return None,None,None
return mw,emitter,pair
for mxs_file in mxs_files:
mxs_path = os.path.join(mxs_dir, mxs_file)
mw,emitter,pair = read_emitter(mxs_path)
if not mw:
continue
pair.watts = watts
emitter.setPair(pair)
if not mw.writeMXS(mxs_path):
print('ERROR: failed to write %s' % mxs_path)
else:
print('OK: adjusted emitter to %s in %s.' % (watts, mxs_path))
mw.freeScene()
watts = watts + incr
Trying to run a script and I get this error message:
File "<string>", line 6, in <module>
NameError: name 'mxs_dir' is not defined
This script changes the Emitter wattage in an Animation sequence from 0 to 25 Watts. I had it runnig in 2017 but since then I guess pymaxwell module was renamed to pymaxwel4, so I changed that and the script now gets hung up on the above mentioned error.
What is he Looking for exactly ANY IDEAS?
THANKS Q!
here's the script:
#============== CHANGE THESE VARIABLES AS REQUIRED ==============
mxs_dir = 'C:/Users/<carsten quilitz>/Desktop/mxsfiles'
mat_name = 'Emitter'
watts_min = 0
watts_max = 25
#================= DON'T CHANGE ANYTHING ELSE =================
import os
import sys
from pymaxwell4 import *
mxs_dir = os.path.normpath(mxs_dir)
if not os.path.isdir(mxs_dir):
print('ERROR: input dir not found: %s' % mxs_dir)
sys.exit(1)
mxs_files = getFilesFromPath(mxs_dir, '.mxs')
if not len(mxs_files):
print('ERROR: no MXS files found: %s' % mxs_dir)
sys.exit(1)
mxs_files.sort()
incr = (watts_max - watts_min) / float(len(mxs_files))
watts = watts_min
def read_emitter(mxs_path):
mw = Cmaxwell(mwcallback)
if not mw.readMXS(mxs_path):
print('ERROR: Failed to read %s.' % mxs_path)
mw.freeScene()
return None,None,None
material = mw.getMaterial(mat_name)
if material.isNull():
print('ERROR: Failed to find "emitter" material in %s.' % mxs_path)
mw.freeScene()
return None,None,None
layer = material.getLayer(0)
if layer.isNull():
print('ERROR: Failed to find layer 0 for "emitter" material in %s.' % mxs_path)
mw.freeScene()
return None,None,None
emitter = layer.getEmitter()
if emitter.isNull():
print('ERROR: Failed to find emitter for layer 0 in %s.' % mxs_path)
mw.freeScene()
return None,None,None
pair,ok = emitter.getPair()
if not ok or emitter.isNull():
print('ERROR: Failed to get emitter pair for layer 0 in %s.' % mxs_path)
mw.freeScene()
return None,None,None
return mw,emitter,pair
for mxs_file in mxs_files:
mxs_path = os.path.join(mxs_dir, mxs_file)
mw,emitter,pair = read_emitter(mxs_path)
if not mw:
continue
pair.watts = watts
emitter.setPair(pair)
if not mw.writeMXS(mxs_path):
print('ERROR: failed to write %s' % mxs_path)
else:
print('OK: adjusted emitter to %s in %s.' % (watts, mxs_path))
mw.freeScene()
watts = watts + incr
Cinema R20 - Rhino - Maxwell Render on 318 Core CPU Ranch Mobile Renderfarm - OS X+WIN X http://www.carstenquilitz.de