Obtain unique Lines from list

I am trying to change nodes by code, but I had some problems, hope you can help me.

I have a list of lines in dir x, others in dir y, and the outer curves of surfaces.

Some lines of dirx and dir y are repeated with the exterior ones, what I am looking for is to evaluate their distance with a midpoint of the internal lines with the exterior and any line that has the distance 0, is removed from the list, in order to have a list with no repeating elements.

I have tried to implement this code test but it does not work for me, at the moment it is giving me an error, which is most likely because the method changes in PythonScript vs DesignScript.

It would be of great help if you could give me your support, thank you very much in advance.

ExCs = List.Flatten(ExtCurves)
XCs = List.Flatten(XCurves)
YCs = List.Flatten(YCurves)
#nx= List.UniqueItems(List.Flatten([ExCs,XCs,YCs]))
Clean Curves
for exc in ExCs:
	ptex = Curve.PointAtParameter(exc)
	for xc in XCs:
		ptex = Curve.PointAtParameter(xc)
		dx = Geometry.DistanceTo(ptex,ptex)
		if ptex == 0:

The portion that has

if ptex == 0:

I think you need to change to be an else, or remove the indention from the append so it happens if not 0, or it will always continue and not give value.

if ptex == 0:
1 Like

Thank you very much for your response, but does not work


for exc in ExCs:
ptex = Curve.PointAtParameter(exc)
for xc in XCs:
ptx = Curve.PointAtParameter(xc)
dx = Geometry.DistanceTo(ptex,ptx)
if dx == 0:

Because even does not eliminate the lines that are in the same place, additionally create an overlap lines because the evaluation, do you have any other option?

Have you tried using the List.Unique node?

1 Like

Yes it does not work because I think is check the unique item for the internal id of the object so if is unique it show all the elements

if you want to check if 2 lines are overlapped, here 2 examples

a few comments

  • this code get the StartPoint (not the midpoint), because there is no parameter argument (0 to 1)
    ptex = Curve.PointAtParameter(exc)

  • Python is an object-oriented language, you can directly use object methods rather than systematically calling the Class
    so to get a midpoint of a curve, this
    ptex = Curve.PointAtParameter(exc, 0.5)
    can be replaced by
    ptex = exc.PointAtParameter( 0.5)


I check for one item and it works like you show in your screen but if I want to use for a list, how I need to do it, because if I create a nested for to iterate a list its appear that the method intersect does not exist, what I am doing wrong, can you explaining, and thank you very much for your time.

def isOverlap(Line1,Line2):
	for l1 in Line1:
		for l2 in Line2:
			LineInt = Line1.Intersect(Line2)
			Evlines= any([isinstance(x,Line) for x in LineInt])
#	if not Evlines:
			return LineInt

OUT = isOverlap(IN[0],IN[1])

Check your function:

It will be easy for others if you could drop the relevant files for clean solution.


Thank you very much for your petition, I changed the code but it still does not have the result that I look, I created a simplify example so you can help me to understand how I need to code this problem.

G-Structural-Grid-Forum.dyn (26.3 KB)

What’s the result you’re looking? Could you be more specific.

Are you trying to remove Polygon lines?

1 Like

Sorry Kulkul if I do not explain well in the first statement and in the script, The result that I want to achieve is from the exterior list, remove all the elements that are overlapping with X and Y, in this case is only one to simplify the problem.

So I want the unique lines from the lists that I input, for those that are overlapping I want to remove or drop from one list, to have the lists clean.

a function is a callable we can call it as many times as we want

import sys
import clr
from Autodesk.DesignScript.Geometry import *
from DSCore import *

ExCs  = IN[0]
XSurfG = IN[1]
YSurfG = IN[2]
fullGrid = YSurfG + XSurfG

def isOverlap(line1,line2):
	resultArr = line1.Intersect(line2)
	check = any([isinstance(x,Line) for x in resultArr])
	return check

ExCsPurg = []
for curv in ExCs:
	if all([not isOverlap(curv,x) for x in fullGrid]):

OUT = ExCsPurg,  XSurfG, YSurfG
1 Like

Thank you very much @c.poupin c.pounpin

Your code skill is pretty high for me, I understand and thank you very much for teaching me how to implement a function inside the loop.

I really appreciate so much the help that all of you give to improve my understanding in this path @SeanP, @Kulkul and of course @c.poupin .

1 Like