Print data from Dynamo to command line

Hi everyone. I’m trying to get the total length of all polylines with a specific property value and print it in the command line, similar as what some lisp for sum of lenghts do. I kinda made the property set and sum part, but I just don’t know how to put that value in command line. Do you have any idea on how to do it? Or other alternatives? Thanks in advance.
PS: Attaching the dyn and the dwg I’m doing tests.
PLANTA IIEE.dwg (1.8 MB)
longitudesPS.dyn (16.3 KB)

Hi @raul.07.11

I have seen couple of codes to send a string to command line like one bellow,

You can use python code to send text to command line.

2 Likes

I’m trying to use that script but the problem is that it sends a character at the time. For example I’m trying to send “The area is…” and it sends T h e … Civil 3D is taking many of the characters as commands. Can you help me? Thanks.
areasHatch.dyn (13.2 KB)

Try wrapping the value in a list using a List.Create prior to passing the value into the Python node.

2 Likes

Not Exactly what you are looking for but see if this alternate way is of any use.

longitudesPS.dyn (17.8 KB)

2 Likes

It’s kind of an alternate solution. I wouldn’t have come with that. Thanks for your response.


Doing that makes that Dynamo sends whole words, not letter by letter as before. But still the same problem. What can I do? Thanks for your response.

If it is printing ‘one’ ‘word’ ‘at’ ‘a’ ‘time’ when before it was doing letter by letter, then let’s try wrapping it in another list as a first step.

When I do that I get this error. What’s the problem? Thanks for your response.

Not sure. Which version of Civil 3D are you in? Can you post a graph with just that node in it?

Sure. This is the dyn file areasHatch_v02.dyn (14.5 KB)
And this the dwg I’m working with AREAS PAVIMENTOS.dwg (730.6 KB)
The idea of the graph is to select hatches and give the total area in the command line. Thanks for your response.

Hi @raul.07.11

Is this what you want?
SendCommand

1 Like

Yes, exactly what I need. What changes did you make? Thanks for your response.

image

Doesn’t use the command line as @Kulkul’s does, but it is a bit more ‘in the user’s face’. :slight_smile:

4 Likes

@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!

5 Likes

Thanks for that. Maybe this is not the place to ask, but what do I need to start making Python scripts in Dynamo? I can see that it’s pretty useful. Thanks again.

The problem is that the user couldn’t check the area after clicking Ok. I’ll save that code cause it will be useful in other ocasion. Thanks for your response.