CodeX

Download codeX.zip

web, webfuncs

I wrote this script to allow writing Python code online, I focused it to work for Maya Python codes, so it also detects the maya.cmds functions and directly creates a link to the Maya documentation. Originally I wrote it for 3dbunk but it came to be also useful here :).

I've some more functionalities in mind and a MEL syntax management may come soon ! Also write it with CSS3 will be good, maybe implement jQuery ?

The function comes with a css file which must be in the same folder as the script

Here is a simple example :

CodeX example
select
def codeXtest(var1, var2):
  for i, v in enumerate(var1):
    if i % 2 == 0:
      yield v
    else:
      cmds.warning('Captain ! We hit %s' % v)
      
if '__name__' == __main__:
  # means script is executed directly
  obj = cmds.listRelatives(cmds.ls(sl=True))
  detect = 1 if len(obj)==0 else 0
  codeXtest(obj, detect)

There is different way to call the code, here are examples ;

Simple :

1
cmds.listRelatives(cmds.ls(sl=True))
createCodeX("cmds.listRelatives(cmds.ls(sl=True))")

With title :

Awesome
1
cmds.listRelatives(cmds.ls(sl=True))
createCodeX("cmds.listRelatives(cmds.ls(sl=True))", "Awesome")

With title and Select button :

Awesome
select
1
cmds.listRelatives(cmds.ls(sl=True))
createCodeX("cmds.listRelatives(cmds.ls(sl=True))", "Awesome", true)

Without header and without lines' number :

cmds.listRelatives(cmds.ls(sl=True))
createCodeX("cmds.listRelatives(cmds.ls(sl=True))", "", false, false)

With external file and title :

hit
1
2
3
4
5
6
def codeXtest(var1, var2):
  for i, v in enumerate(var1):
    if i % 2 == 0:
      yield v
    else:
      cmds.warning('Captain ! We hit %s' % v)
createCodeX(file_get_contents("hit.py"), "hit")

If you have any questions... =)