PDA

View Full Version : ShowAll() - handy Snibbit


Kramsurfer
09-23-2009, 08:12 PM
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\n"
showProperties ObjToShow
)catch()
try(
format "Methods\n"
showMethods ObjToShow
)catch()
try(
format "Events\n"
showEvents ObjToShow
)catch()
try(
format "Constructors\n"
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

PEN
09-24-2009, 12:12 AM
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.

biddle
09-24-2009, 01:09 AM
You can also dump all the interfaces available on the object

try(format "Interfaces:\n"
showinterfaces ObjToShow
showinterfaces (superclassof (classof ObjToShow))
)catch()

KarlPan
09-24-2009, 09:37 AM
:thumbsup: good !!! I have a problem, but now I can't post

Kramsurfer
09-24-2009, 04:39 PM
ahh. thanks.. nice addition biddle.. BTW Demigod looks amazing... nice work

Gravey
09-24-2009, 05:56 PM
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 = "------------------------------------------------------------------------------\n" -- 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 "\t"
format "MaxObject: %\n%" o dashLine
for p in props do
(
for i = 1 to inset do format "\t"
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: %\n" 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--------\n"
showMethods o
format "--------EVENTS---------\n"
showEvents o
format "---.NET CONSTRUCTORS---\n"
dotNet.showConstructors o
)
else if classof o == string do try
(
format "---.NET CONSTRUCTORS---\n"
dotNet.showConstructors o
)catch()
true
)

CGTalk Moderation
09-24-2009, 05:56 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.