Get the sketches that belong to a child occurrence

Get the sketches that belong to a child occurrence

Joshua.mursic
Advocate Advocate
370 Views
2 Replies
Message 1 of 3

Get the sketches that belong to a child occurrence

Joshua.mursic
Advocate
Advocate

Hello,

 

I am trying to access the sketches that are part of this child occurrence.

Joshuamursic_0-1679003457748.png

 

I was able to get the bRepBodies, but I do not see how to get access to the sketches. Is this possible?

 

Thanks

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

kandennti
Mentor
Mentor
Accepted solution

Hi @Joshua.mursic .

 

When the attached f3d file is activated and the following script is executed, the coordinate values of the origin of the red arrow sketch are displayed.

1.png

 

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

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

        targetOcc: fusion.Occurrence = root.allOccurrences.itemByName('level3:1')
        targetComp: fusion.Component = targetOcc.component
        nativeSketch: fusion.Sketch = targetComp.sketches[0]
        proxySketch: fusion.Sketch = nativeSketch.createForAssemblyContext(targetOcc)

        msgLst = [
            f'nativeSketch.originPoint:{nativeSketch.originPoint.worldGeometry.asArray()}',
            f'proxySketch.originPoint:{proxySketch.originPoint.worldGeometry.asArray()}',
            '****',
            f'nativeSketch.sketchPoints[0]:{nativeSketch.sketchPoints[0].worldGeometry.asArray()}',
            f'proxySketch.sketchPoints[0]:{proxySketch.sketchPoints[0].worldGeometry.asArray()}',
        ]
        ui.messageBox('\n'.join(msgLst))

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

 

 

0 Likes
Message 3 of 3

Joshua.mursic
Advocate
Advocate
Thank you very much @kandennti, that's exactly what I needed.