I am a more or less skilled Python user in Maya for quite some time and wanted to look into Python within Blender (Version: 2.79).
This is my code:
def posRotSclObj():
sel = bpy.context.selected_objects
sel2 = sel[0]
sel1 = sel[1]
print(sel1)
print(sel2)
pos1 = sel1.location
rot1 = sel1.rotation_euler
scl1 = sel1.scale
print (scl1)
pos2 = sel2.delta_location
sel2.location = (pos1[0], pos1[1], pos1[2])
sel2.rotation_euler = (rot1[0], rot1[1], rot1[2])
sel2.scale = (scl1[0], scl1[1], scl1[2])
posRotSclObj()
I have 3 problems right now:
When I define my selection by
sel = bpy.context.selected_objectsthensel[0]is the second object I have selected andsel[1]the first...that's pretty counterintuitive, especially because it was the other way around in Maya. Is this right?print selwould work in Maya but Blender needs brackets around my variable:print (sel). Why is there difference in syntax?When I indent beginning from the line after
defexcept for the last where I call my function and paste it into the python console within Blender it gives me indentation errors on every line that has one indent.
locationby attributeObject.location.x,Object.location.yandObject.location.z, which is way more readable. Also paste your code into the text editor and run it from there, that can be cumbersome but there a lot of ways around that and you'll see that Blender's API is well designed (in comparison to Maya's python API). $\endgroup$bpy.context.selected_objectsis not ordered by selection, it's just a list of selected objects in no particular order. $\endgroup$