Get Face from CAD/dwg

Hello,

I have a dwg file with a lot of hatches without polylines. I’m trying to get the face and from there I would like to get the boundaries because in Revit I have this, by hand:

but with my code I can not get it, just lines without order so it’s impossible to use them for creating floors. Any ideas?

Thanks in advance.

Why don’t you try to explode imported dwg, then the hatches will be converted as Filled region with boundaries.

Yes, you are right and finally I’m doing this. The problem is that the file is huge with a lot of layers, etc. so I’m losing a lot of time separating the dwg in several files (Revit can not explode big files). Thanks.

Hi,
The geometry of the hatches of ImportInstance are of type Solid (flat solid)
here is an example to find boundaries

import clr
import sys
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)


importinstance = UnwrapElement(IN[0])
out = []
opt = Options()
geoSet = importinstance.get_Geometry(opt)
for geo in geoSet:
	if isinstance(geo, GeometryInstance):
		for g in  geo.GetInstanceGeometry():
			if isinstance(g, Solid):
				for f in g.Faces:
					for loopCurve in f.GetEdgesAsCurveLoops():
						ds_polycurv = DS.PolyCurve.ByJoinedCurves(x.ToProtoType() for x in loopCurve)
						out.append(ds_polycurv)

OUT = out
5 Likes

Wasn’t recreating the Boundaries of the Hatches in AutoCAD an option?
Maybe even use a LISP to do that?

Hi @POBAvatarBIM

How about getting hatch boundaries by Layer Name:


HatchBoundary

Here is slight modified version of @c.poupin:

import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
importinstance = UnwrapElement(IN[0])
out = []
opt = Options()
geoSet = importinstance.get_Geometry(opt)
for geo in geoSet:
	if isinstance(geo, GeometryInstance):
		for g in  geo.GetInstanceGeometry():
			if isinstance(g, Solid) and g.Volume == 0:
				for f in g.Faces:
					if doc.GetElement(f.GraphicsStyleId).GraphicsStyleCategory.Name == IN[1]:
						for loopCurve in f.GetEdgesAsCurveLoops():
							ds_polycurv = DS.PolyCurve.ByJoinedCurves(x.ToProtoType() for x in loopCurve)
							out.append(ds_polycurv)
OUT = out
4 Likes

Hello @Kulkul
Do you know why the script is not working?

Could you drop here dwg file?

Hi @Kulkul,
I have attached the dwg file, I would be very grateful if you could take a look.
Referance Dwg.dwg (91.8 KB)

Try this:

import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
importinstance = UnwrapElement(IN[0])
out = []
opt = Options()
geoSet = importinstance.get_Geometry(opt)
for geo in geoSet:
	if isinstance(geo, GeometryInstance):
		for g in  geo.GetInstanceGeometry():
			if isinstance(g, Solid):
				for f in g.Faces:
					if doc.GetElement(f.GraphicsStyleId).GraphicsStyleCategory.Name == IN[1]:
						for loopCurve in f.GetEdgesAsCurveLoops():
							ds_polycurv = DS.PolyCurve.ByJoinedCurves(x.ToProtoType() for x in loopCurve)
							out.append(ds_polycurv)
OUT = out
3 Likes

@Kulkul thank you this is working for me :slight_smile: