Post #4875: I really love that video, downloaded it right away, since i want to make somethi

📋 Metadata

🏷️ Tags

macro python-scripting intermediate unsolved

  • Macro Editor
  • Python Scripting

💬 Content

I really love that video, downloaded it right away, since i want to make something similar with other stuffs (but can be also great for CFA)
But! :slight_smile:
I found a code that doing what i (think i) need now. It simply text overlay what i want, but there is a problem (and maybe You referred on that can be problem with text overlay and PME, and yes, this code is not working via PME.
Question: is there any way to make this code workable via PME?
I already have a ptyhon code that toogles on off the CFA, and i could simply attach this code (and the remove version) to turn on off the “CFA on” text overlay.
It works perfectly from Text Editor :smiley:

Blockquote

import bpy
import bgl
import blf

def draw_callback_px(self, context):
font_id = 0
blf.position(font_id, 50, 50, 0)
blf.size(font_id, 50, 72)
blf.color(font_id, 1.0, 0.5, 0.0, 1.0) # Orange color
blf.draw(font_id, “CFA On”)

def register_hello_world_overlay():
bpy.app.driver_namespace[‘caf’] = bpy.types.SpaceView3D.draw_handler_add(
draw_callback_px, (None, bpy.context), ‘WINDOW’, ‘POST_PIXEL’
)

def unregister_hello_world_overlay():
if ‘caf’ in bpy.app.driver_namespace:
bpy.types.SpaceView3D.draw_handler_remove(bpy.app.driver_namespace[‘caf’], ‘WINDOW’)

if name == “main ”:
register_hello_world_overlay()

Blockquote

And i would use those text overlay codes with this code:

Blockquote

import bpy
import os

Check if the toggle variable exists, if not set it to True

if “toggle_state” not in bpy.context.scene:
bpy.context.scene[“toggle_state”] = True

Get the current state from the toggle variable

toggle_state = bpy.context.scene[“toggle_state”]

Set the parameters based on the toggle state

bpy.context.scene.tool_settings.use_transform_correct_face_attributes = toggle_state
bpy.context.scene.tool_settings.use_transform_correct_keep_connected = toggle_state

Update the toggle state for the next run

bpy.context.scene[“toggle_state”] = not toggle_state

Define paths to the scripts you want to run

script_true_path = r”*****_remove.py”
script_false_path = r”****.py”

Execute the appropriate script based on the toggle state with error handling

try:
if toggle_state:
exec(compile(open(script_true_path).read(), script_true_path, ‘exec’), globals())
else:
exec(compile(open(script_false_path).read(), script_false_path, ‘exec’), globals())
except Exception as e:
print(f”Error executing script: {e}”)

Blockquote

i tried calling in this code, and it works fine, but the text overlay isn’t working at all, only from Text Editor

Plus, don’t know why but those referred py-s only working with absolute path, if i add relative path, those called py-s are not working, even if i call those pys from the very same folder.


❤️ 1 likes


🔗 View on Blender Artists