# Get Line Direction through Python

**URL:** <https://forum.dynamobim.com/t/get-line-direction-through-python/39505>\
**Category:** Uncategorized\
**Created:** [August 15, 2019, 12:27pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505 "2019-08-15T12:27:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramoon.bandeira](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ramoon.bandeira/32/23449_2.png) [@ramoon.bandeira](https://forum.dynamobim.com/u/ramoon.bandeira)\
**Post date:** [August 15, 2019, 12:27pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/1 "2019-08-15T12:27:21Z")

</div>

Hi guys… I’m trying to get the line direction through Python… But it doesn’t seem to work.

Any Tips?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/2/12640846de07359763539b68e99c2acd9d2e88eb.png)

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [August 15, 2019, 12:44pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/2 "2019-08-15T12:44:22Z")

</div>

Hello Ramoon,

Try this code out. It uses a List Comprehension to achieve the results in one line 🙂

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

if not isinstance(IN[0], list):
    IN[0] = [IN[0]]

direction = [ln.Direction for ln in IN[0] ]

OUT = direction
```

The error message you were getting is due to the Direction being a property. As such, you cannot **call** it - i.e use parenthesis. Simply use the instance call on each line, which I called **ln** , and get the Direction property from that instance.

Using a loop, it would look like so:

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

if not isinstance(IN[0], list):
    IN[0] = [IN[0]]

direction = []
for line in IN[0]:
    ln = line.Direction
    direction.append(ln)

OUT = direction
```

---

<div class="post-metadata">

**Author:** ![ramoon.bandeira](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ramoon.bandeira/32/23449_2.png) [@ramoon.bandeira](https://forum.dynamobim.com/u/ramoon.bandeira)\
**Post date:** [August 15, 2019, 5:20pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/3 "2019-08-15T17:20:12Z")

</div>

Thanks for your answer @solamour solved my problem.

Is there something i can use to get all properties associated to a given object?

thank you!

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [August 15, 2019, 5:54pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/4 "2019-08-15T17:54:04Z")

</div>

Hello Ramoon,

You can find all of the methods, actions and properties associated with a _thing_ inside of python using the **dir** function.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/5/15328db9cfb4ed092a6daf790d6b923fc7fac59a.png)

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

if not isinstance(IN[0], list):
    IN[0] = [IN[0]]

# Note the double indexing here - because we make all items a list above
OUT = dir(IN[0][0])
```

In order to see the syntax associated with something, you can also call the **.\_ _doc_ \_** property.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/7/277ca30c246ab822f0ae2514fc625a40a3f8fa57.png)

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

if not isinstance(IN[0], list):
    IN[0] = [IN[0]]

# Note the double indexing here - because we make all items a list above
OUT = IN[0][0].Trim. __doc__
```

---

<div class="post-metadata">

**Author:** ![ramoon.bandeira](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ramoon.bandeira/32/23449_2.png) [@ramoon.bandeira](https://forum.dynamobim.com/u/ramoon.bandeira)\
**Post date:** [August 15, 2019, 5:57pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/5 "2019-08-15T17:57:16Z")

</div>

THANK YOU!!! 😍😍😍

Here is a bookmark

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [August 15, 2019, 5:58pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/6 "2019-08-15T17:58:57Z")

</div>

You are most welcome 🙂

---

<div class="post-metadata">

**Author:** ![Luiscko](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luiscko/32/104053_2.png) [@Luiscko](https://forum.dynamobim.com/u/Luiscko)\
**Post date:** [December 7, 2020, 11:28am UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/7 "2020-12-07T11:28:22Z")

</div>

> [@solamour](#):
>
> ```auto
> # Load the Python Standard and DesignScript Libraries
> import sys
> import clr
> clr.AddReference('ProtoGeometry')
> from Autodesk.DesignScript.Geometry import *
> 
> if not isinstance(IN[0], list):
> IN[0] = [IN[0]]
> 
> # Note the double indexing here - because we make all items a list above
> OUT = IN[0][0].Trim. __doc__
> 
> ```

Could you explain how can access to these methods, because I am new and I do not know why when I try to access to these methods appear me this type of error, I really appreciate so much

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/8/383c70881ee5f3c520543a9d473383d1c5c88d66.png)

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [December 7, 2020, 3:05pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/8 "2020-12-07T15:05:11Z")

</div>

Hello @Luiscko -

It depends on the kind of data you are putting into your `Python` node. As you can see in the screenshot below, if you simply put in a single surface (Note: Not in a list) it will work correcty:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/3/335da9f811971a61d991d5faab26e863736830ee.png)

If I wrap this surface in a list, you’ll notice that the `Python` node will **Error out** , albeit with a different error than you have 🙂

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/2/e28eeeb4245d26fd562cb1674b4697c94f65b91e.png)

So can you please take a screenshot showcasing the output of the data that is being fed into this node?

---

<div class="post-metadata">

**Author:** ![Luiscko](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luiscko/32/104053_2.png) [@Luiscko](https://forum.dynamobim.com/u/Luiscko)\
**Post date:** [December 7, 2020, 4:06pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/9 "2020-12-07T16:06:28Z")

</div>

Is something like the second one, thank you very much, Now I understand why is not working before, is because of the complexity of the list even if was one element was inside in a list, so I need to be careful in the way how to feed the code.

I check with your consideration and now I am aware about that,

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/5/d5e47c3d2d531f2dd620c49d27b766d3a5d46b1f.png)

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [December 7, 2020, 4:48pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/10 "2020-12-07T16:48:14Z")

</div>

Inside of Python you need to handle `Lists` manually - Dynamo does this for you automagically 😉

So, you would be doing the following:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/a/6a98432408a57a9a81d9f90f898f424b037903a3.png)

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

dataEnteringNode = IN #This 'IN' variable refers to ALL input ports of Python node
inputOne = IN[0] #This is all the data coming into the port of 'IN[0]' on the Python node

singleItem = Surface.PerimeterCurves(inputOne)

OUT = singleItem
```

If we have a single object coming in to that `IN[0]` input, then we need to index into it to remove the list and pull our chosen element out:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/6/c6dbb09b2834f806f5b5cf647b7b9390fed7c5dc.png)

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

dataEnteringNode = IN #This 'IN' variable refers to ALL input ports of Python node
inputOne = IN[0] #This is all the data coming into the port of 'IN[0]' on the Python node

listItem = Surface.PerimeterCurves(inputOne[0])

OUT = listItem
```

This is achieved using the square brace notation `[number]` to pull out the object. In our case, it’s a single object, so we pull from the first (And only) index of zero (written as `[0]` in Python).

If we had multiple surfaces we wanted to pull the perimeter curves from, then we need to **iterate** over them, which takes the full list, then specifically runs a sequence of events over each item in that list:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/a/aa8095248e20f52438a417a694912d644bf95969.png)

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

dataEnteringNode = IN #This 'IN' variable refers to ALL input ports of Python node
inputOne = IN[0] #This is all the data coming into the port of 'IN[0]' on the Python node

results = [] #We create an empty list to catch our results

for element in inputOne: #Looping in a 'For Loop' over all things inside the inputOne list
    crvs = Surface.PerimeterCurves(element) #For each thing, get their perimter curves
    results.append(crvs) #Append (add to) the empty list called 'results' the curves

OUT = results #Push out the result
```

---

<div class="post-metadata">

**Author:** ![Luiscko](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luiscko/32/104053_2.png) [@Luiscko](https://forum.dynamobim.com/u/Luiscko)\
**Post date:** [December 7, 2020, 6:01pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/11 "2020-12-07T18:01:53Z")

</div>

Thank you very much for your detail explanation I really appreciate so much your time to write this useful information

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [December 7, 2020, 6:11pm UTC](https://forum.dynamobim.com/t/get-line-direction-through-python/39505/12 "2020-12-07T18:11:05Z")

</div>

You are most welcome @Luiscko! Always happy to help where I can 🙂
