Sun, Jan 26, 6:51 PM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Dec 02 3:16 pm)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: Working w/ a 2 column array?


z ( ) posted Sat, 02 May 2015 at 11:07 AM · edited Thu, 01 August 2024 at 3:42 PM

This is my first time using a two column array.

I think I’ve successfully built an array where the first column is one actor, and the second column is a related actor.  Now I want to loop through the list and set the parent of the first actor to the second actor. 

But I don’t know what the syntax would be to refer to the two columns of my list.

Something like this:

ActorList =[]

ActorList.append ([actor1,actor2])

For EachActor in ActorList:

actor1.SetParent(actor2)  ----- of course that is not the right syntax, what would be?

 

 

 

 

 

 

 

 

 


structure ( ) posted Sat, 02 May 2015 at 1:09 PM · edited Sat, 02 May 2015 at 1:23 PM
Forum Coordinator

This should work

ActorList=[(1,2),(3,4)] actor=ActorList[0][0]

actor.SetParent(ActorList[0][1])

or

ActorList[0][0].SetParent(ActorList[0][1])

Locked Out


z ( ) posted Sat, 02 May 2015 at 1:23 PM

Thanks, Struct.

That's very close to what I read online but not quite an answer to my question. Your answer assumes that I know I am on row 0 and I know how many rows there are. I won't. I want to loop.

my question is:

During a looping process how can I refer to the CURRENT row, column 1 and 2?

maybe its: 

For EachActor in ActorList:

    [EachActor].[0]SetParent([EachActor].[1])


structure ( ) posted Sat, 02 May 2015 at 1:29 PM · edited Sat, 02 May 2015 at 1:32 PM
Forum Coordinator

Yes that would work
except your point is in the wrong place.

for EachActor in list:

    EachActor[0].SetParent(EachActor[1])

Locked Out


z ( ) posted Sat, 02 May 2015 at 3:29 PM

Ah, and no brackets around EachActor got it,

(I was using SQL bracketing [table].[field])

 


bagginsbill ( ) posted Sat, 02 May 2015 at 4:16 PM · edited Sat, 02 May 2015 at 4:17 PM

I always go for less typing. The iterator can split your pairs for you.

for a, b in yourlist:

   a.SetParent(b)


Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)


bagginsbill ( ) posted Sat, 02 May 2015 at 4:20 PM · edited Sat, 02 May 2015 at 4:22 PM

Note:
If you were starting with two separate lists to begin with, you can skip making the list of pairs. The built-in function "zip" will iterate over two or more lists, giving you parallel elements from each - kind of like a zipper bringing the teeth from the two sides together.

for p, c in zip(listOfParents, listOfChildren):

    p.SetParent(c)


Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)


structure ( ) posted Sun, 03 May 2015 at 5:52 AM
Forum Coordinator

Thanks BB, I will have to remember that.

Locked Out


Privacy Notice

This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.