title: show window on menuItem clicked Python Maya
body: <p>I'am new to python scripting using Maya I want to autoload a plugin that I created to display a custom menu in Maya main Window. When clicking the menu item, it shows a window using a function that I create. So the problem: When I run my code simply in Maya interface, it runs correctly but when I put my code in a python file and autoload it, it shows each time a different error :
  Sometimes it shows this error on clicking the menu item the first time it's loaded when opening Maya:</p>
  
  <pre><code># Error: NameError: file &lt;maya console&gt; line 1: name 'createUI' is not defined #
  </code></pre>
  
  <p>And sometimes it shows this error: </p>
  
  <pre><code>// Warning: file: C:/Program Files/Autodesk/MAYA20185/Maya2018/scripts/others/pluginWin.mel line 290: No initializePlugin() or initializePlugin2() function
   // 
  // Error: file: C:/Program Files/Autodesk/MAYA20185/Maya2018/scripts/others/pluginWin.mel line 290:  (userInterface) //
  </code></pre>
  
  <p>This is my code: userInterface.py</p>
  
  <pre><code>import maya.cmds as cmds
  import functools
  import pymel.core as pm
  
  def createUI(pWindowTitle):
      windowID = 'myWindowID'
      if cmds.window(windowID, exists=True):
          cmds.deleteUI(windowID)
      cmds.window(windowID, title=pWindowTitle, sizeable=False, resizeToFitChildren=True)
      cmds.rowColumnLayout(numberOfColumns=3, columnWidth=[(1,75), (2,60), (3,60) ], columnOffset=[(1,'right',3)])
      cmds.text(label='Time Range:')
      startTimeField = cmds.intField(value=cmds.playbackOptions(q=True, minTime=True))
      endTimeField = cmds.intField(value=cmds.playbackOptions(q=True, maxTime=True))
      cmds.text( label='Attribute:' )
      targetAttributeField = cmds.textField( text='rotateY' )
      cmds.separator( h=10, style='none' )
      cmds.separator( h=10, style='none' )
      cmds.separator( h=10, style='none' )
      cmds.separator( h=10, style='none' )
      cmds.separator( h=10, style='none' )
      def cancelCallback(*pArgs):
          if cmds.window(windowID, exists=True ):
              cmds.deleteUI(windowID)
      cmds.button(label='Cancel',command=cancelCallback)
      cmds.showWindow()
  
  def keyFullRotation(pObjectName, pStartTime, pEndTime, pTargetAttribute):
      cmds.cutKey( pObjectName, time=(pStartTime, pEndTime), attribute=pTargetAttribute)
      cmds.setKeyframe( pObjectName, time=pStartTime, attribute=pTargetAttribute, value=0)
      cmds.setKeyframe( pObjectName, time=pEndTime, attribute=pTargetAttribute, value=360)    
      cmds.selectKey( pObjectName, time=(pStartTime, pEndTime), attribute=pTargetAttribute, keyframe=True)    
      cmds.keyTangent( inTangentType='linear', outTangentType='linear' )
  
  MainMayaWindow = pm.language.melGlobals['gMainWindow'] 
  customMenu = pm.menu('TestMenu', parent=MainMayaWindow)
  pm.menuItem(label="menu item 'hihi'", command="createUI('My Title')", parent=customMenu)
  </code></pre>