Add custom properties while drawing a panel?

I know its impossible, but is there a way around it?

Basically, I want the user to select an internal text file then the script will find the classes in the text file, add a property for each one, then display the properties in the panel. Is there any way to do this without the user pressing a button?

This is the error I get:
RuntimeError: Calling operator “bpy.ops.object.createvar” error, can’t modify blend data in this state (drawing/rendering)


You might be able to try something like this…

import threading
import time

def thread_review(lock, passedValue, passedSleepTime):
    print (passedValue)

myVariable = 4.20
lock = threading.Lock()
lock_holder = threading.Thread(target=thread_review, args=(lock,myVariable,0.1), name='MyThreadNameHere')

Launch a thread that will execute code after a short delay. This should allow the panel to exit out and not complain. Put your code to add the custom properties in the thread_review def.

The next time the panel draw gets an event, it can try again to operate upon the newly create custom properties.

That works perfectly! Thanks!