ConStructOr

14 votes
Version: 
0.4
Date Updated: 
01/05/2011

This is a WIP function collection to make the working with structs in maxScript easier.
It's kinda inspired by: 1.Garp's Primitive maker in that you can quickly reDefine structs and 2.the lack of functions provided by maxScript.

The only functions in it so far are:

  • addVar - add a property to a struct
  • gotProperty - the equivalent of hasProperty or isProperty functions for a struct

Let me know what kind of functions you'd like to see in here

Additional Info: 
  1. (
  2. clearlistener()
  3.  
  4. struct constructorStr
  5. (
  6. addVar = fn AddVar str var2Add val2Add name isGlobal:false =
  7. (
  8. local name = if classOf name == string then name else "conStructorTempStr"
  9. local propNames = getPropNames str
  10. local temp = str()
  11. local props = for prop in propNames collect getProperty temp prop
  12.  
  13. local stri = ""
  14.  
  15. for i = 1 to propNames.count do
  16. (
  17. case i of
  18. (
  19. 1 :
  20. (
  21. stri += "struct "+ name + "(\n"
  22. stri += propNames[i] as string + " = " + props[i] as string + ",\n"
  23. )
  24. default :
  25. (
  26. stri += propNames[i] as string + " = " + props[i] as string + ",\n"
  27. )
  28. (propNames.count) :
  29. (
  30. stri += propNames[i] as string + " = " + props[i] as string + ",\n"
  31. stri += var2Add as string + " = " + val2Add as string + ")\n"
  32. )
  33. )
  34. )
  35.  
  36. local tStruct = if not isGlobal then copy (execute stri) else execute stri
  37. if not isGlobal do execute (name + " = undefined")
  38.  
  39. return tStruct
  40. ),--END addVar FN
  41.  
  42. gotProperty = fn gotProperty str propName =
  43. (
  44. local propNames = for o in (getPropNames str) collect o as string
  45. findItem propNames (propName as string) != 0
  46. )--END gotProperty FN
  47. )
  48. global constructor = constructorStr()
  49.  
  50.  
  51. /***************************************************************************************************************/
  52. /***************************************************************************************************************/
  53.  
  54. struct personC
  55. (
  56. age, sex, job
  57. )
  58.  
  59. local personClass = constructor.AddVar personC #skills #() "humanClass"
  60.  
  61. local raphael = personClass age:23 sex:#male job:#TechnicalArtist skills:#(#MaxScript, #WorkflowImprovement, #Ect)
  62.  
  63. print raphael
  64.  
  65. format "personClass.gotProperty #skills % \n" (constructor.gotProperty personClass #skills)
  66. format "personClass.gotProperty #height % \n" (constructor.gotProperty personClass #height)
  67.  
  68. OK
  69. )--END local