Modify text Style on Dynamo

Is it possible to modify the text style through Dynamo?? I’m trying to get the text property but I’m always getting “Empty List” .

Hi @frodriguezmXYFSS
Is this what you’re trying to do?

Awesome @Kulkul
Where can I check those python scripts?

I remember seeing something looks similar before on this forum, but I cannot get it now.

Hi, can you share the python scripts to make the text style changes please. i am not too familiar with python.

1 Like

This isn’t quite the same as what @Kulkul did, but give it a try. Provide a string input for the name of the text style you want to change to and it will change all Text and MText in model space.

# Load the Python Standard and DesignScript Libraries
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 *
from Autodesk.AutoCAD.GraphicsInterface import TextStyle

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

errorReport = None

def set_all_texts_style(style):
	
	global adoc
	output = []
		
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
				btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
				
				text_styles = t.GetObject(db.TextStyleTableId, OpenMode.ForRead)
				
				try:
					if text_styles.Has(style):
						for oid in btr:
							obj = t.GetObject(oid, OpenMode.ForWrite)
							if isinstance(obj, (DBText, MText)):
								obj.TextStyleId = text_styles[style]
								output.append(obj)
					elif not style:
						return "No input"
					else:
						return 'The text style "{}" does not exist.'.format(style)
				except:
					import traceback
					errorReport == traceback.format_exc()

				t.Commit()
	if errorReport == None:
		return output
	else:
		return errorReport
	
OUT = set_all_texts_style(IN[0])

Adapted and modified slightly from @Paolo_Emilio_Serra1’s original script here:

4 Likes

Hi guys, the dynamo script worked great on 2021 civil3d version but now that i have the latest 2022 and dynamo version i am having errors on the python script. do you know what could be the issue. I installed the latest iron python as well.

Are the text objects on a locked layer?

the layers are all unlock

@cesar5688433 Could you share here dummy dwg file?

Hi, how to set text style only for text I want to create in model space by this node?

Hi Drbohlav,

I’ve found that setting the text style that you want in Annotate tab before you run Dynamo works the best for text you are creating in Dynamo. The text created in Dynamo uses the style that’s set.
Text Style Tab

Since my Python skills are pretty much non-existent, I’ve tried setting the text style using some Dynamo gymnastics using the ObjectExtensions.GetParameters node and the ObjectExtensions.SetParameterByName node in the Civil3D Toolkit but haven’t had any success. I’d give that a try as well. Maybe I’m doing something wrong and you’ll have better results but it seems like the Python route of setting text styles may be the only option at least for now.

1 Like

There are nodes for this in the Camber package starting in v4.0.0.

text styles

1 Like

You guys know how to change a modified text (modified with the string replace command) in revit into a one line text?