I am writing an add-on for some softwate, using its API. What i need to do is to extract necessary data. I use 'FOR' to go thought API classes. Each object has properties: index (from 0), type (Lin, Ptp, and some others), and value. Going through list of objects, I am interested in two types of objects - those that have type 'Lin' or 'Ptp'; so a few conditions should be met:
As to Lin type:
- if there is some Ptp before Lin (there may be other objects of other types between them, though), Lin gets Ptp's value [Ptp....Lin].
- if there is some other Lin before Lin (there may be other objects of other types between them, though), Lin gets that previous closest Lin's value [Lin....Lin].
- if there is neither Lin nor Ptp before Lin (there may be other objects of other types between them, though), Lin gets value "0" [...Lin].
As to Ptp type, it always gets its own value
As i am a beginner in Python, my thoughs are mixed now and i cannot come up with appropriate algorithm.
I was thinking it should be somthing like this:
for object in obects:
If object.type == Ptp:
...object gets its own value
elif object.type == Lin:
...
Here, there should be other 3 conditions according to [...Lin] or [Lin...Lin] or [Ptp...Lin]