[Closed] isClassCreatable??
Is there a function like this where I can pass a class and see if I can create it?
I don’t think so but you can easily write one. Just use exceptions and if it errors out return false or something like that and if it works return the class you are testing. Here is a read about exceptions in maxscript:
Thanks, I’m aware of exceptions, that is what I’m doing now but I like to avoid it when possible.
Here is some test code. It will open every dialog for every controller.
classStr=stringStream ""
showClass "*:*Controller*" to:classStr--Get all the controller classes.
seek classStr 0
while not eof classStr do
(
r=readLine classStr
strAr=filterString r ":"
conClass=try(execute ((trimRight (trimLeft strAr[1]))+"()"))catch()
if conClass!=undefined do displayControlDialog conClass ""
)
[left]<maxclass>.creatable
[/left]
[left]Read-only Boolean property. Returns true if the class is flagged as being creatable. This property returning true does not guarantee that the class is really creatable
[/left]
[left]
[/left]
[left]
[/left]
Maybe this is not good example for testing correctness of “creatable” property but…
anyway I tried to use this fn for some superclasses
/*
sClass argument:
geometryClass
shape
light
helper
SpacewarpObject
System
material
texturemap
FloatController
Point3Controller
Point4Controller
PositionController
QuatController
RotationController
ScaleController
Matrix3Controller
MorphController
MasterBlockController
MasterPointController
*/
fn checkIsReallyCreatable sClass =
(
local notReallyCreatable = for i in sClass.classes where i.creatable collect i
local reallyCreatable = for i in sClass.classes where (try(i();true)catch(false)) collect i
for i = 1 to notReallyCreatable.count where findItem reallyCreatable notReallyCreatable[i] == 0 do
format "% is not creatable
" notReallyCreatable[i]
)
checkIsReallyCreatable FloatController
Thanks Denis, I knew there had to be something. I will test to see where it fails.
This property returning true does not guarantee that the class is really creatable
class ! don’t you just love stuff like that, and whats the betting it will fail on just that bit you need it for !
Interestingly enough, at least in my class where I’m setting up a UI to deal with controllers when the class can’t be created but returned true on the test it simply returns undefined when created and doesn’t throw an error. At least that is a good thing.