Get Hatch Boundary from Autocad


is there any way to reverse that process? I would like to get boundary curves of a hatch in Dynamo. Is it possible?

@Deniz_Maral you can use the Civil 3D Toolkit.


Thank you very much for your reply! I forgot to mention that I use Dynamo for Revit. Is it still possible to use it? If yes, how can I select hatches?

you can try to use GetLoopAt() method (Active X)

or using this process (Active X)

then you will have to convert the Autocad objects into ProtoType Objects (be careful when converting the Arc, need use GetBulge() method)


Hello Cyril,

I tried that one but it opens AutoCAD and user has to select something. It would be nice to do it like in BiMorphNodes from @Thomas_Mahon
I don’t have much experience in AutoCAD API but I will try to do something. A new chapter to learn something new :slight_smile:

here a simple example without arc (no need to get bulges)

getBoundary hatch3

code IronPython

import sys
import clr
import System
from System import *
from Autodesk.DesignScript.Geometry import *
from math import tan, radians
from System import Array
errorAcd = None
	import System.Runtime.InteropServices
	#import Autodesk.AutoCAD.Interop
	app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application")
		from Autodesk.AutoCAD.Interop.Common import AcadEntity, AcBooleanType
		stringversion = IN[0] #replace by your version if fail
		clr.AddReferenceToFileAndPath('C:/Program Files/Autodesk/AutoCAD {}/Autodesk.AutoCAD.Interop.Common'.format(stringversion))
		from Autodesk.AutoCAD.Interop.Common import AcadEntity, AcBooleanType
	AcDoc = app.ActiveDocument
	acCurDb = AcDoc.Database
	errorAcd = None
	modelSpace = AcDoc.ModelSpace
	paperSpace = AcDoc.PaperSpace
except :
	import traceback
	errorAcd = traceback.format_exc()
def AcDb2DPLineToDS(obj):
	coords = iter(obj.Coordinates)
	DSPoints = [Point.ByCoordinates(x,y,0) for x, y in zip(coords, coords)]
	return PolyCurve.ByPoints(DSPoints, True)
def getHatchBoundary():
	outDS = []
	for i in modelSpace:
		if i.ObjectName == 'AcDbHatch':
			for j in range(i.NumberOfLoops):
				plineObj = clr.Reference[System.Object]()
				i.GetLoopAt(j, plineObj)
				cadCurvesCOM = plineObj.Value
				if not hasattr(cadCurvesCOM, "__iter__"):
					cadCurvesCOM = [cadCurvesCOM]
				for c in cadCurvesCOM:
					if c is not None and c.ObjectName == "AcDbPolyline" :
	return outDS
if errorAcd is None:
	OUT = getHatchBoundary()
	OUT = errorAcd

Merci Cyril! I will try it tomorrow. Can you still get polylines if you delete them after creating hatch?

No, in this case need to use this method


Merci Cyril,

if I have to open AutoCAD via that Node then it would be better to use LISP and create those boundary curves.
I thought, you can get element attributes of hatches like BiMorph gets curve attributes.

A post was split to a new topic: Open Autocad file via Interrop (ActiveX)

Boss @c.poupin ,
in some casses some versions of cad can not get AcDoc correctly may be because of API changes for some of cad versions , so what sohould i do to make your code work nicely with any version of cad.
Your help will be appreciated,
Thanks in advance.

you can try to find all progId from the registry

then you can get the app with

m_App = System.Runtime.InteropServices.Marshal.GetActiveObject(progId)

example here