WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 9 votes, 5.00 average. Display Modes
  #1  
Old 10-23-2009, 01:27 PM
sircedric4 sircedric4 is offline
Member
 
Join Date: Aug 2009
Posts: 22
Array, concatenate, multiple path help please

Maybe I'm thick, but I am still learning Python. I am trying to setup multiple paths for different models that I am incorporating into my program. In the past I was doing this the clunky way by introducing a separate variable for each path:

Example:
path1 = viz.add(viz.ANIMATION_PATH) )
path2= viz.add(viz.ANIMATION_PATH) )
path3 = viz.add(viz.ANIMATION_PATH) )
etc...

Then when I wanted to adjust it I would do things like:
path1.speed(1)
path1.loop(viz.CIRCULAR)
path2.speed(1)
path2.loop(viz.CIRCULAR)
path3.speed(1)
path3.loop(viz.CIRCULAR)

Needless to say this in very clunky, and I want to setup a more default program that doesn't have each path spelled out since I won't always know how many paths I am playing with. I am sure there is some way to do this with for (do-loop) statements.

I guess I don't understand why I can't seem to use an array to do this job. I've tried path[0], path[1], etc... but when I goto tweak the path[0].speed it says no such attribute exists. I believe this is because arrays can't be set to do viz.adds or something. I think arrays can only be certain types and what I am trying to do doesn't fall under that type.

Is there a way to concatenate strings in python? (I come from VB where there is that capability) So for example I could
path + 'someinteger' = viz.add(viz.ANIMATION_PATH) )

and then use that same left hand side wherever to change things
(path + 'someinteger' ).speed(1)

I've tried searching for the means to do this all over the internet and I am hoping someone more familiar with python can tell me the easiest way to do what I am trying to do. I just want variables that I can adjust with a do-loop without having to manually add a bunch of numbered variables. This simple capability is really holding me back on several programs, help please.
Reply With Quote
  #2  
Old 10-25-2009, 06:30 AM
IGoudt IGoudt is offline
Member
 
Join Date: Sep 2009
Posts: 20
I would do the following using a list, so that path1 is on index 0 and path n on index n-1

Code:
pathlist = list()

for curNumber in range(maxNumberOfPaths) :

     path = viz.add(viz.ANIMATION_PATH) 
     path.speed(1)
     path.loop(viz.CIRCULAR)
     pathlist.append(path)
The way to concatenate strings in Python is:

'text' + str(otherArgs)',

so 'path' + str(1) would become 'path1'

If you are unsure about the ability of the otherArgs to be casted correctly, you can wrap a try/catch around it.

If you want to call elements in a container by their name, you can use a dictionary.
Reply With Quote
  #3  
Old 10-26-2009, 03:48 AM
IGoudt IGoudt is offline
Member
 
Join Date: Sep 2009
Posts: 20
I forgot to mention that you cannot use operators and functions on the left side of the equals sign.

path + 'someinteger' = viz.add(viz.ANIMATION_PATH) would not work, but

pathDictionary[path + str(someinteger)] = viz.add(viz.ANIMATION_PATH) will.
Reply With Quote
  #4  
Old 10-28-2009, 06:14 AM
sircedric4 sircedric4 is offline
Member
 
Join Date: Aug 2009
Posts: 22
Thanks, the List() thing is what I was missing. I used the basics of what you outlined and got the program to do exactly what I was looking for.

I kept looking for arrays in the python manual and all it kept showing me was dictionary stuff and it wouldn't do what I wanted. I figured someone more familiar with python would be able to point me directly to what I wanted.

Thanks again.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
smoothing a cubic bezier path just alex Vizard 10 04-22-2009 02:07 PM
2D or 3D array help? durf Vizard 1 02-20-2009 11:57 AM
Problems with interaction of vizact.turn and animation path Enlil Vizard 3 11-24-2008 05:23 PM
speed on animation path whj Vizard 8 11-17-2008 08:41 PM
Copy objects in an array to another array Johannes Vizard 3 04-29-2005 03:37 PM


All times are GMT -7. The time now is 08:24 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC