Post #4972: Sure thing!
📋 Metadata
- Author: Adam_Szalai
- Date: 2023-12-12 17:13:51
- Type:
answer - Quality Score: 8/10
- Reply to: post_04971
- Replies (2): post_04973, post_04974
🏷️ Tags
macro python-scripting advanced solved
⚙️ Related PME Features
- Macro Editor
- Modal Editor
- Python Scripting
💬 Content
Sure thing!
At leats they are pretty simple codes 
so structure is the next:
Modal operator:
-
slot 01: On Invoke / Operator_instancemesh_scale_sewing_macro
-Operator_instancemesh_scale_sewing_macro:
slot 01: py file 01:import bpy
Get the initially selected object
selected_object = bpy.context.active_object
if selected_object is not None: # Remove the last 5 characters and add “Sewing_Instance_Mesh” as suffix new_name = selected_object.name[:-5] + “Sewing_Instance_Mesh”
bpy.ops.object.mode_set(mode='OBJECT') # Deselect all objects bpy.ops.object.select_all(action='DESELECT') # Select the object with the new name bpy.data.objects[new_name].select_set(True) # Set the active object to the newly selected object bpy.context.view_layer.objects.active = bpy.context.scene.objects[new_name] print(f"Object renamed to {new_name} and selected as the active object.")else: print(“No active object selected.”)
-
slot 02: Transform_Resize_Editmode_invoke_macro
-Transform_Resize_Editmode_invoke_macro:
slot 01: bpy.ops.object.mode_set(mode=‘EDIT’)
slot 02: bpy.ops.mesh.select_all(‘EXEC_DEFAULT’, True, action=‘SELECT’)
slot 03: bpy.ops.transform.resize(release_confirm=True)
slot 02: On Cancel / second py file:
import bpy
# Get the initially selected object
selected_object = bpy.context.active_object
# Get the name of the initially selected object
initial_name = selected_object.name
# Find the index of "_Cloth_" in the name
cloth_index = initial_name.find("_Cloth_")
# Find the index of the 2-digit number after "_Cloth_"
number_index = cloth_index + 7 # Length of "_Cloth_" is 7
while number_index < len(initial_name) and initial_name[number_index].isdigit():
number_index += 1
# Construct the new name
new_name = initial_name[:number_index] + "_Baked"
bpy.ops.object.mode_set(mode='OBJECT')
# Deselect all objects
bpy.ops.object.select_all(action='DESELECT')
# Select the object with the constructed name
bpy.data.objects[new_name].select_set(True)
# Set the active object
bpy.context.view_layer.objects.active = bpy.data.objects[new_name]
# Print the constructed name
print(new_name)
- slot 03: On Confirm / second py file (as above)
also don’t know why i can’t assign hotkey to ‘on cancel’ and ‘on confim’
in the video there is no problem to do that
Thank You for the help already 
ok i start to see that i’m missing some set to object modes 
still working on it (code fixed above)!
Now the “states” of the modal are working but my problem is that as i enter to the scale phase and i try to click on the scale field numbers the modal drops me to the ‘on cancel’/‘on confirm’ state.
hmm not sure how should i address the on cancel on confirm states to key ESC, since i need my mouse click for the actual sizing (to clicking in the number field of the sizing)
using PME 1.18.5:
So i have 2 issues now:
-modal goes to on cancel/on confirm if i click LMB or RMB or press ESC (if i disable On Cancel, and leave On Confirm turned on, ESC is still quit from modal, but what ESC is doing with On Confirmt anyway?)
-modal (or something) is stucking the scale context menu leaving the modal, and scales the actually selected object in edit mode even if blender is in object mode.
i would need to get rid of that scale context menu when leaving the modal
Remove On Cancel and Confirm On Release are turned on, but still the context menu is there despite the modal is quit.
even with python i can’t get rid of from the transform menu at code start. i have to click one on the 3dview (even can click on an object) to get rid of the transform context menu
image1143×589 49.2 KB