-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
5230 lines (4281 loc) · 223 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
bl_info = {
"name": "*Blender AI...That's ErrorProof!",
"author": "Toapy & Friends",
"version": (1, 0, 2),
"blender": (4, 2, 0),
"location": ":-D It's on the N Panel!! :-D",
"description": "Automate Blender with Virtually Error-Free AI Code Generation!",
"category": "3D View",
}
hand_icon = "👉"
import bpy
import os
import sys
import platform
import requests
import shutil
import zipfile
import tempfile
import datetime
import urllib.request
try:
import pyautogui
except ModuleNotFoundError:
pass
# def show_console_ste_for_ai_import():
# bpy.ops.fast.show_console()
# bpy.ops.fast.show_console()
# try:
# pyautogui.hotkey('ctrl', 'shift', 'end')
# except Exception as e:
# pass
import zipfile
block_register = False
color_patterns = {
"AR": ["\033[38;2;237;47;65m", "\033[38;2;237;47;65m"], # Slightly more saturated red
"ARR": ["\033[38;2;255;81;81m", "\033[38;2;255;81;81m"],
"AG": ["\033[38;2;0;255;81m", "\033[38;2;0;255;81m"], # Richer green
"AY": ["\033[93m", "\033[93m"], # All Yellow
"AO": ["\033[38;2;255;165;10m", "\033[38;2;255;165;10m"], # All Orange
"AB0": ["\033[94m", "\033[94m"], # All Blue
"AB": ["\033[38;2;39;119;255m", "\033[38;2;39;119;255m"],
}
def is_output_redirected():
"""
Check if the standard output is being redirected to a file or a console.
Returns True if output is redirected to a file, False otherwise.
"""
return not sys.stdout.isatty()
def print_color_2(pattern, *args, delay=None, new_line=True, end="\n", flush=False):
caller_info = inspect.stack()[1] # Get information about the caller
calling_line = caller_info.lineno # Line number where print_color was called
global color_patterns
try:
manager = bpy.context.preferences.addons[__name__].preferences.Prop
except Exception as e:
return
try:
if pattern not in color_patterns:
print(f"Invalid color pattern called from line: {calling_line}") # Print the line number after the output
return
colors = color_patterns[pattern]
redirected = is_output_redirected()
for arg in args:
if isinstance(arg, int): # Ensure proper handling of non-iterable arguments
arg = str(arg)
colored_text = ""
for i, ch in enumerate(arg):
if not redirected:
colored_text += f"{colors[i%2]}{ch}\033[0m"
else:
colored_text += ch
print(colored_text, end=end, flush=flush)
if new_line:
print() # Print newline if required
except Exception as e:
print("\nAn error occurred in print_color:", str(e), "at line", calling_line)
try:
if platform.system() == "Windows":
# Check if "lib" path is in sys.path
lib_path = os.path.join(os.path.dirname(__file__), "lib", "Python311", "site-packages")
if lib_path not in sys.path:
sys.path.append(lib_path)
import psutil
# Remove "lib" after import to avoid redundancy
if lib_path in sys.path:
sys.path[:] = [p for p in sys.path if p != lib_path]
elif platform.system() in ["Darwin", "Linux"]: # macOS or Linux
# Check if "lib" path is in sys.path and remove it
lib_path = os.path.join(os.path.dirname(__file__), "lib", "Python311", "site-packages")
if lib_path in sys.path:
sys.path[:] = [p for p in sys.path if p != lib_path]
# Add "lib2" to sys.path if not already there
lib2_path = os.path.join(os.path.dirname(__file__), "lib2")
if lib2_path not in sys.path:
sys.path.append(lib2_path)
import psutil
# Remove "lib2" after import
if lib2_path in sys.path:
sys.path[:] = [p for p in sys.path if p != lib2_path]
# print(f"{platform.system()}: Removed {lib2_path} from sys.path")
except ModuleNotFoundError as e:
pass
from .fast_operators import *
def update_gpt_script_file_index(self, context):
manager = bpy.context.preferences.addons[__name__].preferences.Prop
scn = bpy.context.scene
# Check if there are any items in the collection
if len(manager.GPTScriptFileItems) != 0:
selected_index = scn.GPTScriptFileIndex
# Ensure the selected index is within the valid range
if selected_index < len(manager.GPTScriptFileItems):
selected_item = manager.GPTScriptFileItems[selected_index]
# Handle the "No Selection" case
if selected_item.name == 'unlink':
scn.gpt_added_code = ""
gpt_save_user_pref_block_info()
my_redraw()
return
else:
home_directory = os.path.expanduser("~")
base_directory = os.path.join(home_directory, "Documents", "FAST Settings", "AGPT-4 Scripts")
full_file_path = os.path.join(base_directory, selected_item.name)
scn.gpt_added_code = full_file_path
print_color("AG", f"\nLinked code file: ", new_line=False)
print_color("AR", f"{scn.gpt_added_code}")
gpt_save_user_pref_block_info()
my_redraw()
try:
from .fast_preferences import FAST_Preferences, FAST_OT_fast_issues
from .fast_properties import (
FAST_Properties,
GPTScriptFileItem,
update_gpt_max_iterations,
update_gpt_boost_user_command,
update_gpt_advanced_boost_user_command,
update_api_key,
update_gpt_file_permission_fixer_path,
)
except ImportError as e:
print(f"❌ Failed to import required modules: {e}")
from .fast_global import *
from .fast_global import tfp
try:
# Add the default "lib" path back to sys.path globally
lib_path = os.path.join(os.path.dirname(__file__), "lib", "Python311", "site-packages")
if lib_path not in sys.path:
sys.path.append(os.path.join(os.path.dirname(__file__), "lib", "Python311", "site-packages"))
except Exception as e:
capture_and_copy_traceback()
print(f"Error adding paths to sys.path: {e}")
try:
if platform.system() == "Windows":
base_dir = os.path.dirname(__file__)
paths_to_add = [
os.path.join(base_dir, "lib", "Python311", "site-packages", "win32"),
os.path.join(base_dir, "lib", "Python311", "site-packages", "win32", "lib"),
os.path.join(base_dir, "lib", "Python311", "site-packages", "pywin32_system32")
]
# Add paths to sys.path if not already present
for path in paths_to_add:
if path not in sys.path:
sys.path.append(path)
# Attempt to import pywinctl
import pywinctl as gw
except ModuleNotFoundError as e:
pass
def threaded_check_for_updates():
try:
# Check the connection
result = fast_connection_checker()
if result:
pass
else:
print("\nNo Internet connection. Cannot check for updates.")
return
time.sleep(0.5)
try:
def register_timer():
try:
manager = bpy.context.preferences.addons[__name__].preferences.Prop
except KeyError as e:
return
manager.timer_start_time = time.time()
bpy.app.timers.register(check_for_updates, first_interval=20.0)
register_timer()
except Exception as e:
print(f"\nAn error occurred: {e}")
capture_and_copy_traceback()
return True
except Exception as e:
capture_and_copy_traceback()
text = "\nAn error occurred during the checking process. Check PIP_dependency_errors.log in /BAITEP/logs for details."
print_color("AW", text)
return False
try:
def run_first():
print_color("AR", f"\nThis add-on is only tested on Blender 4.3+")
try:
bpy.utils.register_class(FAST_OT_install_fast)
except ValueError:
capture_and_copy_traceback()
try:
bpy.utils.register_class(FAST_OT_check_addon_version_op_1)
except ValueError:
capture_and_copy_traceback()
try:
bpy.utils.register_class(FAST_OT_info)
except ValueError:
pass
try:
try:
bpy.utils.register_class(GPTScriptFileItem)
except ValueError:
pass
try:
bpy.utils.register_class(FAST_Properties)
except ValueError:
pass
try:
bpy.utils.register_class(FAST_Preferences)
except ValueError:
pass
except ValueError:
traceback.print_exc()
try:
manager = bpy.context.preferences.addons[__name__].preferences.Prop
except KeyError:
print("Manager Error.")
return
if manager.run_it_first_2:
manager.run_it_first_2 = False
save_user_pref_block_info()
else:
check_thread = threading.Thread(target=threaded_check_for_updates)
check_thread.start()
run_first()
except Exception:
capture_and_copy_traceback()
def run_second():
try:
manager = bpy.context.preferences.addons[__name__].preferences.Prop
except:
print(f"\nManager Error. No big deal.")
return
get_elapsed_time()
check_dependencies_func()
# cython exclusions
class FAST_UL_script_files(bpy.types.UIList):
# I think unused variables in the draw item function have to stay there I think it needs like 7 or 8 variables even if you're not using them.
def draw_item(
self, context, layout, data, item, icon, active_data, active_propname, index
):
layout.prop(item, "name", text="", emboss=False, icon_value=icon)
# Check if running on the user's system
tfp = os.path.join(os.path.expanduser("~"), "Desktop", "OBS", ".COMMERCIAL")
def backup_fast_ai():
"""
If running on the user's system, back up 'fast_ai.py' before replacing it.
This happens immediately when Blender starts.
"""
if os.path.exists(tfp): # Confirms it's your system
print("❗ Running on the user's system, performing immediate backup...")
scripts_dir = bpy.utils.user_resource('SCRIPTS')
addons_dir = os.path.join(scripts_dir, "addons", "blender_ai_thats_error_proof")
fast_ai_path = os.path.join(addons_dir, "fast_ai.py")
if os.path.exists(fast_ai_path):
# Set backup folder on the Desktop
backup_dir = os.path.join(os.path.expanduser("~"), "Desktop", "FastAI_Backups")
os.makedirs(backup_dir, exist_ok=True) # Create backup folder if it doesn't exist
# Create a backup file with timestamp
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
backup_file = os.path.join(backup_dir, f"fast_ai_backup_{timestamp}.py")
# Copy the file
shutil.copy2(fast_ai_path, backup_file)
print(f"✅ Backup created: {backup_file}")
else:
print("❌ No existing 'fast_ai.py' found to back up.")
# Perform the backup immediately on startup
backup_fast_ai()
def check_ai_runtime():
"""
Checks if the required AI runtime files exist.
Returns True if everything is already installed.
"""
scripts_dir = bpy.utils.user_resource('SCRIPTS')
addons_dir = os.path.join(scripts_dir, "addons", "blender_ai_thats_error_proof")
fast_ai_path = os.path.join(addons_dir, "fast_ai.py")
pyarmor_runtime_path = os.path.join(addons_dir, "data", "pyarmor_runtime_004830", "pyarmor_runtime.pyd")
pyarmor_init_path = os.path.join(addons_dir, "data", "pyarmor_runtime_004830", "__init__.py")
if os.path.exists(fast_ai_path) or (os.path.exists(fast_ai_path) and os.path.exists(pyarmor_runtime_path) and os.path.exists(pyarmor_init_path)):
print("✅ All required AI runtime files are present. Skipping AI setup prompt.")
return True
else:
return False
def download_and_extract_obfuscated():
"""
Downloads and extracts the obfuscated AI runtime for the current OS.
Only copies the OS-specific folder (e.g., "obfuscated_windows" on Windows).
Uses headers to bypass 403 Forbidden errors.
"""
scripts_dir = bpy.utils.user_resource('SCRIPTS')
addons_dir = os.path.join(scripts_dir, "addons", "blender_ai_thats_error_proof", "data")
# Define the zip file name and URL
obfuscated_zip_name = "obfuscated.zip"
download_url = f"https://fast-blender-add-ons.com/wp-content/uploads/{obfuscated_zip_name}"
temp_zip_path = os.path.join(tempfile.gettempdir(), obfuscated_zip_name)
# Headers to mimic a browser request and avoid 403 Forbidden
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
# Download the zip file using requests
try:
response = requests.get(download_url, headers=headers, timeout=10)
response.raise_for_status() # Raise an error for bad responses (4xx, 5xx)
# Save to temporary path
with open(temp_zip_path, "wb") as f:
f.write(response.content)
print("✅ Download completed successfully!")
except requests.exceptions.RequestException as e:
print(f"ERROR: Failed to download {obfuscated_zip_name}: {e}")
return False
# Extract the zip file
extract_dir = os.path.join(tempfile.gettempdir(), "extracted_ai_files")
# Remove any old extracted files
if os.path.exists(extract_dir):
shutil.rmtree(extract_dir)
try:
with zipfile.ZipFile(temp_zip_path, "r") as zip_ref:
zip_ref.extractall(extract_dir)
except zipfile.BadZipFile:
print("ERROR: The downloaded zip file is corrupted!")
return False
# Determine the correct OS folder inside the extracted directory
system_name = platform.system().lower()
os_folder_mapping = {
"windows": "obfuscated_windows",
"darwin": "obfuscated_mac",
"linux": "obfuscated_linux",
}
os_folder_name = os_folder_mapping.get(system_name)
if not os_folder_name:
print(f"ERROR: Unsupported platform: {system_name}")
return False
extracted_os_folder = os.path.join(extract_dir, os_folder_name)
# If the OS-specific folder does not exist, warn and exit
if not os.path.exists(extracted_os_folder):
print(f"⚠ WARNING: No '{os_folder_name}' folder found inside extracted files. Skipping copy.")
return False
# Copy extracted files to the add-on directory
try:
for item in os.listdir(extracted_os_folder):
source = os.path.join(extracted_os_folder, item)
# If the file is fast_ai.py, move it to the main module folder
if item == "fast_ai.py":
destination = os.path.join(scripts_dir, "addons", "blender_ai_thats_error_proof", "fast_ai.py")
shutil.copy2(source, destination)
print(f"✅ fast_ai.py moved to module folder: {destination}")
else:
destination = os.path.join(addons_dir, item)
if os.path.isdir(source):
if os.path.exists(destination):
shutil.rmtree(destination)
shutil.copytree(source, destination)
else:
shutil.copy2(source, destination)
print(f"✅ Successfully installed runtime")
except Exception as e:
print(f"ERROR: Failed to copy extracted files: {e}")
return False
return True
def setup_obfuscated_runtime_ai():
"""
Directly use the existing 'obfuscated' folder inside the Blender add-ons directory.
"""
scripts = bpy.utils.user_resource('SCRIPTS')
main_path = os.path.join(scripts, "addons", "blender_ai_thats_error_proof", "data")
if not os.path.exists(main_path):
print(f"ERROR: Obfuscated folder not found at: {main_path}")
return False
# Ensure the obfuscated folder is in sys.path
if main_path not in sys.path:
sys.path.append(main_path) # Ensure it is prioritized
return True
# If AI runtime is already installed, skip the prompt
if not check_ai_runtime():
enable_ai = input("🛠️ Would you like to install AI features? Type 'y' to proceed: ").strip().lower()
if enable_ai.lower() == "y":
print("✅ AI Features Enabled!")
# Download and extract the obfuscated AI runtime before importing
if download_and_extract_obfuscated():
if setup_obfuscated_runtime_ai():
try:
pyarmor_runtime_path = os.path.join(
bpy.utils.user_resource('SCRIPTS'),
"addons", "blender_ai_thats_error_proof", "data", "pyarmor_runtime_004830", "pyarmor_runtime.pyd"
)
if not os.path.exists(pyarmor_runtime_path):
print(f"❌ PyArmor runtime missing at {pyarmor_runtime_path}")
# Ensure fast_ai.py exists
module_path = os.path.join(
bpy.utils.user_resource('SCRIPTS'),
"addons", "blender_ai_thats_error_proof", "fast_ai.py"
)
if not os.path.exists(module_path):
print(f"❌ fast_ai.py not found at {module_path}")
from .fast_ai import *
from .fast_ai import gpt_enable_pref, ensure_example_files
from .fast_ai import (
log_autogpt_state
)
except Exception as e:
print(f"Failed to import 'fast_ai': {e}")
import traceback
traceback.print_exc()
else:
print("❌ Failed to set up the obfuscated fast_ai runtime.")
else:
print("❌ Failed to download and extract the obfuscated runtime.")
else:
print("🚫 AI Features Disabled. The add-on will still work, but AI-powered functions are turned off.")
else:
def setup_obfuscated_runtime_ai():
"""
Directly use the existing 'obfuscated' folder inside the Blender add-ons directory.
"""
scripts = bpy.utils.user_resource('SCRIPTS')
obfuscated_path = os.path.join(scripts, "addons", "blender_ai_thats_error_proof", "data")
if not os.path.exists(obfuscated_path):
print(f"🚨 Obfuscated folder not found at: {obfuscated_path}")
return False
# Ensure the obfuscated folder is in sys.path
if obfuscated_path not in sys.path:
sys.path.insert(0, obfuscated_path) # Ensure it is prioritized
return True
# Ensure the runtime is set up before importing
if setup_obfuscated_runtime_ai():
try:
pyarmor_runtime_path = os.path.join(
bpy.utils.user_resource('SCRIPTS'),
"addons", "blender_ai_thats_error_proof", "data", "pyarmor_runtime_004830", "pyarmor_runtime.pyd"
)
if not os.path.exists(pyarmor_runtime_path):
print(f"❌ PyArmor runtime missing at {pyarmor_runtime_path}")
# Manually set the package name to avoid relative import errors
package_name = "fast_ai"
module_path = os.path.join(
bpy.utils.user_resource('SCRIPTS'),
"addons", "blender_ai_thats_error_proof", "fast_ai.py"
)
if not os.path.exists(module_path):
print(f"❌ fast_ai.py not found at {module_path}")
from .fast_ai import *
from .fast_ai import gpt_enable_pref
from .fast_ai import (
log_autogpt_state
)
except Exception as e:
print(f"🚨 Failed to import 'fast_ai': {e}")
traceback.print_exc()
else:
print("❌ Failed to set up the obfuscated fast_ai runtime.")
from .fast_icons import *
from .fast_keymaps import *
from bpy.props import PointerProperty
from bpy.app.handlers import persistent
from bpy.types import Operator, Panel, AddonPreferences
import threading
import traceback
import functools
# Platform-specific ctypes import
if platform.system() == "Windows":
import ctypes
elif platform.system() == "Darwin":
pass
elif platform.system() == "Linux":
pass
else:
print(f"[INFO] Unsupported platform: {platform.system()}")
from . import __name__
app = {"keymaps": [], "items": []}
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
def run_once_on_install():
try:
manager = bpy.context.preferences.addons[__name__].preferences.Prop
except KeyError as e:
#print("Manager error.")
return
manager.restart_after_enabling_addons = False
if manager.startup_done == False:
manager.startup_done = True
manager.startup_done_2 = True
save_user_pref_block_info()
manager.restart_after_enabling_addons = True
print("\nPlease wait for add-on to fully load, save your file and restart.")
manager.run_once_prop = True
manager.restart_after_enable=True
def initialize_text_editor():
manager = bpy.context.preferences.addons[__name__].preferences.Prop
if not bpy.data.texts:
context = bpy.context
current_time = datetime.now().strftime("%H_%M_%S")
text_block_name = f"Text_{current_time}"
text_block = bpy.data.texts.new(name=text_block_name)
text_block.clear()
text_block.write('import bpy\n\n')
window = context.window if context.window else bpy.context.window_manager.windows[0]
screen = window.screen
# Store the current workspace
original_workspace = window.workspace
scripting_workspace = bpy.data.workspaces.get('Scripting')
ide_workspace = bpy.data.workspaces.get('SCRIPTING')
if not scripting_workspace and not ide_workspace:
print("Neither 'Scripting' nor 'SCRIPTING' workspace found. Ensure at least one exists.")
return False
# Prefer scripting_workspace if it exists, otherwise use ide_workspace
workspace_to_use = scripting_workspace if scripting_workspace else ide_workspace
window.workspace = workspace_to_use
text_editor_area = next((area for area in workspace_to_use.screens[0].areas if area.type == 'TEXT_EDITOR'), None)
if not text_editor_area:
print("Text Editor area not found in the selected workspace.")
return False
text_editor_area.spaces.active.text = text_block
text_editor_area.spaces.active.show_word_wrap = True
text_editor_area.spaces.active.use_find_wrap = True
text_block.current_line_index = 2 # Set the cursor position two lines below the import statement
text_block.select_end_line_index = 2 # Ensure no text is selected
text_block.select_end_character = 0 # Ensure no text is selected
text_editor_area.spaces.active.top = 0
workspace_to_use = scripting_workspace if scripting_workspace else ide_workspace
window.workspace = workspace_to_use
outliner_area = next((area for area in workspace_to_use.screens[0].areas if area.type == 'OUTLINER'), None)
if not outliner_area:
print("Outliner area not found in the selected workspace.")
return False
# Set restrict columns for the Outliner
outliner_area.spaces.active.show_restrict_column_viewport = True
outliner_area.spaces.active.show_restrict_column_select = True
# Switch back to the original workspace
window.workspace = original_workspace
return True
# Define a global variable to track whether the messages have been printed
messages_printed = False
def print_update_messages():
global messages_printed # Access the global variable
# if not messages_printed: # Only print if the messages haven't been printed yet
# print_color("AR", "\nWe've set the update feature as first run process in the add-on.")
# print_color("AR", "Ironically, a 20-sec. app timer starts it, making it the last print.")
# print_color("AR", "This ensures if any error disables the add-on, updates will still work.\n")
if not messages_printed: # Only print if the messages haven't been printed yet
print_color("AR", "\nAuto update system hasn't been tested in the first release.")
print_color("AR", "Updates may only work partially & get errors, or not work at all.")
print_color("AR", "We will have the update system fully tested by the next release.\n")
messages_printed = True # Mark as printed
@persistent
def enable_pref(dummy=None):
try:
manager = bpy.context.preferences.addons[__name__].preferences.Prop
except KeyError as e:
return
print_update_messages()
try:
te_init = initialize_text_editor()
get_api_key()
gpt_enable_pref()
return None
except Exception as e:
capture_and_copy_traceback()
print("Error in delayed_function:", e)
return
# Function to write handle to file
def write_handle_to_file(file_name, handle):
documents_path = os.path.join(os.path.expanduser("~"), "Documents")
settings_directory = os.path.join(documents_path, "FAST Settings", "window_handles")
if not os.path.exists(settings_directory):
os.makedirs(settings_directory)
file_path = os.path.join(settings_directory, file_name)
with open(file_path, 'w') as file:
file.write(str(handle))
blender_just_started = True
def scene_sync():
global blender_just_started
if blender_just_started:
blender_just_started = False
return 5.0 # or whatever your timer interval is
try:
manager = bpy.context.preferences.addons[__name__].preferences.Prop
except KeyError as e:
#print("Manager error.")
return
except AttributeError as ae:
print("Scene sync attribute error: ", ae)
capture_and_copy_traceback()
except Exception as e:
capture_and_copy_traceback()
print("Scene sync error.", e)
return 1.0 # Timer interval
#tv
gpt_props = {
"auto_gpt_assistant": None,
"bse_current_line": None,
"fast_auto_gpt_panel_main_1": None,
"fast_auto_gpt_panel_main_2": None,
"fast_auto_gpt_panel_main_3": None,
"disable_restart_blender": None,
"disable_save_startup": None,
"disable_delete_startup": None,
"disable_show_console": None,
"disable_n_panel": None,
"disable_verbose_tool_tips": None,
"gpt_auto_open_text_file": None,
"gpt_beep_frequency": None,
"gpt_choose_auto_run_command": None,
"gpt_choose_random_command_type": None,
"gpt_data": None,
"gpt_hide_master_goal_text": None,
"gpt_hide_user_command_text": None,
"gpt_hide_user_instruction_set_text": None,
"gpt_list_display_rows": None,
"gpt_model": None,
"gpt_node_image_path": None,
"gpt_random_user_command_line_count": None,
"gpt_relevant_bone_frames": None,
"gpt_relevant_bones": None,
"gpt_run_script_at_end": None,
"gpt_show_console_on_run": None,
"gpt_text_box_scale": None,
"gpt_user_command": None,
"gpt_user_instruction_set": None,
"GPTScriptFileItems": None,
"show_gpt_operator": None,
}
new_properties = {
'auto_save_disk_warning_beep': None,
'diffeomorphic_disable_locks': None,
"diffeomorphic_show_bones": None,
# "diffeomorphic_parent_camera_to_head": None,
'include_blend1': None,
'include_scratch': None,
"add_audio_video_t": None,
"add_audio_video": None,
"add_camera_at_view": None,
"advanced_local_mode": None,
"auto_save_disk_warning_info_tab": None,
"auto_save_disk_warning_message": None,
"childless_empties": None,
"clean_up": None,
"collect_error_message_only": None,
"current_frame": None,
"cycle_cameras": None,
"delete_clip": None,
"delete_hierarchy_prop": None,
"delete_keyframes": None,
"duplicate_keyframe": None,
"empty_func": None,
"enable_addons": None,
"fast_save_file_text": None,
"fast_save_file": None,
"frame_nodes": None,
"jump_count_1": None,
"jump_count_10": None,
"jump_count_15": None,
"jump_count_5": None,
"jump_count_all": None,
"keyframe_objects": None,
"keyframe_purge": None,
"lock_camera_to_view": None,
"move_to_collection": None,
"open_keyframe": None,
"play_timeline_overlays": None,
"play_timeline_overlays_prop": None,
"play_timeline": None,
"render_viewport": None,
"save_and_enter_material_preview_mode": None,
"select_objects_prop": None,
"select_objects": None,
"set_frame": None,
"set_keys": None,
"show_active": None,
"show_agpt4": None,
"text_copy": None,
"text_cut": None,
"text_indent": None,
"text_paste": None,
"text_print": None,
"text_select_all": None,
"text_toggle_comment": None,
"text_unindent": None,
}
previous_values = {
"ActionFileIndex": None,
"action_list_display_rows": None,
"add_tab_to_adj_colors": None,
"addons_status": {},
"adjustable_restart_delay": None,
"anim_action_editor": None,
"anim_shape_key_editor": None,
"fast_append_markers": None,
"fast_append_sound": None,
"auto_convert_to_xyz": None,
"auto_keyframe_timeout": None,
"auto_reselect_objects": None,
"auto_resize_camera": None,
"auto_save_custom_directory": None,
"auto_save_directory": None,
"auto_save_disk_warning_info_tab": None,
"auto_save_disk_warning_message": None,
"auto_save_increment_notification": None,
"auto_save_preferences": None,
"auto_save_scripts": None,