You're better off using bpy.data.objects to manipulate them. This way you don't need to rely on what is selected, all you need is the objects name.
mod_name = 'My-Mirror-Modifier'
for obj in bpy.data.collections["My-Collection"].all_objects:
if obj.type == 'MESH':
mod = obj.modifiers.new(mod_name, 'MIRROR')
Iterate over all objects (or all selected objects, in the following script). If the object supports modifiers, check if the looked for modifier name exists, if it does, rename it.
previous_name_modifier = "boolean1"
new_name_modifier = "MyBoolean"
for obj in bpy.context.selected_objects:
if not obj.modifiers:
For operators use context.
Given the self in the question code, making the assumption you are writing an operator
Further to the answer of @RoufirHassan by way of explanation, looping over the collection objects de-selecting and selecting single, was not changing the active object. Adding context.object to print statement would confirm this.
Is the active ...
You can use the "spin tool".
Start with a plane section.
Place the 3d cursor at the center of the circle.
Use the spin tool which will be placed at the 3D cursor location (thanks for the information, Robin). By default, the tool will rotate around the Z axis.
Once the operation validated you can tune the values, such as the number of extrusions ...
CAD geek here.
You will need atleast some kind of margin between the two surfaces, or you will have a fit that is too tight, and while you can push it in probably, there is a chance (depending on printing filament) your piece will start to crack at the surface joint.
For as to how much margin to use, look up the minimum tolerance of your 3D printer, and use ...
That can be done with some constraints:
Place an empty has child of the original cube. This is to place Suzanne relatively to the cube.
Then add two "transformation" constraints to Suzanne, with the above empty as target.
Presuming the mirror is on X.
One constraint for the locations, inverting X source (maps -1/1 to 1/-1).
One constraint for the ...
At last, a use for the Build modifier?
Create a fan-filled circle-mask with the same number of segments as you have LEDs, rotate in Z to the desired start-point. Give it a Build modifier, set to the appropriate frame start/end, and 'Reverse'.
Segments are made visible one at a time.
A test case:
From left to right: 90° then 30°.
If we go above 30° in the modifier the 30° angle is decimated:
Now we have a 105° angle:
which means the angle variation is 75° (180 - 105°) following the edge (or face) variation.
So if the modifier angle goes above 75°:
... the edge collapse again.
That means the modifier is "cumulative": it will ...
Select all the meshes in your collection and add a mirror modifier.
But as you said it will only mirror the active object ( active object = last object selected with different colored outline). So in order to mirror every single object just type (Ctrl+L) > modifiers. It will link all objects with the same modifier.
You can use it for any other modifiers.