# Form Diagram for large networks

**URL:** <https://forum.compas-framework.org/t/form-diagram-for-large-networks/102>\
**Category:** compas\_tna\
**Created:** [December 1, 2018, 3:24pm UTC](https://forum.compas-framework.org/t/form-diagram-for-large-networks/102 "2018-12-01T15:24:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiunana](https://avatars.discourse-cdn.com/v4/letter/k/49beb7/32.png) [@kiunana](https://forum.compas-framework.org/u/kiunana)\
**Post date:** [December 1, 2018, 3:24pm UTC](https://forum.compas-framework.org/t/form-diagram-for-large-networks/102/1 "2018-12-01T15:24:20Z")

</div>

I was trying to generate the form diagram with line data input from a json file. The formDiagram function exits with a ‘Key error’ at line 1507 of mesh.py. The network is of 2514 line segments. It works fine when I try getting the form diagram from first 1185 lines (edges).

The code section is as follows

> with open(‘lines.json’) as f:\>  
> data = json.load(f)  
> lines =   
> for i in range(1,len(data)): #error at 1186th line  
> tmp = [(data[i][‘End X’],data[i][‘End Y’], data[i][‘End Z’]), (data[i][‘Start X’], data[i][‘Start Y’], data[i][‘Start Z’])]  
> lines.append(tmp)  
> form = FormDiagram.from\_lines(lines)

json file is as follow

> [  
> {  
> “End X”: 355.6245,  
> “End Y”: -372.2939,  
> “End Z”: 0.6798,  
> “Start X”: 355.4023,  
> “Start Y”: -377.328,  
> “Start Z”: 0.6796,  
> “Layer”: 1  
> },  
> …

Has it something to do with the preprocessing of line data? But formdiagram seems to work well with duplicated lines and reversed order of start/end of lines.

---

<div class="post-metadata">

**Author:** ![TiME](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@TiME](https://forum.compas-framework.org/u/TiME)\
**Post date:** [December 3, 2018, 1:28pm UTC](https://forum.compas-framework.org/t/form-diagram-for-large-networks/102/2 "2018-12-03T13:28:57Z")

</div>

Hi Isuru,

The `from_lines` function does not change if the data comes from a json file or not. So the problem is likely come from the pre-processing the lines or with the data itself. Could you send me the json file?

---

<div class="post-metadata">

**Author:** ![TiME](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@TiME](https://forum.compas-framework.org/u/TiME)\
**Post date:** [December 3, 2018, 4:44pm UTC](https://forum.compas-framework.org/t/form-diagram-for-large-networks/102/4 "2018-12-03T16:44:01Z")

</div>

Hi Isuru,

The problem lies with your data, there are a few lines that start and end from the same point. This causes a problem generating the topology of the diagram. If you correct the data it should work. Otherwise you can check for this error in the data as you are generating the lines, like so:

```python

import json
from compas_tna.diagrams import FormDiagram

with open('lines.json') as f:
    data = json.load(f)
lines = []
print len(data)
for i in range(1, len(data)):
    tmp = [(data[i]['End X'], data[i]['End Y'], data[i]['End Z']), (data[i]['Start X'], data[i]['Start Y'], data[i]['Start Z'])]

    if tmp[0] != tmp[1]:
        lines.append(tmp)

form = FormDiagram.from_lines(lines, precision='3f')

```

This should work and return a `FormDiagram` object.

---

<div class="post-metadata">

**Author:** ![kiunana](https://avatars.discourse-cdn.com/v4/letter/k/49beb7/32.png) [@kiunana](https://forum.compas-framework.org/u/kiunana)\
**Post date:** [December 3, 2018, 5:07pm UTC](https://forum.compas-framework.org/t/form-diagram-for-large-networks/102/5 "2018-12-03T17:07:44Z")

</div>

Thank you very much. It works well with that check
