Python geometry error .ToRevitType .ToXyz

Hi All,

I am receiving the following error when calling .ToXyz and .ToRevitType function from a list of points generated in Dynamo.

“Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 34, in
AttributeError: ‘List[object]’ object has no attribute ‘ToRevitType’”

As far as I know, this should have been solved importing the below but it did not work:

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

Any help?

Thanks a lot.

Hi @AlbertoCastellanos

Could you copy paste complete code here and also complete screenshot of your graph.

That warning is quite clear; you are attempting to call the ToRevitType() method on a list. You can only call that method on a single element. You should check your data structure or iterate the list using a loop to access each of its members, then call the method.

Providing your code as @Kulkul suggested is good advice to get the best solution.

Hi @Kulkul, @Thomas_Mahon,

The code is:

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

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

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

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


doc = DocumentManager.Instance.CurrentDBDocument

toggle = IN[0]
points = UnwrapElement(IN[1])
modelPoints = UnwrapElement(IN[2])
cropCurves = UnwrapElement(IN[3])
viewType = UnwrapElement(IN[4])

lst = []

if toggle == True:
	TransactionManager.Instance.EnsureInTransaction(doc)
	for ind, point in enumerate(points):
		modelMP= modelPoints[ind].ToRevitType()
		modelMPX=modelMP.x
		modelMPY=modelMP.y
	
		
		cropLines = cropCurves[ind]
		l1 = cropLines[0].ToRevitType()
		l2 = cropLines[1].ToRevitType()
		l3 = cropLines[2].ToRevitType()
		l4 = cropLines[3].ToRevitType()
		
		elevationPT = point.ToXyz()
		elptRotate = XYZ(elevationPT.X, elevationPT.y, ElevationPT.z+100)
		ln=Line.CreateBound(elevationPT, elptRotate)
		
		elevationPTY = elevationPT.Y
		elevationPTX = elevationPT.x
		combY = elevationPTY-modelMPY
		combX = elevationPTX-modelMPX
		ang = atan2(combY, combX)
		
		eleMarker = ElevationMarker.CreateElevationMarker(doc, viewType.Id, elevationPT, 100)
		ele = eleMarker.CreateElevation(doc, eleMarker.Id, ln, ang)
		
		crManager = ele.GetCropRegionShapeManager()
		
		newCurveLoop = []
		newCurveLoop.Add(l1)
		newCurveLoop.Add(l2)
		newCurveLoop.Add(l3)
		newCurveLoop.Add(l4)
		cLoop = CurveLoop.Create(newCurveLoop)
		
		try:
			crManager.SetCropRegionShape(cLoop)
			lst.append("Elevation Created")
			
		except:
			pass
			lst.append("Missed Elevation")
			
	TransactionManager.Instance.TransactionTaskDone()
	OUT=lst

else:

	OUT=lst

2 posts were split to a new topic: Missing Crop Region Shape