[Closed] ShowAll() – handy Snibbit
Just thought I’d share a snibbit I wrote recently ( long over due ) that has been helping me huge with .Net controls and classes in MaxScript. Also good for exploring any other max interface or object. I put this in scripts\startup\ so it defines as a global function…
fn showall ObjToShow =
(
try(
format "Properties
"
showProperties ObjToShow
)catch()
try(
format "Methods
"
showMethods ObjToShow
)catch()
try(
format "Events
"
showEvents ObjToShow
)catch()
try(
format "Constructors
"
dotNet.showConstructors ObjToShow
)catch()
)
Listener Example:
showall( box() )
Properties
.height : float
.length : float
.lengthsegs : integer
.width : float
.widthsegs : integer
.mapcoords : boolean
.heightsegs : integer
.realWorldMapSize : boolean
Methods
Events
Constructors
Yep, I have the same thing in a dotNet utilities script that I can call on. Loading it up with all the typical dotNet stuff that you might need like creating points, rectangles, colors and what not.
You can also dump all the interfaces available on the object
try(format "Interfaces:
“
showinterfaces ObjToShow
showinterfaces (superclassof (classof ObjToShow))
)catch()
ahh. thanks… nice addition biddle… BTW Demigod looks amazing… nice work
may as well post my showall function too. I’ve been meaning to for about a year or so anyway… its actually 2 functions, showall and formatProps.
the main difference with this one is with the formatProps function. it not only shows the prop names, it also shows the current value and type and its all auto formatted so that everything is displayed in nice neat columns.
below are results from a teapot: (lines up properly in the listener)
------------------------------------------------------------------------------
MaxObject: $Teapot:Teapot01 @ [-17.392120,28.791763,0.000000]
------------------------------------------------------------------------------
propName: #smooth | value: true | type: BooleanClass
propName: #radius | value: 25.8829 | type: Float
propName: #segs | value: 4 | type: Integer
propName: #mapcoords | value: true | 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
------------------------------------------------------------------------------
formatProps is called in showall so you dont need to call it individually unless you really want to. i tend to just use showall on everything. Here’s the code:
mapped fn formatProps o recursive:false inset:0 maxDepth:2 =
(
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
for i = 1 to inset do format " "
format "MaxObject: %
%" o dashLine
for p in props do
(
for i = 1 to inset do format " "
format "propName: %" p[1]
len = p[2]
for i = len to pMax do format " "
format "|"
for i = 1 to gapSize do format " "
format "value: %" p[3]
len = p[4]
for i = len to vMax do format " "
format "|"
for i = 1 to gapSize do format " "
format "type: %
" p[5]
if recursive AND inset < maxDepth-1 do
(
hasSubProps = try((getPropNames p[3]).count > 0)catch(false)
if hasSubProps do formatProps p[3] recursive:true inset:(inset+1) maxDepth:maxDepth
)
)
format "%" dashLine
)
mapped fn showAll o =
(
if o == undefined do return false
formatProps o
if classof o == dotNetClass OR classof o == dotNetObject then
(
format "--------METHODS--------
"
showMethods o
format "--------EVENTS---------
"
showEvents o
format "---.NET CONSTRUCTORS---
"
dotNet.showConstructors o
)
else if classof o == string do try
(
format "---.NET CONSTRUCTORS---
"
dotNet.showConstructors o
)catch()
true
)