# Dynamo python Export polyline to AutoCAD

**URL:** <https://forum.dynamobim.com/t/dynamo-python-export-polyline-to-autocad/51443>\
**Category:** Revit\
**Tags:** python, dynamo\
**Created:** [June 5, 2020, 11:24am UTC](https://forum.dynamobim.com/t/dynamo-python-export-polyline-to-autocad/51443 "2020-06-05T11:24:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabdelmo](https://avatars.discourse-cdn.com/v4/letter/g/e0b2c6/32.png) [@gabdelmo](https://forum.dynamobim.com/u/gabdelmo)\
**Post date:** [June 5, 2020, 11:24am UTC](https://forum.dynamobim.com/t/dynamo-python-export-polyline-to-autocad/51443/1 "2020-06-05T11:24:00Z")

</div>

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…

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/4/e4dbd32f7ed56a5cc11d251283d0c9f4dae3e542.png) [Home.dyn](https://forum.dynamobim.com/uploads/short-url/7Uc6Kzvg1YgLqezkMVagGffc8ur.dyn) (9.2 KB)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [June 6, 2020, 9:59pm UTC](https://forum.dynamobim.com/t/dynamo-python-export-polyline-to-autocad/51443/2 "2020-06-06T21:59:17Z")

</div>

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)_  
[https://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-ED02917C-D1D6-46B8-95C6-736163C31362](https://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-ED02917C-D1D6-46B8-95C6-736163C31362)

```
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
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:
	try:
		CAD = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application").ActiveDocument
		
		if CAD.ActiveSpace == 1:
			SPACE = CAD.ModelSpace
		else:
			SPACE = CAD.PaperSpace
			
		rtn = _Core(MyVar)
	except Exception, e:
		rtn = e
# Assign your output to the OUT variable.
OUT = rtn
```

---

<div class="post-metadata">

**Author:** ![gabdelmo](https://avatars.discourse-cdn.com/v4/letter/g/e0b2c6/32.png) [@gabdelmo](https://forum.dynamobim.com/u/gabdelmo)\
**Post date:** [June 7, 2020, 5:12pm UTC](https://forum.dynamobim.com/t/dynamo-python-export-polyline-to-autocad/51443/3 "2020-06-07T17:12:48Z")

</div>

Thanks, I really appreciate it
