0
$\begingroup$

I am trying to step an object by a small increment via for loop; then return the XY location of each step. Ultimately this will be written to a text file but for now I'm just trying to get the console to print correctly.

The result is the same object XY location from where it started at the beginning of the script, rather than the incremental moves. Is there anything obvious to adjust in the code?

Printed Result

<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>
<Vector (25.3738, -58.8017, 0.0000)>

Python Script:

import bpy

objPart = bpy.context.scene.objects["L FRONT LEG bacci mm"]
objTool = bpy.context.scene.objects["Cylinder"]
objDriver = bpy.data.objects["Plane"]

partLength = objPart.dimensions[0]
passWidth = 1.5
passQty = round(partLength / passWidth)
passRes = 180
stepCount = passQty * passRes
stepWidth = passWidth / passRes

def moveIt():
    objDriver.location.x = objDriver.location.x + stepWidth
    print(objTool.matrix_world.translation)

for s in range(1, stepCount):
    moveIt()

When I run the "moveIt()" function manually one at a time, I get the numbers I want. Which is not ideal as this will run 1000's of times to return each number

>>> operations.moveIt()
<Vector (28.3410, -59.6781, 0.0000)>

>>> operations.moveIt()
<Vector (28.2845, -59.6578, 0.0000)>

>>> operations.moveIt()
<Vector (28.3285, -59.6528, 0.0000)>

>>> operations.moveIt()
<Vector (28.2939, -59.6368, 0.0000)>

>>> operations.moveIt()
<Vector (28.3251, -59.6224, 0.0000)>

>>> operations.moveIt()
<Vector (28.3353, -59.6290, 0.0000)>

here is a screenshot of before the script: before script

and after the script enter image description here

$\endgroup$
1
  • $\begingroup$ in your code, you never change the value of objTool.matrix_world.translation. $\endgroup$ Jan 17 at 6:00

0

You must log in to answer this question.

Browse other questions tagged .