Hint:
It’s better to embed code with a triple backtick at the start and end or use Ctrl-e or use the preformatted text </>
–icon in the WYSIWYG–editor tool bar… maybe with an additional “file name” like so (copied from the previous history version enabled in raw format ) :
YouNameit.py
( AxisScaleShortCut.py ?? )
import bpy
from bpy.props import EnumProperty
class AlignToPivotOperator(bpy.types.Operator):
"""Scale selection to align with the transform pivot point along a specified axis"""
bl_idname = "transform.align_to_pivot"
bl_label = "Align to Pivot"
bl_options = {'REGISTER', 'UNDO'}
axis: EnumProperty(
name="Axis",
items=[
('X', "X Axis", "Align along the X axis"),
('Y', "Y Axis", "Align along the Y axis"),
('Z', "Z Axis", "Align along the Z axis"),
],
default='X',
)
def execute(self, context):
axis_index = {'X': 0, 'Y': 1, 'Z': 2}[self.axis]
# Ensure we're in Edit Mode
if context.object.mode != 'EDIT':
self.report({'ERROR'}, "Must be in Edit Mode")
return {'CANCELLED'}
# Apply scaling to zero along the specified axis
bpy.ops.transform.resize(
value=[0 if i == axis_index else 1 for i in range(3)],
orient_type='GLOBAL' # Use a valid orientation type like 'GLOBAL'
)
return {'FINISHED'}
def register():
bpy.utils.register_class(AlignToPivotOperator)
# Add keymaps
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Mesh', space_type='EMPTY')
for axis in ['X', 'Y', 'Z']:
kmi = km.keymap_items.new(
AlignToPivotOperator.bl_idname,
type=axis,
value='PRESS',
alt=True,
ctrl=True
#ALT AND CTRL ARE THE CURRENT SHORTCUT
)
kmi.properties.axis = axis
def unregister():
bpy.utils.unregister_class(AlignToPivotOperator)
# Remove keymaps
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.get('Mesh')
if km:
for kmi in km.keymap_items:
if kmi.idname == AlignToPivotOperator.bl_idname:
km.keymap_items.remove(kmi)
if __name__ == "__main__":
register()
Also: If used as addon there is some need of something like:
bl_info = {
"name": "AxisScale",
"version": (0, 1),
}
…then it is better findable after installation via Blender Preferences → Install…–button ( here: AxisScale
)
( So it does install more easier with this but i still hadn’t figured out how to use it ? Only in edit mode… yes… should be a shortcut…but which one ?? But then i also didn’t looked too much into the code )
For extension this had changed…