<?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: Error with Rectangular Pattern on Inserted Component in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13151122#M987</link>
    <description>&lt;P&gt;Here's a new version of your program where I added one line that creates a proxy of the occurrence. This fixes the issue you're having. It's line 48.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import traceback
import adsk.fusion
import adsk.core


def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        # get active datafile
        actDataFile: adsk.core.DataFile = app.activeDocument.dataFile
        if not actDataFile:
            ui.messageBox("Save the document once.")
            return

        # get datafile ID
        actId = app.activeDocument.dataFile.id

        # get the unique data file
        dataFolder: adsk.core.DataFolder = app.activeDocument.dataFile.parentFolder
        targetDatafile: adsk.core.DataFile = None
        dataFiles = dataFolder.dataFiles.asArray()
        for df in dataFiles:
            if df.id != actId and df.fileExtension == "f3d":
                targetDatafile = df
                break

        if not targetDatafile:
            ui.messageBox("Could not find the data file to import.")
            return

        instantiate = root.occurrences
        newComponent = instantiate.addNewComponent(adsk.core.Matrix3D.create())

        ##### ----&amp;gt;&amp;gt;  This will create the error  &amp;lt;&amp;lt;----- #####
        # targetComponent = root.occurrences  # This works
        targetComponent = newComponent.component.occurrences  # This doesn't
        ##### ----&amp;gt;&amp;gt;  This will create the error  &amp;lt;&amp;lt;----- #####

        instantiateComponent = targetComponent.addByInsert(
            targetDatafile, adsk.core.Matrix3D.create(), False
        )

        #### ---&amp;gt;&amp;gt; This line fixes it by creating a proxy of the ocurrence. &amp;lt;&amp;lt;---- #####
        instantiateComponent = instantiateComponent.createForAssemblyContext(newComponent)

        # Rectrangular pattern inputs
        rectangularPatternComponents = adsk.core.ObjectCollection.create()
        rectangularPatternComponents.add(instantiateComponent)

        componentAmount = adsk.core.ValueInput.createByString("3")
        patternDistance = adsk.core.ValueInput.createByString("500")
        patternDistType = adsk.fusion.PatternDistanceType.ExtentPatternDistanceType

        # Create rectangular pattern
        rectangularPattern = root.features.rectangularPatternFeatures

        rectangularPatternInput = rectangularPattern.createInput(
            rectangularPatternComponents,
            root.xConstructionAxis,
            componentAmount,
            patternDistance,
            patternDistType,
        )
        rectangularPatternInput.setDirectionTwo(
            root.yConstructionAxis,
            adsk.core.ValueInput.createByString("1"),
            adsk.core.ValueInput.createByString("0 mm"),
        )

        rectangularPattern.add(rectangularPatternInput)

    except:
        if ui:
            ui.messageBox("Failed:\n{}".format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Nov 2024 19:43:11 GMT</pubDate>
    <dc:creator>BrianEkins</dc:creator>
    <dc:date>2024-11-14T19:43:11Z</dc:date>
    <item>
      <title>Error with Rectangular Pattern on Inserted Component</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/12950249#M983</link>
      <description>&lt;P&gt;I was about to ask for help with my code, because i kept getting this error message&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-center" image-alt="2.PNG" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1396457i69C985CDF0067994/image-size/medium?v=v2&amp;amp;px=400" 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;and i could remove it by editing the feature (rectangular pattern) and then immediately clicking ok&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-center" image-alt="3.PNG" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1396459i221EA1CFEEB3B3E7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="3.PNG" alt="3.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="4.PNG" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1396460i7F6128A1FA49B9B2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="4.PNG" alt="4.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;But then it occurred to me that maybe it's the same problem as in my previous post -&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/fusion-api-and-scripts/rigid-joint-between-an-external-inserted-component-and-a-sketch/td-p/12941821" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/fusion-api-and-scripts/rigid-joint-between-an-external-inserted-component-and-a-sketch/td-p/12941821&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that there is a problem with inserted components, so insted of making the pattern from the inserted component, i used (the "hack"/solution Jorge_Jaramillo suggested as a solution in my previous post) the parent component that i created for the inserted component and that fixed the error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;app = adsk.core.Application.get()
ui  = app.userInterface
des = adsk.fusion.Design.cast(app.activeProduct)
root = adsk.fusion.Component.cast(des.rootComponent)

#Select a face to make sketch on
face = ui.selectEntity("Select a Planar Face", "PlanarFaces").entity

#Make sketch on selected face
sketch = root.sketches.add(face)

#Add line
lines = sketch.sketchCurves.sketchLines
line = lines.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(0, 200, 0))

#Add a sketch point a distance from each end
points = sketch.sketchPoints
sketchPoint = points.add(adsk.core.Point3D.create(0, 10, 0))

#Find components
exampleComponent = app.data.activeHub.dataProjects.item(0).rootFolder.dataFolders.itemByName("Autodesk Example").dataFiles.item(0)

#Insert Components (Using forum hack https://forums.autodesk.com/t5/fusion-api-and-scripts/rigid-joint-between-an-external-inserted-component-and-a-sketch/td-p/12941821)
instantiate = root.occurrences
forumHack = instantiate.addNewComponent(adsk.core.Matrix3D.create())
instantiateComponent = forumHack.component.occurrences.addByInsert(exampleComponent, adsk.core.Matrix3D.create(), True)
instantiateComponent.isGroundToParent = True

#Get origin points
originComponent = forumHack.component.originConstructionPoint

#Create joint geometry
joints = root.joints

jointPointComponent = adsk.fusion.JointGeometry.createByPoint(originComponent)
jointPointSketch = adsk.fusion.JointGeometry.createByPoint(sketchPoint)
joint = joints.createInput(jointPointComponent, jointPointSketch)

#Joint settings
joint.isFlipped = False
joint.setAsRigidJointMotion()

#Create joints
joints.add(joint)

#Rectrangular pattern inputs
rectangularPatternComponents = adsk.core.ObjectCollection.create()

##### ----&amp;gt;&amp;gt;  This will create the error  &amp;lt;&amp;lt;----- #####
#rectangularPatternComponents.add(forumHack) # This works
rectangularPatternComponents.add(instantiateComponent) # This doesn't

componentAmount = adsk.core.ValueInput.createByString('3')
patternDistance = adsk.core.ValueInput.createByString("500")
patternDistType = adsk.fusion.PatternDistanceType.ExtentPatternDistanceType

#Create rectangular pattern
rectangularPattern = root.features.rectangularPatternFeatures

rectangularPatternInput = rectangularPattern.createInput(rectangularPatternComponents, line, componentAmount, patternDistance, patternDistType)
rectangularPatternInput.setDirectionTwo(line, adsk.core.ValueInput.createByString('1'), adsk.core.ValueInput.createByString('0 mm'))

rectangularPattern.add(rectangularPatternInput)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;maybe i'm doing something wrong?&lt;/P&gt;&lt;P&gt;if not how do i report this bug?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 21:50:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/12950249#M983</guid>
      <dc:creator>Hyger</dc:creator>
      <dc:date>2024-08-09T21:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Rectangular Pattern on Inserted Component</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13147796#M984</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;Did you find a solution? I just ran into the same problem and I'm running out of ideas. I also noticed that when the loaded component is in the rootComponent the program works fine, but if I move the loaded component to another component and try to make a rectanglePattern I get exactly the same result as you.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2024 10:50:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13147796#M984</guid>
      <dc:creator>espablo</dc:creator>
      <dc:date>2024-11-13T10:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Rectangular Pattern on Inserted Component</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13148945#M985</link>
      <description>&lt;P&gt;Here's a modified version of the original program. The change that matters is&amp;nbsp;&lt;SPAN&gt;that I'm calling createForAssemblyContext to get the origin point in the context of the root component. This is often called a "proxy" of the real point. The &lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A" target="_blank" rel="noopener"&gt;user manual&lt;/A&gt; discusses this&lt;/SPAN&gt;.&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.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = adsk.fusion.Component.cast(des.rootComponent)

        #Make sketch on selected face
        sketch = root.sketches.add(root.xYConstructionPlane)

        #Add line
        lines = sketch.sketchCurves.sketchLines
        line = lines.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(0, 200, 0))

        #Add a sketch point a distance from each end
        points = sketch.sketchPoints
        sketchPoint = points.add(adsk.core.Point3D.create(0, 10, 0))

        #Find components
        project = app.data.activeHub.dataProjects.item(0)
        exampleComponent = project.rootFolder.dataFolders.itemByName("Autodesk Example").dataFiles.item(0)
        occ = root.occurrences.addByInsert(exampleComponent, adsk.core.Matrix3D.create(), True)

        #Get origin points
        originPoint = occ.component.originConstructionPoint

        #*** This is the main thing that was missing ***
        originPoint = originPoint.createForAssemblyContext(occ)

        #Create joint geometry
        joints = root.joints

        jointPointComponent = adsk.fusion.JointGeometry.createByPoint(originPoint)
        jointPointSketch = adsk.fusion.JointGeometry.createByPoint(sketchPoint)
        joint = joints.createInput(jointPointComponent, jointPointSketch)

        #Joint settings
        joint.isFlipped = False
        joint.setAsRigidJointMotion()

        #Create joints
        joints.add(joint)

        #Rectrangular pattern inputs
        rectangularPatternComponents = adsk.core.ObjectCollection.create()

        rectangularPatternComponents.add(occ)

        componentAmount = adsk.core.ValueInput.createByString('3')
        patternDistance = adsk.core.ValueInput.createByString("15")
        patternDistType = adsk.fusion.PatternDistanceType.ExtentPatternDistanceType

        #Create rectangular pattern
        rectangularPattern = root.features.rectangularPatternFeatures

        rectangularPatternInput = rectangularPattern.createInput(rectangularPatternComponents, line, componentAmount, patternDistance, patternDistType)
        rectangularPatternInput.setDirectionTwo(line, adsk.core.ValueInput.createByString('1'), adsk.core.ValueInput.createByString('0 mm'))

        rectangularPattern.add(rectangularPatternInput)
    except:
        app.log('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2024 21:28:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13148945#M985</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2024-11-13T21:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Rectangular Pattern on Inserted Component</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13150265#M986</link>
      <description>&lt;P&gt;What I mean is that when I use the addByInsert method for the root, the rectangularPattern works fine. However, if I create a component and want to use the addByInsert method for it, the rectangularPattern no longer works fine. The effect is the same as in Hyger. I am attaching a program in which this effect occurs.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import traceback
import adsk.fusion
import adsk.core


def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        # get active datafile
        actDataFile: adsk.core.DataFile = app.activeDocument.dataFile
        if not actDataFile:
            ui.messageBox("Save the document once.")
            return

        # get datafile ID
        actId = app.activeDocument.dataFile.id

        # get the unique data file
        dataFolder: adsk.core.DataFolder = app.activeDocument.dataFile.parentFolder
        targetDatafile: adsk.core.DataFile = None
        dataFiles = dataFolder.dataFiles.asArray()
        for df in dataFiles:
            if df.id != actId and df.fileExtension == "f3d":
                targetDatafile = df
                break

        if not targetDatafile:
            ui.messageBox("Could not find the data file to import.")
            return

        instantiate = root.occurrences
        newComponent = instantiate.addNewComponent(adsk.core.Matrix3D.create())

        ##### ----&amp;gt;&amp;gt;  This will create the error  &amp;lt;&amp;lt;----- #####
        # targetComponent = root.occurrences  # This works
        targetComponent = newComponent.component.occurrences  # This doesn't
        ##### ----&amp;gt;&amp;gt;  This will create the error  &amp;lt;&amp;lt;----- #####

        instantiateComponent = targetComponent.addByInsert(
            targetDatafile, adsk.core.Matrix3D.create(), False
        )

        # Rectrangular pattern inputs
        rectangularPatternComponents = adsk.core.ObjectCollection.create()
        rectangularPatternComponents.add(instantiateComponent)

        componentAmount = adsk.core.ValueInput.createByString("3")
        patternDistance = adsk.core.ValueInput.createByString("500")
        patternDistType = adsk.fusion.PatternDistanceType.ExtentPatternDistanceType

        # Create rectangular pattern
        rectangularPattern = root.features.rectangularPatternFeatures

        rectangularPatternInput = rectangularPattern.createInput(
            rectangularPatternComponents,
            root.xConstructionAxis,
            componentAmount,
            patternDistance,
            patternDistType,
        )
        rectangularPatternInput.setDirectionTwo(
            root.yConstructionAxis,
            adsk.core.ValueInput.createByString("1"),
            adsk.core.ValueInput.createByString("0 mm"),
        )

        rectangularPattern.add(rectangularPatternInput)

    except:
        if ui:
            ui.messageBox("Failed:\n{}".format(traceback.format_exc()))&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 14 Nov 2024 12:51:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13150265#M986</guid>
      <dc:creator>espablo</dc:creator>
      <dc:date>2024-11-14T12:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Rectangular Pattern on Inserted Component</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13151122#M987</link>
      <description>&lt;P&gt;Here's a new version of your program where I added one line that creates a proxy of the occurrence. This fixes the issue you're having. It's line 48.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import traceback
import adsk.fusion
import adsk.core


def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        # get active datafile
        actDataFile: adsk.core.DataFile = app.activeDocument.dataFile
        if not actDataFile:
            ui.messageBox("Save the document once.")
            return

        # get datafile ID
        actId = app.activeDocument.dataFile.id

        # get the unique data file
        dataFolder: adsk.core.DataFolder = app.activeDocument.dataFile.parentFolder
        targetDatafile: adsk.core.DataFile = None
        dataFiles = dataFolder.dataFiles.asArray()
        for df in dataFiles:
            if df.id != actId and df.fileExtension == "f3d":
                targetDatafile = df
                break

        if not targetDatafile:
            ui.messageBox("Could not find the data file to import.")
            return

        instantiate = root.occurrences
        newComponent = instantiate.addNewComponent(adsk.core.Matrix3D.create())

        ##### ----&amp;gt;&amp;gt;  This will create the error  &amp;lt;&amp;lt;----- #####
        # targetComponent = root.occurrences  # This works
        targetComponent = newComponent.component.occurrences  # This doesn't
        ##### ----&amp;gt;&amp;gt;  This will create the error  &amp;lt;&amp;lt;----- #####

        instantiateComponent = targetComponent.addByInsert(
            targetDatafile, adsk.core.Matrix3D.create(), False
        )

        #### ---&amp;gt;&amp;gt; This line fixes it by creating a proxy of the ocurrence. &amp;lt;&amp;lt;---- #####
        instantiateComponent = instantiateComponent.createForAssemblyContext(newComponent)

        # Rectrangular pattern inputs
        rectangularPatternComponents = adsk.core.ObjectCollection.create()
        rectangularPatternComponents.add(instantiateComponent)

        componentAmount = adsk.core.ValueInput.createByString("3")
        patternDistance = adsk.core.ValueInput.createByString("500")
        patternDistType = adsk.fusion.PatternDistanceType.ExtentPatternDistanceType

        # Create rectangular pattern
        rectangularPattern = root.features.rectangularPatternFeatures

        rectangularPatternInput = rectangularPattern.createInput(
            rectangularPatternComponents,
            root.xConstructionAxis,
            componentAmount,
            patternDistance,
            patternDistType,
        )
        rectangularPatternInput.setDirectionTwo(
            root.yConstructionAxis,
            adsk.core.ValueInput.createByString("1"),
            adsk.core.ValueInput.createByString("0 mm"),
        )

        rectangularPattern.add(rectangularPatternInput)

    except:
        if ui:
            ui.messageBox("Failed:\n{}".format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 19:43:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13151122#M987</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2024-11-14T19:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Rectangular Pattern on Inserted Component</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13151261#M988</link>
      <description>&lt;P&gt;Ha! It works. Although I still don't understand the mechanism of how this proxy works. But it works exactly as I want. Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 20:53:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/error-with-rectangular-pattern-on-inserted-component/m-p/13151261#M988</guid>
      <dc:creator>espablo</dc:creator>
      <dc:date>2024-11-14T20:53:05Z</dc:date>
    </item>
  </channel>
</rss>

