<?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: bounding Box intersection issue in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11864086#M4052</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6490295"&gt;@Joshua.mursic&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Could you share you code where you import the part to the model and the sequence until you invoque the moveObj()?&lt;/P&gt;</description>
    <pubDate>Sat, 01 Apr 2023 01:19:01 GMT</pubDate>
    <dc:creator>Jorge_Jaramillo</dc:creator>
    <dc:date>2023-04-01T01:19:01Z</dc:date>
    <item>
      <title>bounding Box intersection issue</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11863631#M4050</link>
      <description>&lt;P&gt;I am having a strange problem where ui.messageBox() is actually causing my script to function correctly. And without it the script is broken.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am importing in meshbodies and building a bounding box around them. Then I copy the bounding box and move it around each&amp;nbsp;occurrence in the project. At each interval of movement I check to see if the copied bounding box is intersecting with any other bounding box in the project (excluding the mesh that was just imported), and if it is, I keep moving the part around each occurrence until it can find a spot. Image shows the path of the part around an&amp;nbsp;occurrence.&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="Joshuamursic_0-1680291553812.png" style="width: 283px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1196550i7F0032550978DFD2/image-dimensions/283x292?v=v2" width="283" height="292" role="button" title="Joshuamursic_0-1680291553812.png" alt="Joshuamursic_0-1680291553812.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is working great. However the problem happens when I try to use this function in a loop and import 2 projects in one after another. When I do this, the first part imports fine, but when the second part uses the Intersection checker, it is not registering intersection with the first imported part. The strange thing is that when I use ui.messageBox() to display the result of the intersection check, the 2nd part imports correctly. I tried to use a sleep() in my program but that is not the issue. Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;expected result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Joshuamursic_1-1680291943427.png" style="width: 317px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1196551iADDDDADEC8666539/image-dimensions/317x326?v=v2" width="317" height="326" role="button" title="Joshuamursic_1-1680291943427.png" alt="Joshuamursic_1-1680291943427.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;current result: (importing on top of 1st part)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Joshuamursic_2-1680291983992.png" style="width: 300px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1196552i2EC48E177660DA37/image-dimensions/300x310?v=v2" width="300" height="310" role="button" title="Joshuamursic_2-1680291983992.png" alt="Joshuamursic_2-1680291983992.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;def isIntersecting(selectionBBox:adsk.core.BoundingBox3D):
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    root = design.rootComponent
    occCount = root.occurrences.count

    for i in range(occCount-1):
        occ = root.occurrences.item(i)
        occBBox = occ.boundingBox
        if occBBox.intersects(selectionBBox):
            return True

    return False&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 19:49:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11863631#M4050</guid>
      <dc:creator>Joshua.mursic</dc:creator>
      <dc:date>2023-03-31T19:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: bounding Box intersection issue</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11863715#M4051</link>
      <description>&lt;P&gt;The moveObj() function I am using is running before I even import the next mesh, but for some reason when I calculate the bounding boxes, it is using the original import location of the first part.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is an image of the first loop, you can see it finds a mesh body that is already in the project and builds a bounding box around it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Joshuamursic_0-1680294256515.png" style="width: 352px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1196569i1077D2D117F78BA4/image-dimensions/352x270?v=v2" width="352" height="270" role="button" title="Joshuamursic_0-1680294256515.png" alt="Joshuamursic_0-1680294256515.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then It moves to that part, and then the next part is inserted and the bounding boxes are recalculated. But as you can see the bounding box for the part that was inserted previously is being constructed from where it originally imported, not where it was moved to.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Joshuamursic_1-1680294342480.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1196571iC5E5546EA83E87A0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Joshuamursic_1-1680294342480.png" alt="Joshuamursic_1-1680294342480.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;because of this the second part is inserted directly on top of the first part that is inserted.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Joshuamursic_2-1680294457971.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1196572iDAD8FC64835AF09D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Joshuamursic_2-1680294457971.png" alt="Joshuamursic_2-1680294457971.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this a problem with fusion calculating the bounding boxes faster then the object transform can move them? But if that is the case, my functions are still being called in a sequence and so the boundary intersection check should not start until after the object has moved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here section of code that is moving the mesh around the other meshes looking for spots.&lt;/P&gt;&lt;LI-CODE lang="python"&gt; # Move in -Y
            while loopBoxMax.y &amp;gt;= compMinPoint.y:
                loopBoxMin = adsk.core.Point3D.create(compMaxPoint.x+xIncrement+padding,compMaxPoint.y+yIncrement,(maxPoint.z - minPoint.z)/-2)
                loopBoxMax = adsk.core.Point3D.create(loopBoxMin.x+meshDimensions.x,loopBoxMin.y+meshDimensions.y,loopBoxMin.z+meshDimensions.z)
                loopBox = adsk.core.BoundingBox3D.create(loopBoxMin,loopBoxMax)
                if insideStock(loopBox,stock,"circle") and intersection(loopBox) == False:
                    ui.messageBox(f'Positioning relative too {comp.name}')
                    moveVector = adsk.core.Vector3D.create(loopBox.maxPoint.x-maxPoint.x,loopBox.maxPoint.y-maxPoint.y,loopBox.maxPoint.z-maxPoint.z)
                    moveObj(mesh,moveVector)
                    return  True
                yIncrement -= incrementValue&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and here is my moveObj() function&lt;/P&gt;&lt;LI-CODE lang="general"&gt;def moveObj(mesh:adsk.fusion.MeshBody,vector:adsk.core.Vector3D):
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    root = design.rootComponent
    features = root.features

    rootOccCount = root.occurrences.count
    meshAssembly = mesh.createForAssemblyContext(root.occurrences.item(rootOccCount-1))

    meshCollection = adsk.core.ObjectCollection.create()
    meshCollection.add(meshAssembly)
    
    # Create Move Inputs
    x = adsk.core.ValueInput.createByReal(vector.x)
    y = adsk.core.ValueInput.createByReal(vector.y)
    z = adsk.core.ValueInput.createByReal(vector.z)

    # Excecute Move
    moveFeature = features.moveFeatures
    moveFeatureInput = moveFeature.createInput2(meshCollection)
    moveFeatureInput.defineAsTranslateXYZ(x,y,z,True)
    moveFeature.add(moveFeatureInput)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 20:30:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11863715#M4051</guid>
      <dc:creator>Joshua.mursic</dc:creator>
      <dc:date>2023-03-31T20:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: bounding Box intersection issue</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11864086#M4052</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6490295"&gt;@Joshua.mursic&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Could you share you code where you import the part to the model and the sequence until you invoque the moveObj()?&lt;/P&gt;</description>
      <pubDate>Sat, 01 Apr 2023 01:19:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11864086#M4052</guid>
      <dc:creator>Jorge_Jaramillo</dc:creator>
      <dc:date>2023-04-01T01:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: bounding Box intersection issue</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11864200#M4053</link>
      <description>&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Hi Mr JoshuaMursic,&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider looking at &lt;EM&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;Snapshot Object&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;Try including the following in your code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; if&amp;nbsp;&amp;nbsp;snapshots.hasPendingSnapshot:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new_snap = snapshots.add()&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&lt;STRONG&gt;Regards&lt;/STRONG&gt;&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&lt;STRONG&gt;MichaelT&lt;/STRONG&gt;&lt;/EM&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 01 Apr 2023 03:36:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11864200#M4053</guid>
      <dc:creator>MichaelT_123</dc:creator>
      <dc:date>2023-04-01T03:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: bounding Box intersection issue</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11868135#M4054</link>
      <description>&lt;P&gt;Thanks this was the issue, the design environment was not capturing the position of the components after I moved them. Thank you very much.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 13:15:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bounding-box-intersection-issue/m-p/11868135#M4054</guid>
      <dc:creator>Joshua.mursic</dc:creator>
      <dc:date>2023-04-03T13:15:09Z</dc:date>
    </item>
  </channel>
</rss>

