<?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: Struggling to get script-generated sketch to line up with existing sketch in design in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12456935#M2273</link>
    <description>&lt;P&gt;What I am trying to do is pretty simple. I want to programmatically generate some geometry and place it in its own sketch that is aligned with an existing sketch.&amp;nbsp;Then I want to use that geometry as a cutting tool.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically, I am creating my own custom patterns to cut the vertical sides of 3D printed objects. The patterns are self-supporting so that no support material is needed. The purpose is for creating lighter parts that require less filament to make, and thus cost less to produce and print faster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can achieve the result manually by drawing in Fusion and then repeating as a pattern, but it is very tedious. Doing it in a script will save me countless hours and allow me to quickly iterate through different options.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Dec 2023 22:25:22 GMT</pubDate>
    <dc:creator>darrenPH8TL</dc:creator>
    <dc:date>2023-12-21T22:25:22Z</dc:date>
    <item>
      <title>Struggling to get script-generated sketch to line up with existing sketch in design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12456505#M2271</link>
      <description>&lt;P&gt;I'm trying to create my first script. I've made it as far as creating a sketch with two nested, constrained rectangles in it. Now I want that sketch to line up with an existing sketch.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can get it on the same plane, but the coordinate system is rotated vs what I expect.&amp;nbsp; The bottom sketch's geometry is supposed to be in the positive XY quadrant, but as you can see it gets inserted rotated.&amp;nbsp; This is a clean test design with a sketch with one rectangle on it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I copy the existing sketch's origin, size and coordinate system?&amp;nbsp; Ideally I want to pick any existing sketch and place my generated sketch and its geometry on the same plane, or on an offset plane directly "above" the existing plane and sized exactly the same. It's my intent to generate patterned geometry to intersect and cut the existing geometry.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;        # Create a new sketch.
        thisComp = design.rootComponent
        sketches = thisComp.sketches

        masterSketch = sketches.item(0)

        # Get the profile
        prof = masterSketch.profiles.item(0)

        # Get construction planes
        planes = thisComp.constructionPlanes
        
        # Create construction plane input
        planeInput = planes.createInput()
        
        # Add construction plane by offset
        offsetValue = adsk.core.ValueInput.createByReal(0)
        planeInput.setByOffset(prof, offsetValue)
        planeOne = planes.add(planeInput)


        sketch = sketches.add(planeOne)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fusion360.png" style="width: 815px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1307182i8BB54D07BFD056C4/image-dimensions/815x491?v=v2" width="815" height="491" role="button" title="fusion360.png" alt="fusion360.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 18:46:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12456505#M2271</guid>
      <dc:creator>darrenPH8TL</dc:creator>
      <dc:date>2023-12-21T18:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling to get script-generated sketch to line up with existing sketch in design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12456918#M2272</link>
      <description>&lt;P&gt;I'm not following exactly what you're trying to do, but hopefully, this will help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each sketch has its coordinate system, and all the geometry created within it is relative to that coordinate system. Fusion doesn't give you any control over the position or orientation of a sketch. Sketches are created by selecting a construction plane or planar face. Fusion has some internal algorithm to create the sketch and keep it associatively linked to the selected construction plane or face.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are some functions on the Sketch object that let you get information about the sketch space and go between sketch and model space. These are modelToSketchSpace, sketchToModelSpace, transform, xDirection, and yDirection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 22:10:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12456918#M2272</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2023-12-21T22:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling to get script-generated sketch to line up with existing sketch in design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12456935#M2273</link>
      <description>&lt;P&gt;What I am trying to do is pretty simple. I want to programmatically generate some geometry and place it in its own sketch that is aligned with an existing sketch.&amp;nbsp;Then I want to use that geometry as a cutting tool.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically, I am creating my own custom patterns to cut the vertical sides of 3D printed objects. The patterns are self-supporting so that no support material is needed. The purpose is for creating lighter parts that require less filament to make, and thus cost less to produce and print faster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can achieve the result manually by drawing in Fusion and then repeating as a pattern, but it is very tedious. Doing it in a script will save me countless hours and allow me to quickly iterate through different options.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 22:25:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12456935#M2273</guid>
      <dc:creator>darrenPH8TL</dc:creator>
      <dc:date>2023-12-21T22:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling to get script-generated sketch to line up with existing sketch in design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12458185#M2274</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9524685"&gt;@darrenPH8TL&lt;/a&gt;&amp;nbsp;-San.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this what it's like?&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface

        msg: str = 'Select Sketch'
        selFilter: str = "Sketches,SketchCurves,SketchPoints"
        sel: core.Selection = select_ent(msg, selFilter)
        if not sel:
            return

        create_clone_sketch(sel.entity)

        ui.messageBox('Done')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def create_clone_sketch(
        sktEntity: fusion.SketchEntity
) -&amp;gt; fusion.Sketch:

    skt: fusion.Sketch = None
    if sktEntity.classType() == fusion.Sketch.classType():
        skt = sktEntity
    else:
        skt = sktEntity.parentSketch

    comp: fusion.Component = skt.parentComponent
    refPlane = skt.referencePlane

    # get sketch entities
    sktEnts: core.ObjectCollection = core.ObjectCollection.createWithArray(
        list(skt.sketchCurves),
    )
    [sktEnts.add(pnt) for pnt in skt.sketchPoints]

    # create offset plane
    planes: fusion.ConstructionPlanes = comp.constructionPlanes
    planeIpt: fusion.ConstructionPlaneInput = planes.createInput()
    planeIpt.setByOffset(
        refPlane,
        core.ValueInput.createByReal(0),
    )
    offsetPlane: fusion.ConstructionPlane = planes.add(planeIpt)

    # create sketch
    cloneSkt: fusion.Sketch = comp.sketches.add(offsetPlane)

    # copy
    cloneSkt.copy(
        sktEnts,
        core.Matrix3D.create(),
    )

    return cloneSkt


def select_ent(
        msg: str,
        filterStr: str
) -&amp;gt; core.Selection:

    try:
        app: core.Application = core.Application.get()
        ui: core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 22 Dec 2023 15:20:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12458185#M2274</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2023-12-22T15:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling to get script-generated sketch to line up with existing sketch in design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12458590#M2275</link>
      <description>&lt;P&gt;That's getting there.&amp;nbsp; As soon as I call design.rootComponent.sketches.add(clonedSketch), the add call throws an exception: "&lt;SPAN&gt;3 : not a planar entity".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;But what's really odd is that even with the exception, the cloned sketch is indeed added to the design and matches the position and dimension of the original.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 19:50:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12458590#M2275</guid>
      <dc:creator>darrenPH8TL</dc:creator>
      <dc:date>2023-12-22T19:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling to get script-generated sketch to line up with existing sketch in design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12459367#M2276</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9524685"&gt;@darrenPH8TL&lt;/a&gt;&amp;nbsp;-San.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We have not been able to reproduce such a condition.&lt;BR /&gt;It may be an inherent problem with the data you are trying.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Dec 2023 13:41:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12459367#M2276</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2023-12-23T13:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling to get script-generated sketch to line up with existing sketch in design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12459593#M2277</link>
      <description>&lt;P&gt;I can make up a package to send to you with the script and the design. The sample design file is a single sketch with a single rectangle in it. Where would I upload that?&lt;/P&gt;</description>
      <pubDate>Sat, 23 Dec 2023 18:44:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12459593#M2277</guid>
      <dc:creator>darrenPH8TL</dc:creator>
      <dc:date>2023-12-23T18:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Struggling to get script-generated sketch to line up with existing sketch in design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12460745#M2278</link>
      <description>&lt;P&gt;After some more investigation, the clone_sketch function provided is already inserting the cloned sketch into the design,which I didn't realize until I read the code.&amp;nbsp;So my code was trying to insert it a second time.&amp;nbsp; I took out my code to add it a second time and now it's good. No idea why that throws a "non planar entity" exception. :shrug:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I just need to access some parameters from the design file so I can use them in my script. They appear to be in Design-&amp;gt;allParameters.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Dec 2023 22:21:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/struggling-to-get-script-generated-sketch-to-line-up-with/m-p/12460745#M2278</guid>
      <dc:creator>darrenPH8TL</dc:creator>
      <dc:date>2023-12-24T22:21:36Z</dc:date>
    </item>
  </channel>
</rss>

