By Mingfae Wong - Tue Aug 10, 2021 6:22 am
- Tue Aug 10, 2021 6:22 am
#400964
I'm trying to replace the MaxwellScatter setting from one object to another one by pymaxwell, but it just doesn't work. Could someone help me or point me in the right direction? I'm using pymaxwell4.
from pymaxwell4 import *
def replaceScatterSetting():
filepath = "C:/Users/twong/Desktop/test.mxs"
replaceDict = {'FloorA_old': 'FloorA_new', 'FloorB_old': 'FloorB_new'}
scene = Cmaxwell(mwcallback)
scene.readMXS(filepath)
for a in replaceDict:
objOld = scene.getObject(a)
objnew = scene.getObject(replaceDict[a])
if objOld.hasGeometryModifiers()[0]: # True = have Modifiers.
modifyQty = objOld.getGeometryModifierExtensionsNumber()[0] # check how many Modifiers in the object.
for i in range(modifyQty): # check Modifiers ono by one.
extData = objOld.getGeometryModifierExtensionParamsAtIndex(i)[0]
if extData.getFloat('Density')[1]: # Ture = MaxwellScatter
print('MaxwellScatter found')
scatter_Object = extData.getString('Object')
scatter_ObjectID = extData.getByte('Inherit ObjectID')
scatter_Density = extData.getFloat('Density')
scatter_DensityMap = extData.getTextureMap('Density Map')[0]
scatter_Overlapped = extData.getByte('Remove Overlapped')
scatter_Seed = extData.getUInt('Seed')
scatter_Scale_X = extData.getFloat('Scale X')
scatter_Scale_Y = extData.getFloat('Scale Y')
scatter_Scale_Z = extData.getFloat('Scale Z')
scatter_ScaleMap = extData.getTextureMap('Scale Map')[0]
scatter_UniformScale = extData.getByte('Uniform Scale')
scatter_Scale_Xvar = extData.getFloat('Scale X Variation')
scatter_Scale_Yvar = extData.getFloat('Scale Y Variation')
scatter_Scale_Zvar = extData.getFloat('Scale Z Variation')
scatter_Rotate_X = extData.getFloat('Rotation X')
scatter_Rotate_Y = extData.getFloat('Rotation Y')
scatter_Rotate_Z = extData.getFloat('Rotation Z')
scatter_RotateMap = extData.getTextureMap('Rotation Map')[0]
scatter_Rotate_Xvar = extData.getFloat('Rotation X Variation')
scatter_Rotate_Yvar = extData.getFloat('Rotation Y Variation')
scatter_Rotate_Zvar = extData.getFloat('Rotation Z Variation')
scatter_DirectionY = extData.getFloat('Direction Type')
scatter_LOD = extData.getByte('Enable LOD')
scatter_LOD_MinDist = extData.getFloat('LOD Min Distance')
scatter_LOD_MaxDist = extData.getFloat('LOD Max Distance')
scatter_LOD_MaxDist_Density = extData.getFloat('LOD Max Distance Density')
scatter_DirectionType = extData.getFloat('Direction Type')
scatter_InitialAngle = extData.getFloat('Initial Angle')
scatter_InitialAngVar = extData.getFloat('Initial Angle Variation')
scatter_InitialAngleMap = extData.getTextureMap('Initial Angle Map')[0]
scatter_DisplayPercent = extData.getUInt('Display Percent')
scatter_DisplayMaxIns = extData.getUInt('Display Max. Instances')
print('copy setting to new object')
extManger = CextensionManager.instance()
extManger.loadAllExtensions()
scatterExt = extManger.createDefaultGeometryModifierExtension('MaxwellScatter')
scatterExtData = scatterExt.getExtensionData()
scatterExtData.setString('Object', scatter_Object[0])
scatterExtData.setByte('Inherit ObjectID', scatter_ObjectID[0])
scatterExtData.setFloat('Density', scatter_Density[0])
scatterExtData.setTextureMap('Density Map', scatter_DensityMap)
scatterExtData.setUInt('Seed', scatter_Seed[0])
scatterExtData.setByte('Remove Overlapped', scatter_Overlapped[0])
scatterExtData.setFloat('Scale X', scatter_Scale_X[0])
scatterExtData.setFloat('Scale Y', scatter_Scale_Y[0])
scatterExtData.setFloat('Scale Z', scatter_Scale_Z[0])
scatterExtData.setTextureMap('Scale Map', scatter_ScaleMap)
scatterExtData.setFloat('Scale X Variation', scatter_Scale_Xvar[0])
scatterExtData.setFloat('Scale Y Variation', scatter_Scale_Yvar[0])
scatterExtData.setFloat('Scale Z Variation', scatter_Scale_Zvar[0])
scatterExtData.setByte('Uniform Scale', scatter_UniformScale[0])
scatterExtData.setFloat('Rotation X', scatter_Rotate_X[0])
scatterExtData.setFloat('Rotation Y', scatter_Rotate_Y[0])
scatterExtData.setFloat('Rotation Z', scatter_Rotate_Z[0])
scatterExtData.setTextureMap('Rotation Map', scatter_RotateMap)
scatterExtData.setFloat('Rotation X Variation', scatter_Rotate_Xvar[0])
scatterExtData.setFloat('Rotation Y Variation', scatter_Rotate_Yvar[0])
scatterExtData.setFloat('Rotation Z Variation', scatter_Rotate_Zvar[0])
scatterExtData.setUInt('Direction Type', int(scatter_DirectionY[0]))
scatterExtData.setByte('Enable LOD', scatter_LOD[0])
scatterExtData.setFloat('LOD Min Distance', scatter_LOD_MinDist[0])
scatterExtData.setFloat('LOD Max Distance', scatter_LOD_MaxDist[0])
scatterExtData.setFloat('LOD Max Distance Density', scatter_LOD_MaxDist_Density[0])
scatterExtData.setFloat('Direction Type', scatter_DirectionType[0])
scatterExtData.setFloat('Initial Angle', scatter_InitialAngle[0])
scatterExtData.setFloat('Initial Angle Variation', scatter_InitialAngVar[0])
scatterExtData.setTextureMap('Initial Angle Map', scatter_InitialAngleMap)
scatterExtData.setUInt('Display Percent', scatter_DisplayPercent[0])
scatterExtData.setUInt('Display Max. Blades', scatter_DisplayMaxIns[0])
objnew.applyGeometryModifierExtension(scatterExtData)
scene.writeMXS('C:/Users/twong/Desktop/output.mxs')
replaceScatterSetting()
from pymaxwell4 import *
def replaceScatterSetting():
filepath = "C:/Users/twong/Desktop/test.mxs"
replaceDict = {'FloorA_old': 'FloorA_new', 'FloorB_old': 'FloorB_new'}
scene = Cmaxwell(mwcallback)
scene.readMXS(filepath)
for a in replaceDict:
objOld = scene.getObject(a)
objnew = scene.getObject(replaceDict[a])
if objOld.hasGeometryModifiers()[0]: # True = have Modifiers.
modifyQty = objOld.getGeometryModifierExtensionsNumber()[0] # check how many Modifiers in the object.
for i in range(modifyQty): # check Modifiers ono by one.
extData = objOld.getGeometryModifierExtensionParamsAtIndex(i)[0]
if extData.getFloat('Density')[1]: # Ture = MaxwellScatter
print('MaxwellScatter found')
scatter_Object = extData.getString('Object')
scatter_ObjectID = extData.getByte('Inherit ObjectID')
scatter_Density = extData.getFloat('Density')
scatter_DensityMap = extData.getTextureMap('Density Map')[0]
scatter_Overlapped = extData.getByte('Remove Overlapped')
scatter_Seed = extData.getUInt('Seed')
scatter_Scale_X = extData.getFloat('Scale X')
scatter_Scale_Y = extData.getFloat('Scale Y')
scatter_Scale_Z = extData.getFloat('Scale Z')
scatter_ScaleMap = extData.getTextureMap('Scale Map')[0]
scatter_UniformScale = extData.getByte('Uniform Scale')
scatter_Scale_Xvar = extData.getFloat('Scale X Variation')
scatter_Scale_Yvar = extData.getFloat('Scale Y Variation')
scatter_Scale_Zvar = extData.getFloat('Scale Z Variation')
scatter_Rotate_X = extData.getFloat('Rotation X')
scatter_Rotate_Y = extData.getFloat('Rotation Y')
scatter_Rotate_Z = extData.getFloat('Rotation Z')
scatter_RotateMap = extData.getTextureMap('Rotation Map')[0]
scatter_Rotate_Xvar = extData.getFloat('Rotation X Variation')
scatter_Rotate_Yvar = extData.getFloat('Rotation Y Variation')
scatter_Rotate_Zvar = extData.getFloat('Rotation Z Variation')
scatter_DirectionY = extData.getFloat('Direction Type')
scatter_LOD = extData.getByte('Enable LOD')
scatter_LOD_MinDist = extData.getFloat('LOD Min Distance')
scatter_LOD_MaxDist = extData.getFloat('LOD Max Distance')
scatter_LOD_MaxDist_Density = extData.getFloat('LOD Max Distance Density')
scatter_DirectionType = extData.getFloat('Direction Type')
scatter_InitialAngle = extData.getFloat('Initial Angle')
scatter_InitialAngVar = extData.getFloat('Initial Angle Variation')
scatter_InitialAngleMap = extData.getTextureMap('Initial Angle Map')[0]
scatter_DisplayPercent = extData.getUInt('Display Percent')
scatter_DisplayMaxIns = extData.getUInt('Display Max. Instances')
print('copy setting to new object')
extManger = CextensionManager.instance()
extManger.loadAllExtensions()
scatterExt = extManger.createDefaultGeometryModifierExtension('MaxwellScatter')
scatterExtData = scatterExt.getExtensionData()
scatterExtData.setString('Object', scatter_Object[0])
scatterExtData.setByte('Inherit ObjectID', scatter_ObjectID[0])
scatterExtData.setFloat('Density', scatter_Density[0])
scatterExtData.setTextureMap('Density Map', scatter_DensityMap)
scatterExtData.setUInt('Seed', scatter_Seed[0])
scatterExtData.setByte('Remove Overlapped', scatter_Overlapped[0])
scatterExtData.setFloat('Scale X', scatter_Scale_X[0])
scatterExtData.setFloat('Scale Y', scatter_Scale_Y[0])
scatterExtData.setFloat('Scale Z', scatter_Scale_Z[0])
scatterExtData.setTextureMap('Scale Map', scatter_ScaleMap)
scatterExtData.setFloat('Scale X Variation', scatter_Scale_Xvar[0])
scatterExtData.setFloat('Scale Y Variation', scatter_Scale_Yvar[0])
scatterExtData.setFloat('Scale Z Variation', scatter_Scale_Zvar[0])
scatterExtData.setByte('Uniform Scale', scatter_UniformScale[0])
scatterExtData.setFloat('Rotation X', scatter_Rotate_X[0])
scatterExtData.setFloat('Rotation Y', scatter_Rotate_Y[0])
scatterExtData.setFloat('Rotation Z', scatter_Rotate_Z[0])
scatterExtData.setTextureMap('Rotation Map', scatter_RotateMap)
scatterExtData.setFloat('Rotation X Variation', scatter_Rotate_Xvar[0])
scatterExtData.setFloat('Rotation Y Variation', scatter_Rotate_Yvar[0])
scatterExtData.setFloat('Rotation Z Variation', scatter_Rotate_Zvar[0])
scatterExtData.setUInt('Direction Type', int(scatter_DirectionY[0]))
scatterExtData.setByte('Enable LOD', scatter_LOD[0])
scatterExtData.setFloat('LOD Min Distance', scatter_LOD_MinDist[0])
scatterExtData.setFloat('LOD Max Distance', scatter_LOD_MaxDist[0])
scatterExtData.setFloat('LOD Max Distance Density', scatter_LOD_MaxDist_Density[0])
scatterExtData.setFloat('Direction Type', scatter_DirectionType[0])
scatterExtData.setFloat('Initial Angle', scatter_InitialAngle[0])
scatterExtData.setFloat('Initial Angle Variation', scatter_InitialAngVar[0])
scatterExtData.setTextureMap('Initial Angle Map', scatter_InitialAngleMap)
scatterExtData.setUInt('Display Percent', scatter_DisplayPercent[0])
scatterExtData.setUInt('Display Max. Blades', scatter_DisplayMaxIns[0])
objnew.applyGeometryModifierExtension(scatterExtData)
scene.writeMXS('C:/Users/twong/Desktop/output.mxs')
replaceScatterSetting()
You do not have the required permissions to view the files attached to this post.