Skip to content

Instantly share code, notes, and snippets.

@demohero101
Created November 15, 2023 21:31
Show Gist options
  • Save demohero101/7bec55a2157b870b7008aae8ce86bc7f to your computer and use it in GitHub Desktop.
Save demohero101/7bec55a2157b870b7008aae8ce86bc7f to your computer and use it in GitHub Desktop.
Ornekler
import bpy
# Create a red material
red_material = bpy.data.materials.new(name="RedMaterial")
red_material.diffuse_color = (1, 0, 0, 1) # Set color to red
# Assign the red material to selected objects
for obj in bpy.context.selected_objects:
obj.data.materials.append(red_material)
---------------------------------------------------------------
import bpy
# Create a new material
red_material = bpy.data.materials.new(name="Red")
# Set the diffuse color to red with full opacity
red_material.diffuse_color = (1.0, 0.0, 0.0, 1.0)
# Assign the material to the selected objects
for obj in bpy.context.selected_objects:
if obj.type == 'MESH':
obj.data.materials.append(red_material)
-----------------------------------------------------------------
import bpy
# Create a green material
green_material = bpy.data.materials.new(name="Green")
green_material.diffuse_color = (0, 1, 0, 1) # Set color to red
# Assign the red material to selected objects after removing old materials
for obj in bpy.context.selected_objects:
# Remove existing materials
obj.data.materials.clear()
# Append the red material to the object
obj.data.materials.append(green_material)
----------------------------------------------------------------
import bpy
# Create a new material
red_material = bpy.data.materials.new(name="Red")
# Set the diffuse color to red with full opacity
red_material.diffuse_color = (1.0, 0.0, 0.0, 1.0)
# Assign the material to the selected objects
for obj in bpy.context.selected_objects:
if obj.type == 'MESH':
# Remove the old material from the object
obj.active_material_index = 0
bpy.ops.object.material_slot_remove()
# Add the new material to the object
obj.data.materials.append(red_material)
----------------------------------------------------------------------
import bpy
# Get the selected objects
selected_objects = bpy.context.selected_objects
# Create a new material
material = bpy.data.materials.new(name="Red")
material.diffuse_color = (1, 0, 0, 1) # Set the color to red
# Assign the material to each selected object
for obj in selected_objects:
if obj.type == "MESH":
obj.data.materials.append(material)
# Create modifier and apply
modifier = obj.modifiers.new(name="Subdivision Surface", type="SUBSURF")
modifier.levels = 3 # Set the subdivision level to 3
bpy.ops.object.modifier_apply(modifier=modifier.name) # Apply the modifier
-----------------------------------------------------------------------------------------
import bpy
class MyPanel(bpy.types.Panel):
bl_label = "My Panel"
bl_idname = "OBJECT_PT_my_panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "My Addon"
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("object.my_operator")
class MyOperator(bpy.types.Operator):
bl_idname = "object.my_operator"
bl_label = "Sihirli Buton"
def execute(self, context):
# Get the selected objects
selected_objects = bpy.context.selected_objects
# Create a new material
material = bpy.data.materials.new(name="Red")
material.diffuse_color = (1, 0, 0, 1) # Set the color to red
# Assign the material to each selected object
for obj in selected_objects:
if obj.type == "MESH":
obj.data.materials.append(material)
# Add subdivision modifier and apply
modifier = obj.modifiers.new(name="Subdivision Surface", type="SUBSURF")
modifier.levels = 3 # Set the subdivision level to 3
bpy.ops.object.modifier_apply(modifier=modifier.name) # Apply the modifier
# Add shade smooth
bpy.ops.object.shade_smooth()
return {'FINISHED'}
def register():
bpy.utils.register_class(MyPanel)
bpy.utils.register_class(MyOperator)
def unregister():
bpy.utils.unregister_class(MyPanel)
bpy.utils.unregister_class(MyOperator)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment