Get Hatch Boundary from Autocad

Hello,

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.

Capture

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?

Hello
you can try to use GetLoopAt() method (Active X)
https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-93E21F08-C55A-4D56-9A3B-DEADB29838C0

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)

2 Likes

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 *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from math import tan, radians
from System import Array
errorAcd = None
try:	
	import System.Runtime.InteropServices
	#import Autodesk.AutoCAD.Interop
	app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application")
	try:
		clr.AddReference('Autodesk.AutoCAD.Interop.Common')
		from Autodesk.AutoCAD.Interop.Common import AcadEntity, AcBooleanType
	except:
		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" :
						outDS.append(AcDb2DPLineToDS(c))
				
	return outDS
if errorAcd is None:
	OUT = getHatchBoundary()
else:
	OUT = errorAcd
6 Likes

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

2 Likes

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.

Hi,
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

https://adndevblog.typepad.com/manufacturing/2013/05/running-programmatically-a-specific-version-of-inventor.html