title: Python for Maya, solar system generator
body: <p>The end goal is to create a solar system that is semi-randomly generated, using polySphere and Curves, assigning colours, etc.
  Right now I've got the background size (a polyPlane with four different options in an optionsMenu) sorted out, and the next step is adding in pointLights to illuminate the background like a starry backdrop. But in trying to run the pointLights through a for loop to duplicate them results in the polyPlane getting duplicated, and not the light.</p>
  <p>I am using Maya 2022.4, on Windows 10.</p>
  <pre><code>import maya.cmds as cmds
  import random
  from random import randint
  
  star_count = 10
  
  def solar_UI(): 
  
  #delete previous iteration of UI
      if cmds.window(&quot;MainWindow&quot;, exists = True):
          cmds.deleteUI(&quot;MainWindow&quot;)
  
  #UI Window buttons and creation
      cmds.window(&quot;MainWindow&quot;, t = &quot;Custom Solar System Generator&quot;, w = 500, h = 700, mnb = False, mxb = False, sizeable = False)
      cmds.columnLayout(&quot;MainLayout&quot;, w = 300, cal = ('center'), adj = False, en = True)
      cmds.rowColumnLayout(nc = 2)
      
  #starfield background     
      cmds.optionMenu(&quot;BackgroundCreationList&quot;, w = 250, label = &quot;Polygon Selection:&quot;)
      cmds.menuItem(label = &quot; &quot;)
      cmds.menuItem(label = &quot;Small&quot;)
      cmds.menuItem(label = &quot;Medium&quot;)
      cmds.menuItem(label = &quot;Large&quot;)
      cmds.menuItem(label = &quot;XL&quot;)
  
      cmds.button(&quot;Create_Background&quot;, l = &quot;Create&quot;, w = 150, align = 'middle', c = BackgroundCreation)
      cmds.setParent('..')    
      
      cmds.separator(h = 2, en = True)
      
  #rename star
      cmds.rowColumnLayout(nc = 3)
      cmds.text(l = &quot;Star name:&quot;, w = 75)
      star_text = cmds.textField('star_name', w = 100, pht = 'Type Here')    
      cmds.button(l = &quot;Rename&quot;, w = 100, c = rename_star)
      cmds.setParent('..')
  
  #Select and delete all
      cmds.columnLayout()
      cmds.button(&quot;Delete&quot;, l = &quot;Delete&quot;, w = 200, align = 'middle', bgc = [0.5, 0, 0], c = DeleteButton)
      cmds.setParent('..')   
  
      cmds.showWindow(&quot;MainWindow&quot;)
  
  ##
  ## Define Functions
  ##
  
  #starfield background creation and sizes
  def BackgroundCreation(*args):
      cmds.shadingNode('pointLight', asLight = True)
      bgValue = cmds.optionMenu(&quot;BackgroundCreationList&quot;, q = True, v = True)
      if bgValue == &quot;Small&quot;: 
          cmds.polyPlane(n = &quot;Small_Background&quot;, w = 75, h = 75)
          for pointLight in cmds.ls(sl = True):
              for i in range(10):
                  cmds.duplicate(pointLight, rc = True, ic = True, st = True)[0]
                  for axis in ['.tx', '.tz']:
                      cmds.setAttr(pointLight + axis, random.uniform(-15,15))
                      cmds.setAttr(pointLight + '.ty', 3)
      elif bgValue == &quot;Medium&quot;:
          cmds.polyPlane(n = &quot;Medium_Background&quot;, w = 200, h = 200)
      elif bgValue == &quot;Large&quot;:
          cmds.polyPlane(n = &quot;Large_Background&quot;, w = 500, h = 500)
      elif bgValue == &quot;XL&quot;:
          cmds.polyPlane(n = &quot;XL_Background&quot;, w = 1000, h = 1000)
  
  #star rename function
  def rename_star():
      for obj in cmds.ls(sl = True):
          star_name = cmds.textField(obj, q = True, text = True)
          cmds.rename(obj, star_name)
  
  #change colour, 10 selections
  #def colourChange():
  #    if cmds.getAttr('pSphere1.color') == 0: #Blue
  #        cmds.polyColorPerVertex(r = 0.159, g = 0.3811, b = 0.86, a = 1, cdo = True)
  #            
  #    elif cmds.getAttr('pSphere1.color') == 1: #Red
  #        cmds.polyColorPerVertex(r=.86,g=.159,b=.3811,a=1, cdo = True)
  #            
  #    elif cmds.getAttr('pSphere1.color') == 2: #Green
  #        cmds.polyColorPerVertex(r = 0.3811, g = 0.86, b = 0.159, a = 1, cdo = True)
  #cmds.scriptJob(attributeChange=['pSphere1.color',colorChange])
  
  #delete all function
  def DeleteButton(*args):
      for obj in cmds.ls(l = True):
          cmds.select(all = True)
          cmds.delete()
      
  solar_UI()
  
  
  #
  ## Alternate code, just in case
  #
  
  #        for point in range(star_count):
  #            pointy  = cmds.pointLight(intensity = 10, decayRate = 2, edit = True, rgb = [1, 1, 0])
  #            cmds.setAttr(pointy + '.ry', -90)
  #            cmds.setAttr(pointy + '.ty', random.uniform(3, 15))
  #            cmds.setAttr(pointy + '.tx', random.uniform(-75, 75))
  #            cmds.setAttr(pointy + '.tz', random.uniform(-75, 75))
  #            cmds.setAttr(pointy + '.useDepthMapShadows', 2)
  
  </code></pre>