# Color by distance

![](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-LhLOp7q1AeHcCA6v9Cz%2F-LhLP0H8NWOFk8UeB9uR%2Fcrane.jpg?alt=media\&token=82024eba-2e3c-44c9-9b65-4c97e73ffc61)

{% file src="<https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-LhLOp7q1AeHcCA6v9Cz%2F-LhLP_rfXf4_Wt6xo6x-%2Fcrane.zip?alt=media&token=0c27c7a9-a72d-4d17-b147-d6fa9be7f17f>" %}

```d
l1=(Line.ByStartPointEndPoint((elm.BoundingBox).MaxPoint,
(elm.BoundingBox).MinPoint)).PointAtParameter(0.5);
crnBb=BoundingBox.ByGeometry(crn.Geometry());
crnCp=(Line.ByStartPointEndPoint(crnBb.MaxPoint,
crnBb.MinPoint)).PointAtParameter(0.5);
l2=Line.ByStartPointEndPoint(Point.ByCoordinates
(crnCp.X,crnCp.Y,crnBb.MinPoint.Z),Point.ByCoordinates
(crnCp.X,crnCp.Y,crnBb.MaxPoint.Z));

//max and min distances of each distance group
d1=Flatten(l1<1>.DistanceTo(l2));
d2=List.MinimumItem(d1)..List.MaximumItem(d1)..~inc;

i1=List.DropItems(d2,-1);
i2=List.DropItems(d2,1);

//Filteration criteria
b1=List.Flatten(d1>i1<1><2>,1);
b2=List.Flatten(d1<=(i2+100)<1><2>,1);
b1&&b2;

//Sorting elements into groups
g1=List.FilterByBoolMask(elm,(b1&&b2)<1>);
g2=List.GetItemAtIndex(g1<1>,0);

//Colors
c=List.TakeItems(Transpose(col)[1],List.Count(d2)-1);

//Override color in Revit view
g=g2<1><2>.OverrideColorInView(c<1>);

//Legend
lg1=Math.Round(i1,1);
lg2=Math.Round(i2,1);
lg3=List.TakeItems(Transpose(col)[0],List.Count(d2)-1);
lg=[lg1,lg2,lg3];

lg1+" to "+lg2+" ["+lg3+"]";
```

```d
[["Red",Color.ByARGB(255,255,0,0)],
["Green",Color.ByARGB(255,0,255,0)],
["Blue",Color.ByARGB(255,0,0,255)],
["Yellow",Color.ByARGB(255,255,255,0)],
["Cyan",Color.ByARGB(255,0,255,255)],
["Magenta",Color.ByARGB(255,255,0,255)],
["Violet",Color.ByARGB(255,238,130,238)],
["Orange",Color.ByARGB(255,255,165,0)],
["Brown",Color.ByARGB(255,165,42,42)],
["Gray",Color.ByARGB(255,128,128,128)]];
```

{% file src="<https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-LhLOp7q1AeHcCA6v9Cz%2F-LhLPX5F-TA_RFl28EB_%2Fcrane1.zip?alt=media&token=e723a082-a0e2-45bf-aeff-c95ea4a1d0a3>" %}

![](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-LhLOp7q1AeHcCA6v9Cz%2F-LhLP28n_lzIgdvIfWo5%2Fcrane1.jpg?alt=media\&token=b85b8081-b626-48d4-a069-d2324ca4ba5b)
