Print data from Dynamo to command line

@raul.07.11 Instead of using SendCommand method, I used a different approach “Editor . WriteMessage () method” and also I have cleaned your dyn graph with just one python. Just Connect Select Objects node to it:


import clr

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

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

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

def hatch_area(hatches):
	
	output=[]
	obj=[]
	errorReport = None
	
	if not isinstance(hatches,list):
		hatches = [hatches]
	
	global adoc
	
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				for hatch in hatches:
					handle=hatch.Handle
					oid=(db.GetObjectId(False,Handle(int(handle,16)),0))
					obj=t.GetObject(oid, OpenMode.ForRead)					
					try:
						if isinstance(obj, Hatch):
							area=obj.Area
							output.append(area)							
					# Error handling
					except:
						import traceback
						errorReport = traceback.format_exc()						
				t.Commit()			
	if errorReport == None:
		return "Area is {}".format(sum(output))
	else:
		return errorReport
	
OUT = editor.WriteMessage("\n"+hatch_area(IN[0])+"\n")

Don’t forget to mark the post as solved :slight_smile:

Good Luck!

6 Likes