Create Multiple Catchment Labels

Continuing the discussion from Hatch centroid definition:

@KirkWM here’s some Python code if you want to create actual Catchment labels instead of MText.

import clr

clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
from Autodesk.Civil.DatabaseServices.Styles import *

adoc = Application.DocumentManager.MdiActiveDocument
civdoc = CivilApplication.ActiveDocument

catchment = IN[0]
labelStyleName = IN[1]

def create_catchment_label(catchment,styleName):

	global adoc
	global civdoc
	
	output = []
	
	if not isinstance(catchment, list):
		catchment = [catchment]

	with adoc.LockDocument():
	    with adoc.Database as db:
	        with db.TransactionManager.StartTransaction() as t:
				for c in catchment:
					catchmentId = c.InternalObjectId
					obj = t.GetObject(catchmentId, OpenMode.ForRead)
					if isinstance(obj, Catchment):
						labelStyleId = civdoc.Styles.LabelStyles.CatchmentLabelStyles.AreaLabelStyles[styleName]
						label = CatchmentLabel.Create(catchmentId,labelStyleId)
						output.append(t.GetObject(label,OpenMode.ForRead))
				t.Commit()
	return output

OUT = create_catchment_label(IN[0],IN[1])
4 Likes

This is brilliant! Worked perfectly, thanks a bunch.
Attaching dyn for the next person.Catchment labels python v1.dyn (11.4 KB)

2 Likes

@KirkWM check out Camber, my new package for Civil 3D. There are some nodes for creating Catchment labels.

CatchmentLabels

1 Like