Project points into sketch

Project points into sketch

brad.bylls
Collaborator Collaborator
598 Views
2 Replies
Message 1 of 3

Project points into sketch

brad.bylls
Collaborator
Collaborator

Hello all, I am trying to project points from one sketch into another.

sketches = activeComp.sketches
newSketch = sketches.addWithoutEdges(xyPlane) # User selected surface
newSketch.name = strResult # strResult = 'Selected Sketch Name'
sketchPoints = moldBaseComp.sketches.itemByName(strResult).sketchPoints
newSketch.project(sketchPoints) # Line 57 (error)

Then I get the error message

Untitled.png

I've tried several different things from the forum and help but can't figure it out.

Help please.

Brad Bylls
0 Likes
Accepted solutions (1)
599 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor

Hi @brad.bylls .

 

Probably the proxy is not getting enough.

Here is the result of running the following sample with the attached file.

 

# 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
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        moldBaseOcc: adsk.fusion.Occurrence = root.occurrences.itemByName('MoldBase:1')
        moldBaseComp: adsk.fusion.Component = moldBaseOcc.component
        moldBaseSketchName: str = 'Reference Sketch'

        resultOcc: adsk.fusion.Occurrence = root.occurrences.itemByName('Result:1')
        resultComp: adsk.fusion.Component = resultOcc.component
        resultSketchName: str = 'Result Sketch'
        resultxyPlane: adsk.fusion.ConstructionPlane = resultComp.xYConstructionPlane



        # create sketch
        sketches = resultComp.sketches
        newSketch = sketches.addWithoutEdges(resultxyPlane)
        newSketch.name = resultSketchName

        # create proxy
        newSketchProxy = newSketch.createForAssemblyContext(resultOcc)

        # get reference sketch
        moldBaseSketch: adsk.fusion.Sketch = moldBaseComp.sketches.itemByName(moldBaseSketchName)

        # create proxy
        referenceSketchProxy = moldBaseSketch.createForAssemblyContext(moldBaseOcc)

        # execute project
        sketchPoints = referenceSketchProxy.sketchPoints
        [newSketchProxy.project(p) for p in sketchPoints]

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

 

1.png

 

For more information about proxies, please click here.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A 

Message 3 of 3

brad.bylls
Collaborator
Collaborator
Accepted solution

Thanks  

I only needed to change the last line to

 [newSketchProxy.project(p) for p in sketchPoints]

 

Brad Bylls
0 Likes