That’s very easy one also:
Great! There you go @csanchez, you have a few options to work with now. Here is a simplified version if you don’t care to have the dictionary output.
import sys import clr # Add Assemblies for AutoCAD and Civil3D clr.AddReference('AcMgd') clr.AddReference('AcCoreMgd') clr.AddReference('AcDbMgd') clr.AddReference('AecBaseMgd') clr.AddReference('AecPropDataMgd') clr.AddReference('AeccDbMgd') # Import references from AutoCAD from Autodesk.AutoCAD.Runtime import * from Autodesk.AutoCAD.ApplicationServices import * from Autodesk.AutoCAD.EditorInput import * from Autodesk.AutoCAD.DatabaseServices import * from Autodesk.AutoCAD.Geometry import * # Import references from Civil3D from Autodesk.Civil.ApplicationServices import * from Autodesk.Civil.DatabaseServices import * adoc = Application.DocumentManager.MdiActiveDocument editor = adoc.Editor def text_to_upper(handles): text= obj= errorReport = None if not isinstance(handles,list): handles = [handles] global adoc with adoc.LockDocument(): with adoc.Database as db: with db.TransactionManager.StartTransaction() as t: for handle in handles: oid=(db.GetObjectId(False,Handle(int(handle,16)),0)) obj=t.GetObject(oid, OpenMode.ForWrite) try: if isinstance(obj, DBText): newText=obj.TextString.upper() obj.TextString=newText text.append(newText) # Error handling except: import traceback errorReport = traceback.format_exc() t.Commit() if errorReport == None: return text else: return errorReport OUT = text_to_upper(IN)
Thank you guys for the help. i created the python script and copied and pasted the code but nothing changed i CAD and i see this warning. I a doing something wrong? i am not familiar with python for cad… thanks.
You need to input a list of object handles like the picture in this above post:
Thank you, it works like a charm. I want to learn Python for Dynamo but i don’t see a good place to find a step by step learning. DO you know where i can find good tutorials?
There isn’t really a consolidated resource for specific “Python for Civil 3D” documentation. You’ll have to just dive in and learn from examples on this site in combination with the API documentation for AutoCAD/Civil 3D.
Thank you very much guys.
Some more potentially useful info:
Sorry to ask but how do I use the Python script in my Dynamo graph? This script allows me to select what layer to take the Text from? Thank you so much in advance.
Thanks very much!
Hi Zachri, I have literally copied and pasted this script into my python node in dynamo for civil 3D, and the program throws me a series of error messages.
This is the version of Dynamo that I have, and I also have the DynamoIronPython2.7 V1.0.0 package installed.
Did you get this figured out?
Hello mzjensen, I tried this with text and it works perfectly, how can I use it with Mtext?
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)
Thanks for your quick reply, what I want is to get the MText position as a point inside Dynamo
That is not related to the original thread. Please create a new thread if you can’t find another one with the solution.