Message 1 of 5

Not applicable
03-25-2021
02:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm not very used to Python, but as I understand, for loops can easily be performed using a variable as iterator.
I'm wondering why I'm having an error in case of iterations in a adsk.core.ObjectCollection:
# data is an array of 3-elements arrays which contains
# floating 3d points coordinates each
# sketch is a sketch ;-)
points = adsk.core.ObjectCollection.create()
for pt in data:
points.add(adsk.core.Point3D.create(pt[0], pt[1], pt[2]))
# The previous for loop works just fine and let's say it adds n points
for point in points:
sketch.sketchPoints.add(pp)
# This second for loops give me the following error:
# Exception has occurred: IndexError
# The index (n) is out of range.
# I solved like this:
for i in range(len(points)):
sketch.sketchPoints.add(points[i])
# but I can't figure out why...
Obviously it's me, I just started using python yesterday (actually yesterday), but I really can't understand the problem!
Thanks
Luca
Solved! Go to Solution.