Adding Sketch to Face Reverts Component Translations

Adding Sketch to Face Reverts Component Translations

jss.mlls
Contributor Contributor
527 Views
1 Reply
Message 1 of 2

Adding Sketch to Face Reverts Component Translations

jss.mlls
Contributor
Contributor

Hello,

 

I have a script that performs multiple translations on a single component. The component (in this case the circular shape) is moved inside the box shown below (looking from above):

 

jssmlls_0-1688911198075.png

Once the script finds an open spot for the component in the box, it stops translating the component, and grabs the next component to be translated. Eventually all the components are arranged in the box, and I have something like this:

jssmlls_1-1688912150818.png

 

I recently added an additional function determinePickup to the script that adds a sketch to the translated component's surface face before being arranged in the box (line 7 below):

 

 

        for c in compsByLayer[l]:
            interference = True
            compBody = c.bRepBodies[0]
            bodiesColl.add(compBody)
            zoffset = l*material[sysData.SLICETHICK]
            initX, initY = buildPoint.x, buildPoint.y
            pickPt = determinePickup(c, pickupDiameter, ptPerMM)
            adsk.doEvents()
            pickAndPlace.append([(pickPt.x, pickPt.y, pickPt.z)])
            occ = rootComp.allOccurrencesByComponent(c)[0]
            adsk.doEvents()
            # start translating the component
            for xPlace in arange(cutStart.x, cutEnd.x, arranged[sysData.LINRES]):
                if interference:
                    for yPlace in arange(cutStart.y, cutEnd.y, arranged[sysData.LINRES]):
                        # need to translate component using the occurance object in a list
                        transform = occ.transform2
                        transform.translation = adsk.core.Vector3D.create(xPlace - initX, -zoffset, -(yPlace - initY))
                        occ.transform2 = transform
                        adsk.doEvents()
                        # more lines below determining if there is interference or not

 

 

determinePickup adds a sketch to the top face of the component being translated using the snippit below:

 

 

def determinePickup(comp, pickupDiameter, ptPerMM):
    capFace = comp.features.extrudeFeatures.item(0).endFaces.item(0)
    sk = comp.sketches.add(capFace)
    sk.intersectWithSketchPlane([capFace])

 

 

Here is the problem: For some reason, adding determinePickup (i.e. adding a sketch to the top face) moves the component back to its original spot outside of the box, when I start translating the next component. So, I call determinePickup on a component 'c', the script will find a good spot to place the component 'c' in the box like normal, loop to the next component, calls determinePickup on that next component in the loop, and when that next component is translated into the box, the original component 'c' is moved back to its starting position outside of the box, and the next component is translated around until an optimal spot is found, without the original component 'c' in there to take up space. This unexpected behavior only started happening when I added the determinePickup function to the above code.

 

What I have tried:

  • When I remove the determinePickup function, this behavior goes away, and I get a box full of arranged components like I expect
  • When I only call determinePickup on the first component to be arranged, the behavior goes away, and I get a box full of arranged components
  • When I perform the determinePickup operation outside of this loop and before the function I am in, the behavior goes away and I get a box full of arranged components

Any idea why adding a sketch to a face is resulting in this behavior?

 

Thanks

Jesse

0 Likes
Accepted solutions (1)
528 Views
1 Reply
Reply (1)
Message 2 of 2

jss.mlls
Contributor
Contributor
Accepted solution

Of course, as soon as I post a question after struggling for several hours, I find a solution 5min later 

 

Was actually looking for something completely unrelated, and found this similar question:

 

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/capture-position-after-transforming-occura...

 

Adding 

design.snapshots.add()

 after each part is placed overrides whatever operation as reverting the translation. Hope this helps someone else.