Refer to your comments
1) I understand what you said and why the value of the points should be generated inside the function. However, if I change my function to
def pointBoundary(iterations, ptA, ptB, ptC):
do I still need to, at least for once, use the random function to generate 3 points before I can call my function?
when I call the recursion, can I just say, for instance:
pointBoundary(10, ptA, ptB, ptC) or pointBoundary(10)
2) I am not clear what do you mean:
"it should be idented under the else statement, so that it is executed only if iterations are not equal to 0"
because I have already idented...what should I change?
3)I successfully created random points and store them in a list.
pts=["ptA","ptB","ptC"]
for i in range (len(pt)):
from random import *
x = uniform(-squareSideLength/2, squareSideLength/2)
y = uniform(-squareSideLength/2, squareSideLength/2)
pts[i] =(x,y)
Is that alright?
** I have extra questions -
any differences if I write "pts[%d]%i" but not "pt[i]" ??
4) How to make sure I offset the line outward but not inward, in relation to the centre of the square??
5) Would using "classes" will help to shortening the script? because I always need to repeat the each steps for A, B, C...but I can't simply use loop...
6) Other questions you haven't answered:
a) Can you run the Serpentine Pavilion Script? I have syntax error with the line "iterations-=i"
b) What does argument type -"boolean" and "linear" mean?
c) What does "break" mean?
d) I can check cmds.command on the python help list, but how about others like "random" commands, those kinds of none cmds. commands?
Thanks.
Hi Alice,
ReplyDeleteSorry it took me so long to reply! Well, better late than never, right? Well, regarding your doubts:
1) Yes, you need to generate once before you call the function for the first time, and then as inside the function you'll be generating new ptA, ptB and ptC, you can call the function just by saying
pointBoundary(i, ptA, ptB, ptC)
and it will use the new values.
2) Ok, probably it was a problem with how the code was being displayed here at the blog. So if you indented, then it should be fine!
3) Hmmm no. It might create the points, but you should change some things. First, the "from random import *" should be executed only once in your whole script, or better yet, only once in a Maya session. Once you execute it once, the random module is already stored in memory and you are free to use its functions (such as uniform()). If you put it inside the loop, it will be imported everytime the loop iterates, which is unnecessary. Second, in oder to put these coordinates in a list, all you need is an empty list. pts should be empty, and not containing these three strings. When you do that, you are actually putting in strings inside of the list which you don't actually need. Then for the loop, you could create a new variable called, let's say, numPoints, and use this values in the range command. Then everytime you generate some numbers, you should use the append command to add it to the former empty pts list. It would look like this:
pts = []
numPoints = 3
for i in range(numPoints):
x = ....
y = ....
pts.append((x,y))
Don't forget also that you always need a Z value in Maya, even if the Z values is always zero.
3.a) It is very different, but for your purposes the second alternative is what you should use. The % sign should be used only when you need to format strings...
4) This is done by testing. Offset with a positive value and then with a negative value, and see which one is the best. I am not sure there is a way to predict that, but it should be consistent for any object.
5) The use of classes doens't always make sense. I guess for your script it could optimize it in some ways, but this problem you describe won't be solved by making it into a class. And still, this problem is fairly easily solved if you think about storing all those values in lists! You can create a list for the curve names, one for the distances, one for the radiuses, one for the circles, and so on, and you'll always know that always the index 0 of all lists go together, all index 1 of all lists go together, and so on. You can even create one big list, with sublists for each object, and inside of these sublists, store all those values. More or less like this:
listA = []
listB = []
listC = []
than make a loop going through each object and execute all those commands only once each iteration. By the end of this loop you should have:
listA = [line, len, ri, circle, tan, off, node, per] # each value referring to object A
listB = [line, len, ri, circle, tan, off, node, per] # each value referring to object B
listC = [line, len, ri, circle, tan, off, node, per] # each value referring to object C
#then put all lists inside of a big list!
bigList = [listA, listB, listC]
6.a) I can run it here without problems!
6.b) Type boolean is an argument which is either True or False (1 or 0). A linear argument is a number, either a float or an integer.
6.c) break is a command which stops the execution of a loop at anytime it is called
6.d) Google is the answer! If you want, for example, to know all commands existent in the random module, or in the math module, for example, simple type in Google "python math" or "python random" (without quotes...) and you should get it very well explained.