Hi @AymanAl-Maaraf,
Here’s a simplified version that will work for both Text and MText. Also, there is no need to pass in the handles of the objects like the previous version. Just pass in the objects themselves, like below. It will filter out any objects that are not Text or MText, and it will return the newly-modified text contents.
import clr
clr.AddReference('AcDbMgd')
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
adoc = Application.DocumentManager.MdiActiveDocument
def text_to_upper(dynObjs):
if not dynObjs:
return
if not isinstance(dynObjs,list):
dynObjs = [dynObjs]
global adoc
output=[]
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
for dynObj in dynObjs:
acObj=t.GetObject(dynObj.InternalObjectId, OpenMode.ForWrite)
if isinstance(acObj, DBText):
newText=acObj.TextString.upper()
acObj.TextString=newText
output.append(newText)
if isinstance(acObj, MText):
newText=acObj.Contents.upper()
acObj.Contents=newText
output.append(newText)
t.Commit()
return output
OUT = text_to_upper(IN[0])