Page 2 of 2

Re: Change Emitter Value in Bongo Animation?

Posted: Thu Nov 09, 2017 5:44 pm
by Q2
BAM!!!!!

Great- Works fine now! :D :D :D :D :D :D :D :D :D

Thanks again, great help!!!!!!!

Re: Change Emitter Value in Bongo Animation?

Posted: Thu Nov 09, 2017 5:50 pm
by JDHill
Glad to hear it. :)

Re: Change Emitter Value in Bongo Animation?

Posted: Thu Nov 09, 2017 5:55 pm
by Q2
:oops: JUST BY ANY CHANCE....

Would it also be possible to script the same thing for an "Emitter MXI".
A picture that has been converted in Maxwell Render to an Emitter.

???

Re: Change Emitter Value in Bongo Animation?

Posted: Thu Nov 09, 2017 5:58 pm
by JDHill
Do you mean that you have a series of .mxi files, where you want to change the path in the emitter material to use a different .mxi in each frame?

Re: Change Emitter Value in Bongo Animation?

Posted: Thu Nov 09, 2017 6:02 pm
by Q2
No, I have a series of files where I need to change the emitter value also from 0-100 Percent...Exept this time I use an MXI as my light source and not a regular Maxwell emitter with wattage.

Now that I think of it, maybe it would work with your script anyway....

Checking....

Re: Change Emitter Value in Bongo Animation?

Posted: Thu Nov 09, 2017 6:05 pm
by JDHill
It won't work as-is, because it modulates the wattage, not the .mxi intensity. Hang on...

Re: Change Emitter Value in Bongo Animation?

Posted: Thu Nov 09, 2017 6:08 pm
by Q2
JEPP, Just tried it...do not work this does

Re: Change Emitter Value in Bongo Animation?

Posted: Thu Nov 09, 2017 6:18 pm
by JDHill
This should do the trick:
Code: Select all

#============== CHANGE THESE VARIABLES AS REQUIRED ==============

mxs_dir = 'C:/Users/<user name>/Desktop/mxsfiles'
mat_name = 'Emitter'
intensity_min = 0
intensity_max = 100

#=================  DON'T CHANGE ANYTHING ELSE  =================

import os
import sys
from pymaxwell 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 = (intensity_max - intensity_min) / float(len(mxs_files))
intensity = intensity_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
   mxi,ok = emitter.getMXI()
   if not ok or emitter.isNull():
      print('ERROR: Failed to get mxi for layer 0 in %s.' % mxs_path)
      mw.freeScene()
      return None,None,None
   return mw,emitter,mxi

for mxs_file in mxs_files:
   mxs_path = os.path.join(mxs_dir, mxs_file)
   mw,emitter,mxi = read_emitter(mxs_path)
   if not mw:
      continue
   mxi.value = intensity
   emitter.setMXI(mxi)
   if not mw.writeMXS(mxs_path):
      print('ERROR: failed to write %s' % mxs_path)
   else:
      print('OK: adjusted mxi intensity to %s in %s.' % (intensity, mxs_path))
   mw.freeScene()
   intensity = intensity + incr
   

Re: Change Emitter Value in Bongo Animation?

Posted: Thu Nov 09, 2017 6:35 pm
by Q2
MOTHER OF ALL CODERS!!!!!!!!


THIS IS AWESOME.

Man, this saves me a ton of work!

SO MANY THANKS. Works great!!!

:D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :o :o :o :o :o :o :o :o :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D