Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy does name error occur when module is run by importing but not when run from script editor in maya
    text
    copied!<p>all i am trying is to is add more items to dictionary and populate with second button if necessary!!! everything goes fine, on running code from maya script editor by clicking on the blue play button but if i import this script import funtest funtest.main()</p> <p>the window loads up fine but i get error on clicking either of the buttons ... So please tell me why is their a difference between executing the code from script editor and the other one by importing..</p> <p>it shouild be same or if it is what is wrong with my logic ?</p> <pre><code>import maya.cmds as cmds dic={} print("dictionary is empty",dic) def main(): inst=btnUI() inst.create() class btnUI(object): def __init__(self, winName="winTheWindow"): self.winTitle = "The Window" self.winName = winName def create(self): if cmds.window(self.winName, exists=True): cmds.deleteUI(self.winName) dic['item1']='item1value' dic['item2']='item2value' cmds.window(self.winName, title=self.winTitle) self.mainCol = cmds.columnLayout( adjustableColumn=True ) self.btnA = cmds.button( label='Press Me - External Func',c='outsideFunc(dic)' ) self.btnb = cmds.button( label='Populate more items',c='populateDic()' ) cmds.showWindow( self.winName ) cmds.window(self.winName, edit=True, widthHeight=[250,75]) def populateDic(): dic['item3']='item3value' dic['item4']='item4value' dic['item5']='item5value' def outsideFunc(dicItems): print("Outside function, called from inside a class function") print(dicItems) if __name__ == '__main__': main() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload