Reading points in a sketch

Reading points in a sketch

dozerdroid
Enthusiast Enthusiast
504 Views
2 Replies
Message 1 of 3

Reading points in a sketch

dozerdroid
Enthusiast
Enthusiast

Hi folks, I'm trying to read the coordinates for some points in a sketch after the user adjusted their location in the drawing but I'm not really getting the values I expect, so i wrote a little test below which should get the first two points in the first sketch?  What i really want is the float values for the x , y , z for these points, any help welcome. Khim 

 

 

design = g_app.activeProduct
actComp = design.activeComponent
sketchesObj = actComp.
sketch0 = sketchesObj.item(0)
# get the first point in the first sketch
x1 = sketch0.sketchPoints[0].worldGeometry.x
y1 = sketch0.sketchPoints[0].worldGeometry.y
z1 = sketch0.sketchPoints[0].worldGeometry.z
# get the second point in the first sketch
x2 = sketch0.sketchPoints[1].worldGeometry.x
y2 = sketch0.sketchPoints[1].worldGeometry.y
z2 = sketch0.sketchPoints[1].worldGeometry.z

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

kandennti
Mentor
Mentor
Accepted solution

Hi @dozerdroid .

 

sketchPoints[0] is the origin point of the sketch.

Try creating a sketch in a new document, drawing some sketch points, and then running the following script.

# Fusion360API Python script

import traceback
import adsk.core
import adsk.fusion

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        rootComp: adsk.fusion.Component = des.rootComponent

        skt: adsk.fusion.Sketch = rootComp.sketches[0]
        sktPoints: adsk.fusion.SketchPoints = skt.sketchPoints
        for idx, sktPoint in enumerate(sktPoints):
            app.log(f'Index:{idx} _ isOrigin:{sktPoint == skt.originPoint}')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 3 of 3

dozerdroid
Enthusiast
Enthusiast

Thank you, most helpful. 

0 Likes