2

Can one get (in python) transform properties (location, rotation ect.) of the objects created by the array modifier? (while the array modifier is active, without applying it)

I need to be able to snap some other object to one of the array duplicates

thanx

gnotev
  • 21
  • 3
  • Doing that implies recoding part of the modifier in Python (eventually taking into account other modifiers in the stack)... so if your situation has some specific parameters for the modifiers you should explain it in the question (as a generic recoding of the array is not a so simple thing). – lemon Apr 24 '18 at 10:20
  • Whatever geometry array modifier creates it's not exposed to API as objects as far as I can tell. But you are able to snap to array-created geometry through vertex / edge / face mode as with the original mesh. – kheetor Apr 24 '18 at 11:21
  • An exposed api would be nice... as the api is probably not exposed (why?), I guess I will have to find some other workarround. Ijust need the locations and rotations of the objects. snap is not the right term to use. I need to get other objects to the locations of the array objects programmetically. any link to learn about that array recording thing? – gnotev Apr 24 '18 at 12:01
  • 1
    @gnotev, technically speaking, array modifier does not create a sequence of separated objects. It creates additional mesh parts which are inside the same original object. So from the array modifier result, there is no simple way to retrieve these mesh parts. The only way is to recalculate all from the original object and the array parameters (but as I said above, you need to provide more information to see if the calculation is possible or not) – lemon Apr 24 '18 at 12:35
  • I'd say this is quite do-able. Being a modifier, it does create the arrays as one mesh, but in doing so is calculating the local coords of each copy, Suggest grabbing the c source code and emulating in python. As stated previously would only need to create an array of matrices each having the transform of array instance. – batFINGER Apr 24 '18 at 13:21
  • Emulating the c source in python is too complicated for me now. I wanted to use the existing modifier's power to find the positions i need without having to calculate anything. I wish there was some kind of api or the resulting transforms were acessible. I suppose it is up to the modifier's programmers so i will try to find a wishlist for a later version perhaps. Thank you all !!! – gnotev Apr 24 '18 at 14:26
  • a quick and dirty way would be to copy the mesh apply the modifiers do you calculations on the results and then delete your copy. – rob Apr 25 '18 at 12:00
  • yep that crossed my mind... might have to do that – gnotev Apr 25 '18 at 15:59

1 Answers1

1

Using modifier array, e.g.:

def array(self, obj):
    mod = bpy.data.objects[obj.name].modifiers.new(name='array', type='ARRAY')
    mod.count = 10
    mod.relative_offset_displace[0] = 2.5

position and rotation can be calculated from the formula, e.g. 5th element in array would have x = 5 * mod.relative_offset_displace[0], so if original is [0,0,0] then 5th will be [6.25,0,0].