[Closed] classOf for values?
Is there a way through script to check what value type a parameter needs? Kind of like what classOf does, but instead would let me know that a certain parameter on an object needs an integer instead of a string or boolean.
ClassOf, of course, does tell you what type of value it is if there is a value already assigned, the problem I’m running into is with maps in a material before they have maps assigned to them. They return undefined.
Basically just trying to set up error checking to avoid an “unable to convert to type” error, without having to resort to a try()catch().
I figure max knows what every value has to be (obviously, otherwise there wouldn’t be an error telling me it has to be a certain type of value), so there must be a way to access this info before hand.
Thanks guys.
Pjannsen, were you able to find an answer to this in the help file? If so could you please tell me where because I have been through it looking for a solution and havent found one.
Whats a help file? hahaha, jk
Yeah, I need it realtime. I’m basically cycling through a bunch of parameters being read in from an ini in order to create materials on the fly. It needs to be user friendly, so I want to be able to check first that the value being provided from the ini is compatible with the property that the user is trying to assign it to. In some cases it would also be helpful to know the class needed for the param so I know to perform certain tasks with the data being provided before trying to assign it, not just for error checking.
Does showinterfaces do what you want? Mind you – that’s not on the fly. Perhaps you could create some kind of lookup table?
Not sure if you're up on Regular Expressions or not, but if you were to parse even the help files pages with an expression like this:
Find: <[^>]+>\.(\w+)\s(\w+)
Replace: param:"$1" type:"$2"
You'd get this (for the Raytrace Material):
param:"Ambient_Color_On" type:"Boolean"
param:"Ambient" type:"Color"
param:"Ambient_Amount" type:"Float"
param:"Luminosity_Color_On" type:"Boolean"
param:"Luminosity" type:"Color"
param:"Self_Illum_Amount" type:"Float"
param:"Diffuse" type:"Color"
param:"Transparency_Color_On" type:"Boolean"
param:"Transparecy" type:"Color"
param:"Transparency_Amount" type:"Float"
param:"Reflect_Color_On" type:"Integer"
param:"Reflect" type:"Color"
param:"Reflect_amount" type:"Float"
param:"Index_of_Refraction" type:"Float"
param:"Spec__Color" type:"Color"
param:"Specular_Level" type:"Float"
param:"Glossiness" type:"Float"
param:"Soften" type:"Float"
param:"Extra_Lighting" type:"Color"
param:"translucency" type:"Color"
param:"Fluorescence" type:"Color"
param:"Fluorescence_Bias" type:"Float"
param:"Wire_Size" type:"Float"
param:"wireUnits" type:"Integer"
param:"Color_Density_Enable" type:"Boolean"
param:"Color_Density_Start" type:"Float"
param:"Color_Density_End" type:"Float"
param:"Color_Density_Amount" type:"Float"
param:"Color_Density_Color" type:"Color"
param:"Fog_Enable" type:"Boolean"
param:"Fog_Start" type:"Float"
param:"Fog_End" type:"Float"
param:"Fog_Amount" type:"Float"
param:"Fog_Color" type:"Color"
param:"Reflection_Type" type:"Integer"
param:"Reflection_Gain" type:"Float"
param:"Enable_Raytraced_Reflections" type:"Boolean"
param:"Enable_Raytraced_Refractions" type:"Boolean"
param:"Reflection_Falloff_Mode" type:"Integer"
param:"Reflection_Falloff_End_Distance" type:"Float"
param:"Refraction_Falloff_End_Distance" type:"Float"
param:"Bump_Map_Effect" type:"Float"
param:"Override_Global_Antialiasing_Settings" type:"Boolean"
param:"Adaptive_Antialiasing_On" type:"Boolean"
param:"Options___Raytracer_Enable" type:"Boolean"
param:"Options___Antialiasing_Enable" type:"Boolean"
param:"Options___Self_Reflect_Refract" type:"Boolean"
param:"Options___Raytrace_Atmospherics" type:"Boolean"
param:"Options___Reflect_Refract_Material_ID_s" type:"Boolean"
param:"Options___Raytrace_Objects_in_Glass" type:"Boolean"
param:"Options___Raytrace_Atmospherics_in_Glass" type:"Boolean"
param:"Options___Color_Density___Fog_Enable" type:"Boolean"
param:"Local_Threshold" type:"Float"
param:"Local_Min__Rays" type:"Integer"
param:"Local_Max__Rays" type:"Integer"
param:"Local_Blur_Offset" type:"Float"
param:"Local_Blur_Aspect" type:"Float"
param:"Local_Defocus" type:"Float"
param:"Local_Defocus_Aspect" type:"Float"
param:"ambientMap" type:"TextureMap"
param:"ambientMapAmount" type:"Float"
param:"ambientMapEnable" type:"Boolean"
param:"bumpMap" type:"TextureMap"
param:"bumpMapAmount" type:"Float"
param:"bumpMapEnable" type:"Boolean"
param:"diffuseMap" type:"TextureMap"
param:"diffuseMapAmount" type:"Float"
param:"diffuseMapEnable" type:"Boolean"
param:"displacementMap" type:"TextureMap"
param:"displacementMapAmount" type:"Float"
param:"displacementMapEnable" type:"Boolean"
param:"reflectionMap" type:"TextureMap"
param:"reflectionMapAmount" type:"Float"
param:"reflectionMapEnable" type:"Boolean"
param:"refractionMap" type:"TextureMap"
param:"refractionMapAmount" type:"Float"
param:"refractionMapEnable" type:"Boolean"
param:"glossinessMap" type:"TextureMap"
param:"glossinessMapAmount" type:"Float"
param:"glossinessMapEnable" type:"Boolean"
param:"specularLevelMap" type:"TextureMap"
param:"specularLevelMapAmount" type:"Float"
param:"specularLevelMapEnable" type:"Boolean"
param:"luminosityMap" type:"TextureMap"
param:"luminosityMapAmount" type:"Float"
param:"luminosityMapEnable" type:"Boolean"
param:"transparencyMap" type:"TextureMap"
param:"transparencyMapAmount" type:"Float"
param:"transparencyMapEnable" type:"Boolean"
param:"environmentMap" type:"TextureMap"
param:"environmentMapAmount" type:"Float"
param:"environmentMapEnable" type:"Boolean"
param:"transEnvMap" type:"TextureMap"
param:"transEnvMapAmount" type:"Float"
param:"transEnvMapEnable" type:"Boolean"
param:"iorMap" type:"TextureMap"
param:"iorMapAmount" type:"Float"
param:"iorMapEnable" type:"Boolean"
param:"translucencyMap" type:"TextureMap"
param:"translucencyMapAmount" type:"Float"
param:"translucencyMapEnable" type:"Boolean"
param:"extraLightingMap" type:"TextureMap"
param:"extraLightingMapAmount" type:"Float"
param:"extraLightingMapEnable" type:"Boolean"
param:"fluorescenceMap" type:"TextureMap"
param:"fluorescenceMapAmount" type:"Float"
param:"fluorescenceMapEnable" type:"Boolean"
param:"colorDensityMap" type:"TextureMap"
param:"colorDensityMapAmount" type:"Float"
param:"colorDensityMapEnable" type:"Boolean"
param:"fogColorMap" type:"TextureMap"
param:"fogColorMapAmount" type:"Float"
param:"fogColorMapEnable" type:"Boolean"
param:"diffusionMap" type:"TextureMap"
param:"diffusionMapAmount" type:"Float"
param:"diffusionMapEnable" type:"Boolean"
param:"specularMap" type:"TextureMap"
param:"specularMapAmount" type:"Float"
param:"specularMapEnable" type:"Boolean"
param:"Bounce_Coefficient" type:"Float"
param:"Static_Friction" type:"Float"
param:"Sliding_Friction" type:"Float"
param:"Attenuation_Start" type:"Float"
param:"Attenuation_Exponent" type:"Float"
param:"Attenuation_Color_Mode" type:"Integer"
param:"Attenuation_Color" type:"Color"
param:"Attenuation_Near" type:"Float"
param:"Attenuation_Control_1" type:"Float"
param:"Attenuation_Control_2" type:"Float"
param:"Attenuation_Far" type:"Float"
param:"Blur_Map" type:"Boolean"
param:"Defocus_Map" type:"Boolean"
param:"Enable_Reflection_Falloff" type:"Boolean"
param:"Reflection_Falloff_Distance" type:"Float"
param:"Enable_Refraction_Falloff" type:"Boolean"
param:"Refraction_Falloff_Distance" type:"Float"
param:"supersample" type:"Boolean"
param:"shaderByName" type:"String"
param:"Anisotropy" type:"Float"
param:"Orientation" type:"Float"
param:"sampler_param_block" type:"SubAnim"
class:"RaytraceMaterial.sampler_param_block" param:"sampler_on" type:"Boolean"
class:"RaytraceMaterial.sampler_param_block" param:"sampler_quality" type:"Float"
Maybe if you wanted to do it on the fly you could pass the results of showinterfaces to a Python or .NET script to parse using RegExp ... ?
don’t forget about showProperties
fn getPropsAndPropTypes obj = (
propString = stringStream ""
showproperties obj to:propString
propString = propString as string
propArray = filterString propString "
"
if (propArray.count == 0) then ( return #(#(),#()) )
propNamesArray = #(); propNamesArray[propArray.count] = undefined
propTypesArray = #(); propTypesArray[propArray.count] = undefined
for i = 1 to propArray.count do (
prop = propArray[i]
prop = filterString prop ":"
propNameString = (filterString prop[1] " ")[1]
propNameString = trimLeft propNameString
propNameString = trimRight propNameString
propNamesArray[i] = (subString propNameString 2 -1) as name
if (prop.count == 2) then (
propTypeString = prop[2]
propTypeString = trimLeft propTypeString
propTypeString = trimRight propTypeString
propTypesArray[i] = propTypeString
)
)
#(propNamesArray,propTypesArray)
)
Returns a 2-element array.
array[1] – contains all the property names returned with this method
array[2] – contains the property types
I’ve used this in a .NET treeview properties viewer to easily display what property type is expected for a value; especially useful when a property’s value is “undefined”, seeing as that could mean the parameter takes any maxwrapper, a node, a texture map, a material, etc – which you can’t find out if all you have to work with is “undefined”.
Good luck
Edit: removed references to the SplutterFish scripting lib – whoops.
I’m not sure elegant is the word Seems to work, though – as long as the property shows up with showProperties, that is. If it doesn’t, then classOf <value> is a decent fallback as long as <value> isn’t undefined
( similarly, but less of an issue, classOf <string> doesn’t tell you if it’s just any ol’ string or a filename string. )
Awesome! Exactly what I was looking for. Never even thought of parsing showProperties, good call! Thanks a lot for the replies guys, appreciate it.
Richard,
Great solution!
By the way, what’s the “sfs.lib.strTrim” thing that’s in the script? It kicks an error because this is undefined.