Dynamo python Export polyline to AutoCAD

Dears I’m trying to edit the code by LinkDWG to take polygons from the dynamo and export it to AutoCAD as a polyline but I keep getting Value does not fall within the expected range.

Any suggestions…

Home.dyn (9.2 KB)

Hello @gabdelmo
here is the corrected python code
the argument of AddPolyline function must be a Array not a list of multiple Array (note the extend function instead of append)

# Enable Python support and load DesignScript library
import clr
from Autodesk.DesignScript.Geometry import *
from math import *
import System
from System import Array

# The inputs to this node will be stored as a list in the IN variables.
#rtn = None
MyVar = IN[1]
rtn = None

# Place your code below this line
def _VLOPoint(pt):
	return Array[float]([pt.X, pt.Y, pt.Z])

def _Core(abc):
	if isinstance(abc, Polygon):
		MyList = []
		for i in abc.Points:
			MyList.extend([i.X, i.Y, i.Z])
		lstvertex = Array[float](MyList)	
		poly = SPACE.AddPolyline(lstvertex)
		poly.Closed = True
	return poly

if IN[0] == True:
		CAD = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application").ActiveDocument
		if CAD.ActiveSpace == 1:
			SPACE = CAD.ModelSpace
			SPACE = CAD.PaperSpace
		rtn = _Core(MyVar)
	except Exception, e:
		rtn = e
# Assign your output to the OUT variable.
OUT = rtn

Thanks, I really appreciate it