Manipulating text properties using Dynamo

Hello,

I’m very new to Dynamo, and just starting to wrap my head around how to utilize it. I’m hoping one of you fantastic experts could help provide an example, and shed some light on how to modify properties.

My goal here is to automate some of the mundane steps we take at my organization to prepare a base plan for design. I’m hoping to create a Dynamo program that will accomplish the following:

  1. Select all text entities on a specific layer (this part I have sorted out thanks to @mzjensen)
  2. Change Annotative property from No to Yes
  3. Change Text Height to a specific value

This seems like it should be extremely easy to accomplish, but I haven’t had any luck with my experimentation so far. Can these manipulations be accomplished in Dynamo without Python coding?

Thank you for any direction you can provide!

Hi @RyanNorbury,

We don’t have nodes for these yet. So Python is needed.

Here’s the Python code for this one. IN[0] is a list of text objects (or a single object), and IN[1] is the desired text height.

import sys
import clr

# Add Assemblies for AutoCAD
clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')

# Import references from AutoCAD
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

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

def set_text_height(text,height):

	output=[]
	obj=[]
	errorReport = None
	
	if not isinstance(text,list):
		text = [text]
	
	global adoc
	
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				for item in text:
					handle=item.Handle
					oid=(db.GetObjectId(False,Handle(int(handle,16)),0))
					obj=t.GetObject(oid, OpenMode.ForWrite)					
					try:
						if isinstance(obj, DBText):
							obj.Height=height
							output.append(item)							
					# Error handling
					except:
						import traceback
						errorReport = traceback.format_exc()						
				t.Commit()			
	if errorReport == None:
		return output
	else:
		return errorReport
	
OUT = set_text_height(IN[0],IN[1])

1 Like

Here’s another method if you have the Civil 3D Toolkit package (which I recommend getting if you don’t).

1 Like

Thank you again good sir. This is exactly what I was looking for!

This is a bit more complicated programmatically, and I haven’t had time to dive into it. So the below code seems to work, but I don’t think it’s the right way to do it. In my tests, it will set the annotative property for text objects to “Yes”. You’ll have to set the annotation scale separately though.

import sys
import clr

# Add Assemblies for AutoCAD
clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')

# Import references from AutoCAD
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

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

def set_text_annotative(text):

	output=[]
	obj=[]
	errorReport = None
	
	if not isinstance(text,list):
		text = [text]
	
	global adoc
	
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				for item in text:
					handle=item.Handle
					oid=(db.GetObjectId(False,Handle(int(handle,16)),0))
					obj=t.GetObject(oid, OpenMode.ForWrite)					
					try:
						if isinstance(obj, DBText):
							obj.Annotative=0
							output.append(item)							
					# Error handling
					except:
						import traceback
						errorReport = traceback.format_exc()						
				t.Commit()			
	if errorReport == None:
		return output
	else:
		return errorReport
	
OUT = set_text_annotative(IN[0])
1 Like

Using the SetParameterValueByName node you pointed out, I was able to change the state of Annotative to Yes as follows.

Now, changing the “Paper text height” specifically using that method doesn’t seem to be as intuitive. Changing height does in fact change the “Model text height” and changes the Paper text height by association. This may work for my purposes as our Annotative scale doesn’t change from default at this point in the base plan preparation.

Yes, this somehow works no matter what you pass as the input. So you could just type in “blah” and it will work :thinking: