Thanks !   :) 

On Thursday, September 14, 2017 at 5:02:02 PM UTC-7, Simon Anderson wrote:
>
> Hey, the only thing that looks a bit suspect to me is the way you are 
> setting a variable that is outside of the method. The scope of the variable 
> may be incorrect.
>
> Can I suggest that if everything runs correctly in your makestairs() then 
> you return True, and then check against the returned variable. Bit nicer 
> then passing values to and from different method scopes.
>
>     if stairs >= 1:
>         checkTest = makestairs()
>         
>     if checkTest: 
>         distributeStairs()
>
>
> Also noticed that you are setting checkTest over a hundred times as you 
> have it running in the loop, maybe move it out of the loop. So that it only 
> gets run once all the stairs are built. I would also recommend passing 
> values into a method, instead of just accessing them from a different 
> scope, this can result in bugs, and it a bit ugly.
>
> def makestairs(staris)
>     # code here
>
> def distributeStairs(stairs):
>      # code here
>
> if checkTest: 
>     distributeStairs(stairs)
>
> I hope that helps
>
>
> On Friday, 15 September 2017 08:56:17 UTC+10, jettam wrote:
>>
>> I am trying to write a function that will first make a spiral staircase, 
>> and then distribute the staircase randomly.  I can get this script to 
>> generate only one spiral staircase, but it stops there. I can't get it to 
>> duplicate and distribute multiples of these. I have attached a logic path 
>> that I think the script should follow A,B,C,D (see attached image) Am I 
>> missing something ? 
>>
>>
>> <https://lh3.googleusercontent.com/-KJqfSpoFRQE/WbsIvjelpmI/AAAAAAABOsw/CaX0WaGDW1sLSNXCD9I8ME1lURLocWUwgCLcBGAs/s1600/Capture.JPG>
>>
>>
>> Here is the code:
>> import maya.cmds as mc
>> import random
>>
>> def distributeObjects(stairs=None):
>>     ''' This will make and randomly distribute a spiralStaircase '''
>>     
>>     checkTest = 0
>>     
>>     def makestairs():
>>         ''' first make one spiral staircase '''
>>         # make a dictionary
>>         steps = {'name':'Step','slide':5,'rotations':10,'spacing':1,
>> 'stepDepth':2,'stepHeight':.75} 
>>         stepName=steps.get('name')
>>         # make masterGroup
>>         groupAllSteps = mc.group(name="Group"+stepName+"s", empty=True)
>>         for x in range (0,100):  
>>             #make stairs
>>             # make step
>>             stepObj = mc.polyCube(name=stepName+"#", w=5, h=steps.get(
>> 'stepHeight'), d=steps.get('stepDepth'), ch=0)
>>             # make group
>>             stepGrp = mc.group(empty=True, name=stepName+'_Grp#')
>>             # parent stepObj to stepGrp
>>             mc.parent(stepObj, stepGrp)
>>             # rotate stepGrp
>>             mc.xform(stepGrp, ro=(0,(steps.get('rotations')*x),0))
>>             # transform stepObj
>>             mc.xform(stepObj[0], t=(steps.get('slide'),steps.get(
>> 'stepHeight')*steps.get('spacing')*x,0))
>>             # parent stepObj to masterGroup 
>>             mc.parent(stepObj, groupAllSteps)
>>             # delete stepGrp
>>             mc.delete(stepGrp)
>>             checkTest = 1
>>                         
>>     def distributeStairs():
>>         ''' duplicate the pre-made spiral staircase X amount of times, 
>> and randomly distribute them '''
>>         for i in range (stairs): 
>>             trX = random.uniform(-30,30)
>>             trY = random.uniform(-30,30)
>>             trZ = random.uniform(-30,30)
>>             newGroup = mc.duplicate(GroupSteps,name=GroupSteps+i)
>>             mc.setAttr(newGroup+".translate",trX,trY,trZ,type='double3')
>>
>>     if stairs >= 1:
>>         makestairs()
>>         
>>     if checkTest == 1: 
>>         distributeStairs()
>>
>>
>> distributeObjects(3)
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/edd70e60-7403-4874-9cd6-3d6038333416%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to