Get Point values from ObjectCollection of Point3D

Get Point values from ObjectCollection of Point3D

rocco.mayr
Enthusiast Enthusiast
661 Views
2 Replies
Message 1 of 3

Get Point values from ObjectCollection of Point3D

rocco.mayr
Enthusiast
Enthusiast

In my script I added some points to a ObjectCollection

segmentPoints = adsk.core.ObjectCollection.create()
segmentPoints.add(adsk.core.Point3D.create(centerX, centerY, centerY))

 

How do I get the x, y, z values later on?

posX = segmentPoints.item(0).getData().x will give an error:

AttributeError: 'list' object has no attribute 'x'

0 Likes
Accepted solutions (2)
662 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @rocco.mayr .

 

Point3D is stored in the ObjectCollection.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.fusion.Application = adsk.core.Application.get()
        ui = app.userInterface

        # create points
        pos = [
            [1,2,3],
            [4,5,6],
            [7,8,9],
        ]

        points = []
        for p in pos:
            points.append(adsk.core.Point3D.create(p[0],p[1],p[2]))

        # set ObjectCollection
        segmentPoints = adsk.core.ObjectCollection.create()
        for p in points:
            segmentPoints.add(p)

        # dump
        for idx, pnt in enumerate(segmentPoints):
            p = adsk.core.Point3D.cast(pnt)
            app.log(f'index[{idx}] - X:{p.x} Y{p.y} Z{p.z}')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

1.png

 

0 Likes
Message 3 of 3

rocco.mayr
Enthusiast
Enthusiast
Accepted solution
That's the line I was looking for, THX

 

posX = adsk.core.Point3D.cast(segmentPoints.item(0))

 

0 Likes