Notifications
Clear all

[Closed] ShowMore Function

A useful function worth putting in your scripts/startup folder… Gives you a print out of the properties and also the values with those properties, useful for finding values in renderer settings for instance.

fn showMore theclass =
(
	if theclass != undefined then
	(
		for p in getPropNames theclass do
		(
			format "% : % : value: %
" ("." + (p as string)) (classof (getproperty theclass p)) (getproperty theclass p)
		)
	)
	else undefined
)

--usage examples
showMore selection[1]
showMore (VrayMtl())


–Output example

.smooth : BooleanClass : value: true
.radius : Float : value: 25.0
.segs : Integer : value: 16
.mapcoords : BooleanClass : value: false
.slice : BooleanClass : value: false
.hemisphere : Float : value: 0.0
.sliceFrom : Float : value: 0.0
.sliceTo : Float : value: 0.0
.chop : Integer : value: 0
.recenter : BooleanClass : value: false
.realWorldMapSize : BooleanClass : value: false

6 Replies

Another slightly more advanced one which lists the node properties (if it is a node) and also the interfaces all in one go.

fn showAll theclass =
(
	if theclass != undefined then
	(
		format "
--% - Properties
" (theclass.name as string)
		for p in getPropNames theclass do
		(
			format "% : % : value: %
" ("." + (p as string)) (classof (getproperty theclass p)) (getproperty theclass p)
		)
		
		if IsValidNode theclass do
		(
			format "
--% - Node Properties
" (theclass.name as string)
			for p in getPropNames node do
			(
				format "% : % : value: %
" ("." + (p as string)) (classof (getproperty theclass p)) (getproperty theclass p)
			)
		)
		
		ss = stringstream ""
		sss = ""
		format "

--% - Interfaces

" (theclass.name as string)
		showinterfaces theclass to:ss
		seek ss 0
		while not eof ss do 
		(
			append sss ((Readline ss) + "
")
		)
		format sss
	)
	else undefined
)

it might be cleaner to use showproperties function and add property values. instead of you method the showproperies returns right value class if the value is not defined (undefined state).

Potentially, I found this bit of code whilst I was looking for something else and thought I’d let people have it.

I’ve found issues with the showproperties to get the class also. If you try showproperties on the coords of a bitmaptexture for instance there are two properties Mapping and UVTransform which don’t list their class… which is annoying for a different tool I was trying to write.

that ‘s because some ParamBlock property type might be define as Number (mapping) or Value(UVTransform). so this property can be technically any class of superclass Number (float, integer, …) or Value (point2, point3, … matrix3, …)

 mapped fn formatPropNames o recursive:false inset:0 maxDepth:2 toFile:Listener =
    (
    	if classof toFile != WindowStream AND classof toFile != FileStream AND classof toFile != StringStream do
    		throw "The optional argument 'toFile' must be of class: WindowStream, FileStream or StringStream"
    	
    	hasProps = try((getPropNames o).count > 0)catch(false)
    	if NOT hasProps do return OK
    	
    	dashLine = "------------------------------------------------------------------------------
" -- has the new line 'built in'
    	gapSize = 3
    	pMax = 0
    	vMax = 0
    	failVal = "| getProperty FAILED |"
    	props = for p in (getPropNames o) collect try( #(p,
    												(p as string).count+1,
    												(val = getProperty o p),
    												(val as string).count,
    												(cls = classof val),
    												(cls as string).count
    												)-- end array
    												)-- end try
    												catch( #(p,
    												(p as string).count+1,
    												failVal,
    												failVal.count,
    												failVal,
    												failVal.count
    												)-- end array
    												)-- end catch
    	for p in props do 
    	(
    		if p[5] == Name then p[4] += 1 -- to account for the extra # character of Name values
    		if p[2] > pMax do pMax = p[2]
    		if p[4] > vMax do vMax = p[4]
    	)
    	pMax += gapSize
    	vMax += gapSize
    	
    	if inset > 0 then dashLine = ""
    	format "%" dashLine to:toFile
    	for i = 1 to inset do format "	" to:toFile
    	format "MaxObject: %
%" o dashLine to:toFile
    	for p in props do
    	(
    		for i = 1 to inset do format "	" to:toFile
    		format "propName: %" p[1] to:toFile
    		len = p[2]
    		for i = len to pMax do format " " to:toFile
    		format "|" to:toFile
    		for i = 1 to gapSize do format " " to:toFile
    		
    		format "value: %" p[3] to:toFile
    		len = p[4]
    		for i = len to vMax do format " " to:toFile
    		format "|" to:toFile
    		for i = 1 to gapSize do format " " to:toFile
    		
    		format "type: %
" p[5] to:toFile
    		
    		if recursive AND inset < maxDepth-1 do
    		(
    			hasSubProps = try((getPropNames p[3]).count > 0)catch(false)
    			if hasSubProps do formatPropNames p[3] recursive:true inset:(inset+1) maxDepth:maxDepth toFile:toFile
    		)
    	)
    	format "%" dashLine to:toFile
    )
    
    mapped fn showAll o toFile:Listener =
    (
    	if o == undefined do return false
    	if classof toFile != WindowStream AND classof toFile != FileStream AND classof toFile != StringStream do
    		throw "The optional argument 'toFile' must be of class: WindowStream, FileStream or StringStream"
    	
    	formatPropNames o toFile:toFile
    	if classof o == dotNetClass OR classof o == dotNetObject OR classof o == dotnetcontrol then
    	(
    		format "--------METHODS--------
" to:toFile
    		showMethods o to:toFile
    		format "--------EVENTS---------
" to:toFile
    		showEvents o to:toFile
    		format "---.NET CONSTRUCTORS---
" to:toFile
    		dotNet.showConstructors o to:toFile
    	)
    	else if classof o == string do try
    	(
    		format "---.NET CONSTRUCTORS---
" to:toFile
    		dotNet.showConstructors o to:toFile
    	)catch()
    	true
    )
    

this is my version. i wrote this a long time ago and it has served me well. there’s 2 functions but you only need to call showall directly.

Example output: (the columns are all aligned correctly in the mxs listener)

showall (teapot())
  ------------------------------------------------------------------------------
  MaxObject: $Teapot:Teapot002 @ [0.000000,0.000000,0.000000]
  ------------------------------------------------------------------------------
  propName: #smooth			  |   value: true	 |   type: BooleanClass
  propName: #radius			  |   value: 25.0	 |   type: Float
  propName: #segs				|   value: 4		|   type: Integer
  propName: #mapcoords		   |   value: false	|   type: BooleanClass
  propName: #body				|   value: true	 |   type: BooleanClass
  propName: #handle			  |   value: true	 |   type: BooleanClass
  propName: #spout			   |   value: true	 |   type: BooleanClass
  propName: #lid				 |   value: true	 |   type: BooleanClass
  propName: #realWorldMapSize	|   value: false	|   type: BooleanClass
  ------------------------------------------------------------------------------

Thank you guys! Simple and useful.