<?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: Create centerpoint rectangles from sketch centers in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10030561#M9634</link>
    <description>&lt;P&gt;@Anonymous&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, if you don't have this problem, I think it is easy to use BoundingBox3D.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://modthemachine.typepad.com/my_weblog/2017/06/getting-the-overall-size-of-parts.html" target="_self"&gt;https://modthemachine.typepad.com/my_weblog/2017/06/getting-the-overall-size-of-parts.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-9ce5053e-72b6-4a47-8172-e4223fb4caff" target="_self"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-9ce5053e-72b6-4a47-8172-e4223fb4caff&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Although there is not enough processing, we have created such a sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#Fusion360API Python script
import traceback
import adsk.core
import adsk.fusion

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface
        des :adsk.fusion.Design = _app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        # create Bounding BoxSketch
        # Default modeling orientation "Y up" only
        createBoundingBoxSketch(root.sketches[0],root.xZConstructionPlane)

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def createBoundingBoxSketch(
    targetSkt :adsk.fusion.Sketch,
    supportPlane :adsk.core.Base = None
    ) -&amp;gt; adsk.fusion.Sketch:

    # check profile
    if targetSkt.profiles.count &amp;lt; 1:
        return None

    # create new sketch
    comp :adsk.fusion.Component = targetSkt.parentComponent
    skt = adsk.fusion.Sketch.cast(None)
    if supportPlane:
        skt = comp.sketches.add(supportPlane)
    else:
        skt = comp.sketches.add(targetSkt.referencePlane)

    # get boundingBox
    prof :adsk.fusion.Profile
    bound :adsk.core.BoundingBox3D = targetSkt.profiles[0].boundingBox
    for prof in targetSkt.profiles:
        bound.combine(prof.boundingBox)


    # get min/max point
    minPnt :adsk.core.Point3D = bound.minPoint
    maxPnt :adsk.core.Point3D = bound.maxPoint

    # get mid point
    midPnt :adsk.core.Point3D = adsk.core.Point3D.create(
                                (maxPnt.x + minPnt.x) * 0.5,
                                (maxPnt.y + minPnt.y) * 0.5,
                                (maxPnt.z + minPnt.z) * 0.5)

    # create boundingBox
    lines = skt.sketchCurves.sketchLines
    lines.addCenterPointRectangle(midPnt, maxPnt)

    skt.name = f'BoundingBox of {targetSkt.name}'

    return skt&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;However, you need to set "Y up" in the Fusion360 preferences to get the correct result.&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Isn't the attached f3d file created with "Y up"?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 891px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/871731i1FB736CEB70EA193/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Jan 2021 01:32:34 GMT</pubDate>
    <dc:creator>kandennti</dc:creator>
    <dc:date>2021-01-26T01:32:34Z</dc:date>
    <item>
      <title>Create centerpoint rectangles from sketch centers</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10023556#M9630</link>
      <description>&lt;P&gt;Hey there -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;New to Fusion scripting, and I am 90% sure I am getting tangled up in object types, but thought this would be a good place to start.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote a script already that imports a pile of DXF files separately. Now, what I would like to do is create a rectangle of fixed size around the *individual sketch* origin, not the origin of the entire project.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having 2 issues:&lt;/P&gt;&lt;P&gt;1) I can't create another point translated from the first for some reason&lt;/P&gt;&lt;P&gt;2) Trying to retrieve the origin of the sketch is proving to be difficult - I keep getting the global origin, *not* the origin on the sketch. I have a demo file attached, and code is below. Thanks for the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;import traceback

import adsk.core
import adsk.fusion


def run(context):
    ui = None
    try: 
        app = adsk.core.Application.get()
        ui = app.userInterface

        design = app.activeProduct

        cornerTrans = adsk.core.Vector3D.create(24, 24, 0)

        # Get the sketch out of the root component of the active design.
        rootComp = design.rootComponent
        sketches = rootComp.sketches;
        sketch = sketches[0]
        wO = sketch.origin

        xzPlane = rootComp.xZConstructionPlane
        sketchNew = sketches.add(xzPlane)

        sketchPoints = sketchNew.sketchPoints
        lines = sketchNew.sketchCurves.sketchLines;
        workOrigin = sketchPoints.add(wO)

        rC = wO.translateBy(cornerTrans)
        recCorner = sketchPoints.add(rC)
        recLines = lines.addCenterPointRectangle(workOrigin, recCorner)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 22 Jan 2021 20:19:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10023556#M9630</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-01-22T20:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create centerpoint rectangles from sketch centers</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10024804#M9631</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is possible that I am not understanding what you want.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The translateBy method of the Point3D object is a destructive method that changes the calling instance itself.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-29830e60-05c0-4c88-8ef7-2bfe7af6bcc1" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-29830e60-05c0-4c88-8ef7-2bfe7af6bcc1&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The first parameter of the addCenterPointRectangle method is the Point3D object.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-cdc75402-9c1c-4134-bd01-e95eb9c9b8ee" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-cdc75402-9c1c-4134-bd01-e95eb9c9b8ee&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So if you do it this way, the error will no longer&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;・・・
        sketchPoints = sketchNew.sketchPoints
        lines = sketchNew.sketchCurves.sketchLines;
        workOrigin = sketchPoints.add(wO)

        # rC = wO.translateBy(cornerTrans)
        rC = wO.copy()
        rC.translateBy(cornerTrans)

        recCorner = sketchPoints.add(rC)
        
        # recLines = lines.addCenterPointRectangle(workOrigin, recCorner)
        recLines = lines.addCenterPointRectangle(workOrigin.geometry, recCorner)
・・・&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 23 Jan 2021 13:48:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10024804#M9631</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2021-01-23T13:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create centerpoint rectangles from sketch centers</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10025844#M9632</link>
      <description>&lt;P&gt;Thank you for this help! I will check it out on Monday and report back. I think at the least this will solve one of the issues.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 02:24:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10025844#M9632</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-01-24T02:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create centerpoint rectangles from sketch centers</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10029513#M9633</link>
      <description>&lt;P&gt;This definitely got a step closer, but is not quite what I am looking for. Here is the goal that I am aiming for:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I select an imported DXF sketch in Fusion that is off the part origin:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 667px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/871570iAE76A5DE2351A0B7/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;...and then hit "Create sketch"...&lt;/P&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="2.png" style="width: 644px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/871572i20C5986019602BC2/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.png" alt="2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am given a sketch plane where its local origin corresponds to the center of the previously selected sketch. If I draw from that point, I can create fully defined sketches:&lt;/P&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="3.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/871573i2FB7634A9E0A786D/image-size/large?v=v2&amp;amp;px=999" role="button" title="3.png" alt="3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;...the long goal here being I am trying to automate a very repetitive CAM process by importing a bunch of DXFs from a folder, create a center rectangle representing the stock, and then automatically create CAM profile data and export a pile of NC code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does that make a bit more sense?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 17:54:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10029513#M9633</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-01-25T17:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create centerpoint rectangles from sketch centers</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10030561#M9634</link>
      <description>&lt;P&gt;@Anonymous&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, if you don't have this problem, I think it is easy to use BoundingBox3D.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://modthemachine.typepad.com/my_weblog/2017/06/getting-the-overall-size-of-parts.html" target="_self"&gt;https://modthemachine.typepad.com/my_weblog/2017/06/getting-the-overall-size-of-parts.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-9ce5053e-72b6-4a47-8172-e4223fb4caff" target="_self"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-9ce5053e-72b6-4a47-8172-e4223fb4caff&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Although there is not enough processing, we have created such a sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#Fusion360API Python script
import traceback
import adsk.core
import adsk.fusion

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface
        des :adsk.fusion.Design = _app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        # create Bounding BoxSketch
        # Default modeling orientation "Y up" only
        createBoundingBoxSketch(root.sketches[0],root.xZConstructionPlane)

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def createBoundingBoxSketch(
    targetSkt :adsk.fusion.Sketch,
    supportPlane :adsk.core.Base = None
    ) -&amp;gt; adsk.fusion.Sketch:

    # check profile
    if targetSkt.profiles.count &amp;lt; 1:
        return None

    # create new sketch
    comp :adsk.fusion.Component = targetSkt.parentComponent
    skt = adsk.fusion.Sketch.cast(None)
    if supportPlane:
        skt = comp.sketches.add(supportPlane)
    else:
        skt = comp.sketches.add(targetSkt.referencePlane)

    # get boundingBox
    prof :adsk.fusion.Profile
    bound :adsk.core.BoundingBox3D = targetSkt.profiles[0].boundingBox
    for prof in targetSkt.profiles:
        bound.combine(prof.boundingBox)


    # get min/max point
    minPnt :adsk.core.Point3D = bound.minPoint
    maxPnt :adsk.core.Point3D = bound.maxPoint

    # get mid point
    midPnt :adsk.core.Point3D = adsk.core.Point3D.create(
                                (maxPnt.x + minPnt.x) * 0.5,
                                (maxPnt.y + minPnt.y) * 0.5,
                                (maxPnt.z + minPnt.z) * 0.5)

    # create boundingBox
    lines = skt.sketchCurves.sketchLines
    lines.addCenterPointRectangle(midPnt, maxPnt)

    skt.name = f'BoundingBox of {targetSkt.name}'

    return skt&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;However, you need to set "Y up" in the Fusion360 preferences to get the correct result.&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Isn't the attached f3d file created with "Y up"?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 891px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/871731i1FB736CEB70EA193/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2021 01:32:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10030561#M9634</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2021-01-26T01:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create centerpoint rectangles from sketch centers</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10032961#M9635</link>
      <description>&lt;P&gt;This is great! Yes, this was the enabling bit to get my code to work. Posting here for a little more help in case anyone else needs this. Essentially, I have updated this to iterate through all available sketches, create a fixed size bounding box, and place a point at the lower left bounding box corner to help automate CAM setup creation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;#Author-S. Cusack
#Description-CORE: Create Setup CAM Boundaries
#Units are in *CM*, thus the weird scale factors

import traceback
import adsk.core
import adsk.fusion

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface
        des :adsk.fusion.Design = _app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        # Get number of existing sketches
        sketchLen = root.sketches.count
        i = 0

        # create Bounding BoxSketch
        # Default modeling orientation "Y up" only
        while i &amp;lt; sketchLen:
            createBoundingBoxSketch(root.sketches[i],root.xZConstructionPlane)
            i += 1

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def createBoundingBoxSketch(
    targetSkt :adsk.fusion.Sketch,
    supportPlane :adsk.core.Base = None
    ) -&amp;gt; adsk.fusion.Sketch:

    # check profile
    if targetSkt.profiles.count &amp;lt; 1:
        return None

    # create new sketch
    comp :adsk.fusion.Component = targetSkt.parentComponent
    skt = adsk.fusion.Sketch.cast(None)
    if supportPlane:
        skt = comp.sketches.add(supportPlane)
    else:
        skt = comp.sketches.add(targetSkt.referencePlane)

    # create sizing vector
    cornerTrans = adsk.core.Vector3D.create(60.96, 60.96, 0)
    cT2 = cornerTrans.copy()
    cT2.scaleBy(-2)

    # get boundingBox
    prof :adsk.fusion.Profile
    bound :adsk.core.BoundingBox3D = targetSkt.profiles[0].boundingBox
    for prof in targetSkt.profiles:
        bound.combine(prof.boundingBox)


    # get min/max point
    minPnt :adsk.core.Point3D = bound.minPoint
    maxPnt :adsk.core.Point3D = bound.maxPoint

    # get mid point
    midPnt :adsk.core.Point3D = adsk.core.Point3D.create(
                                (maxPnt.x + minPnt.x) * 0.5,
                                (maxPnt.y + minPnt.y) * 0.5,
                                (maxPnt.z + minPnt.z) * 0.5)

    # translate midpoint to exterior corner
    rC = midPnt.copy()
    rC.translateBy(cornerTrans)
    
    # create boundingBox
    lines = skt.sketchCurves.sketchLines
    lines.addCenterPointRectangle(midPnt, rC)

    # create boundary corner
    rC.translateBy(cT2)
    sketchPoints = skt.sketchPoints
    sketchPoints.add(rC)

    skt.name = f'Boundary for {targetSkt.name}'

    return skt&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 559px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/872295iF2F1A5541B588666/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2.png" style="width: 503px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/872294i0AE4D1EBAA2AD5F7/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.png" alt="2.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2021 18:58:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/create-centerpoint-rectangles-from-sketch-centers/m-p/10032961#M9635</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-01-26T18:58:19Z</dc:date>
    </item>
  </channel>
</rss>

