Howdy, this is my first post on blenderartists.org forums and my first attempt at addon creation with python. As you
should already guessed from the preceding lines, I’m new to python and to the blender programming world in general.
I just hope for you to take it easy with me :D. I know the code could be vastly optimized and condensed, but for me
was a great exercise as a beginner. Feel free to make any changes to the code and use it in any project as you like.
I don’t know if the GPL license is the the most appropriate for this but I think will be OK for now. Please, implementing
your own ideas and/or code variations is highly welcomed and encouraged. I should also add that I have taken a few
bits here and there from several places around the internet and modify them a little bit for my own purposes. Special
thanks to CodeXman for his bits and ideas that you can find everywhere around the web (literally), and Tom Rethaller
for his addon: “Align by faces”. The latter gave me the idea for this one.
The addon “Align by faces” is excellent for what it does but it didn’t give me the results I was looking for. I tried
using quaternions rotations exclusively and what not, but had no luck with matching the math involved with the
outcome I wanted to from this. I went the other route and use the parenting hack; you know, because the parent is a
plane (actually a triangle called “Circle”) it was easier to manipulate.
It should be OK for mechanical modeling and to accomplish some tasks associated with the placement of an object
onto another mesh object’s faces or vertices. I have tested it by placing a mesh, curve, lamp, camera, monkey onto
the faces or vertices of another mesh object on under Blender v2.75 at the moment. To install it, just place the python
file inside your addons folder and enable it under your preferences settings. I have not tested it under all possible
scenarios. Please, don’t use it on critical projects for now. I don’t warrant a perfect outcome.
A short demo:
[video]https://youtu.be/NO55BrEFHr4[/video]
The link to download the file.py from Google Drive:
https://drive.google.com/file/d/0BxpQX0r5Rs8XNzJNS2d2cEw5RjQ/view?usp=sharing
Or, if you prefer:
object_copy_to_selected.zip (2.97 KB)
And; well, this is how it works:
1- Select the source object:* This object will be copy on the faces or vertices of the target object.
* This object could be a mesh, curve, empty, lamp, camera, etc.
2- If the object is a mesh or curve, enter edit mode and select the polygon or control point accordingly.* Just one face or one control point should be selected.
* This is what will get aligned with the other faces or vertices.
3- Select the target object:* This object will be the recipient of the copy or copies.
* This object have to be a mesh.
4- Enter edit mode and select the faces or vertices:* The source object will be copied to these selected faces or vertices.
- The tool edit mode state (vertex or face) will determine where the object will be copied to.
5- Press spacebar, search and choose “Copy Object to Selected”:* This can be done from edit mode or object mode.
6- Move, rotate, resize or make changes to the original mesh at this step if you wish to:* Everything will be selected under edit mode. - Because the copies are linked to the source object, any mesh edit will be replicated.
- The most appropriate pivot and transform orientation will be apply for you at this stage.
- Use local for transformations (xx, yy, zz). Transform axis will be your best guide (experiment).
- Notice that all this should be done under edit mode.
If everything went according to these steps, you should get the object copied and aligned to the normal of the faces
or vertices selected on the target. If you select more than two objects (source and target), none or more than one
face on the source object or no face on the target object, an error info will pop up indicating this. The object with the
error will be in edit mode and you will be able to correct the issue. It is recommended that the two objects be on the
same layer, but it will create the objects if not so anyways. I still have to test it for different scenes, animation and
under a few others conditions, but the addon is functional for what it is. Again, just add, delete, change, use any code
inside as you see suitable. Enjoy…