Points from dwg with Python

Hi,

I have some Python dwg codes that can filter layers, polylines and points

for the last one i like to extract the point coordinates by layer name. everything is working except to get the points coordinates. anyone an idea? this code is working well with polylines.

In the picture the result i like to get under the Element.Geometry node. But my Python script gives the error…

import clr

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

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

geo_opt = Autodesk.Revit.DB.Options()

doc = DocumentManager.Instance.CurrentDBDocument

dwgImport = UnwrapElement(IN[0])
layerName = IN[1]

# Layer name to String
for name in layerName:
x = name

# Get DWG geometry
geometry = dwgImport.get_Geometry(geo_opt)

points = []
list = []

# Get geometry in DWG (Points)
for geo_inst in geometry:
    geo_elem = geo_inst.GetInstanceGeometry()     
    for point in geo_elem:
	    element = doc.GetElement(point.GraphicsStyleId)    	
	
	# Get Layer Names
	layer = element.GraphicsStyleCategory.Name 
	is_point = point.GetType().Name
	if is_point == "Point" and layer == x:
		list.append(is_point)
		for pts in point.GetCoordinates():
			points.append(pts)
OUT = points

Hi,

I think it’s because Point Class has no GetCoordinates method, but a Coord property.
http://www.revitapidocs.com/2019/81467732-3105-bd24-a6a5-b276a3c3f8af.htm

give a try replacing
point.GetCoordinates() with
point.Coord

1 Like

Hi,

I tried what you said but it gives you the following error:

Hi,

With a little change in the code i get the coordinates. So that’s good.

Now i only have to figure out why element.Geometry gives me other point.coordinates than Python?

Solved :slight_smile: i had to make the translate from feet to mm and create Point.ByCoordinates.

2 Likes