<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Project sketch curves from a sketch in one occurrence to new sketch in a different occurrence. in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10804866#M7288</link>
    <description>&lt;P&gt;You were so close.&amp;nbsp; Here's a modified version of your code where the sketch and face are coming from selections.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def run(context):
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui: adsk.core.UserInterface = app.userInterface

        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent

        selSketch = ui.selectEntity('In the browser, select the sketch to project.', 'Sketches')
        sourceSketch: adsk.fusion.Sketch = selSketch.entity

        selFace = ui.selectEntity('Select the face to project to', 'Faces')
        face: adsk.fusion.BRepFace = selFace.entity

        faceComp = face.nativeObject.body.parentComponent
        faceOcc = face.assemblyContext
        faceSketch: adsk.fusion.Sketch = faceComp.sketches.addWithoutEdges(face.nativeObject)
        targetSketch = faceSketch.createForAssemblyContext(faceOcc)

        # Project each of the sketch curves.
        for curve in sourceSketch.sketchCurves:
            targetSketch.project(curve)
    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 06 Dec 2021 22:41:48 GMT</pubDate>
    <dc:creator>BrianEkins</dc:creator>
    <dc:date>2021-12-06T22:41:48Z</dc:date>
    <item>
      <title>Project sketch curves from a sketch in one occurrence to new sketch in a different occurrence.</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10800062#M7285</link>
      <description>&lt;P&gt;I am trying to write a script to project sketch curves in an occurrence sketch by clicking on the sketch name in the browser.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want them to project to a new sketch on a face of a different occurrence I selected.&lt;/P&gt;&lt;P&gt;I can't figure out how to get the fullPathName of the original sketch parent occurrence.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 22:35:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10800062#M7285</guid>
      <dc:creator>brad.bylls</dc:creator>
      <dc:date>2021-12-03T22:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: Project sketch curves from a sketch in one occurrence to new sketch in a different occurrence.</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10802161#M7286</link>
      <description>&lt;P&gt;The trick is having references to both the source and target sketches in the context of the top-level assembly.&amp;nbsp; Here's a simple script that demonstrates this using the attached design.&amp;nbsp; Of course, how you get the sketches will probably be different because of the workflow of your command.&amp;nbsp; It's even easier if the user is selecting things because the selection will already be a proxy in the context of the top assembly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def run(context):
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui: adsk.core.UserInterface = app.userInterface

        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent

        #### Get the source sketch in the context of the assembly

        # Get the occurrence that contains the source sketch.
        sourceOcc = root.occurrences.itemByName('Source:1')

        # Get the sketch from the referenced component. This results in
        # losing the assembly context.
        sourceSketch = sourceOcc.component.sketches.itemByName('Source')

        # Create a proxy of the sketch so we have it in assembly context.
        sourceSketch = sourceSketch.createForAssemblyContext(sourceOcc)

        #### Get the target sketch in the context of the assembly

        # Get the occurrence that contains the source sketch.
        targetOcc = root.occurrences.itemByName('Target:1')

        # Get the sketch from the referenced component. This results in
        # losing the assembly context.
        targetSketch = targetOcc.component.sketches.itemByName('Target')

        # Create a proxy of the sketch so we have it in assembly context.
        targetSketch = targetSketch.createForAssemblyContext(targetOcc)

        # Project each of the sketch curves.
        for curve in sourceSketch.sketchCurves:
            targetSketch.project(curve)
    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2021 17:24:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10802161#M7286</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2021-12-05T17:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Project sketch curves from a sketch in one occurrence to new sketch in a different occurrence.</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10803584#M7287</link>
      <description>&lt;P&gt;Thanks Brian.&lt;/P&gt;&lt;P&gt;The problem is, I don't know the name of the source sketch occurrence (Source:1) or the name of the sketch (Source) that the user will select.&lt;/P&gt;&lt;P&gt;I also don't know the name of the occurrence the new sketch will be on.&lt;/P&gt;&lt;P&gt;I get the correct components (A Plate and B Plate), but not the occurrence name (A Plate:1 and B Plate:1).&lt;/P&gt;&lt;P&gt;My code below:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;selFace: adsk.fusion.BRepFace = _inputSelectFace.selection(0).entity
selFaceComp = selFace.nativeObject.body.parentComponent  ## A Plate (correct)
selSketch: adsk.fusion.Sketch = _inputSelectSketch.selection(0).entity
selSketchComp = selSketch.nativeObject.parentComponent  ## B Blate (correct)
selSketchComp = selSketchComp.occurrences  ## This line comes up 'count 0' no occurrences? (a test)
selSketchCompOcc = adsk.fusion.Components.itemByName(selSketchComp.name)  ### Problem line
newSketch: adsk.fusion.Sketch = selFaceComp.sketches.addWithoutEdges(selFace.nativeObject)
sketchPoints = selSketchComp.sketches.itemByName(selSketch.name).sketchPoints
sketchCurves = selSketchComp.sketches.itemByName(selSketch.name).sketchCurves

[newSketch.project(p.createForAssemblyContext(selSketchCompOcc)) for p in sketchPoints]
[newSketch.project(c.createForAssemblyContext(selSketchCompOcc)) for c in sketchCurves]&lt;/LI-CODE&gt;&lt;P&gt;Been messing with this for about a week now.&lt;/P&gt;&lt;P&gt;Probably just having senior moments, but still frustrating me.&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 13:36:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10803584#M7287</guid>
      <dc:creator>brad.bylls</dc:creator>
      <dc:date>2021-12-06T13:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Project sketch curves from a sketch in one occurrence to new sketch in a different occurrence.</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10804866#M7288</link>
      <description>&lt;P&gt;You were so close.&amp;nbsp; Here's a modified version of your code where the sketch and face are coming from selections.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def run(context):
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui: adsk.core.UserInterface = app.userInterface

        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent

        selSketch = ui.selectEntity('In the browser, select the sketch to project.', 'Sketches')
        sourceSketch: adsk.fusion.Sketch = selSketch.entity

        selFace = ui.selectEntity('Select the face to project to', 'Faces')
        face: adsk.fusion.BRepFace = selFace.entity

        faceComp = face.nativeObject.body.parentComponent
        faceOcc = face.assemblyContext
        faceSketch: adsk.fusion.Sketch = faceComp.sketches.addWithoutEdges(face.nativeObject)
        targetSketch = faceSketch.createForAssemblyContext(faceOcc)

        # Project each of the sketch curves.
        for curve in sourceSketch.sketchCurves:
            targetSketch.project(curve)
    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 22:41:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10804866#M7288</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2021-12-06T22:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Project sketch curves from a sketch in one occurrence to new sketch in a different occurrence.</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10811618#M7289</link>
      <description>&lt;P&gt;Thanks Brian.&lt;/P&gt;&lt;P&gt;That did it.&lt;/P&gt;&lt;P&gt;Works great.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 12:47:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/project-sketch-curves-from-a-sketch-in-one-occurrence-to-new/m-p/10811618#M7289</guid>
      <dc:creator>brad.bylls</dc:creator>
      <dc:date>2021-12-09T12:47:40Z</dc:date>
    </item>
  </channel>
</rss>

