Grouping Curves with Design Script

Design script definition that groups a list of shuffled curves into loops…

On the package manager search for tstngwtrs-GroupCurves

However the node doesn’t need to be downloaded, paste the below code in a code block and call grpCrvs(crv)

    def grpCrvs(crv:var[]..[])
    {
    	dis1 = (crv.StartPoint)<1>.DistanceTo(crv<2>)==0
        ||(crv.EndPoint)<1>.DistanceTo(crv<2>)==0;
    	ind1 = List.AllIndicesOf(dis1<1>,true);
    	bln1 = true;
    	ind2 = [Imperative]
    	{
    		while (bln1)
    		{
    			cnt1 = List.Count(ind1);
    			ind1 = grpIndx(ind1);
    			cnt2 = List.Count(ind1);
    			bln1 = cnt2!=cnt1;
    		}
    		return = ind1;
    	}
    	crv1 = List.GetItemAtIndex(crv,ind2);
    	return = crv1;
    };

    def grpIndx(ind:var[]..[])
    {
    	ind1 = SetIntersection(ind<1>,ind<2>);
    	cnt1 = List.Count(ind1<1><2>)>0;
    	ind2 = List.FilterByBoolMask(ind,cnt1<1>);
    	ind3 = List.FirstItem(ind2<1>);
    	ind4 = List.UniqueItems(Flatten(ind3<1>)<1>);
    	ind5 = List.UniqueItems(List.Sort(ind4<1>));
    	return = ind5;
    };

21 Likes

That has made my day @Vikram_Subbaiah super stuff!

2 Likes

Update for Dynamo 2

def grpCrvs(crv:var[]..[])
    {
    	dis1 = (crv.StartPoint)<1>.DistanceTo(crv<2>)==0
        ||(crv.EndPoint)<1>.DistanceTo(crv<2>)==0;
    	ind1 = DSCore.List.AllIndicesOf(dis1<1>,true);
    	bln1 = true;
    	ind2 = [Imperative]
    	{
    		while (bln1)
    		{
    			cnt1 = DSCore.List.Count(ind1);
    			ind1 = grpIndx(ind1);
    			cnt2 = DSCore.List.Count(ind1);
    			bln1 = cnt2!=cnt1;
    		}
    		return = ind1;
    	}
    	crv1 = DSCore.List.GetItemAtIndex(crv,ind2);
    	return = crv1;
    };

    def grpIndx(ind:var[]..[])
    {
    	ind1 = DSCore.List.SetIntersection(ind<1>,ind<2>);
    	cnt1 = DSCore.List.Count(ind1<1><2>)>0;
    	ind2 = DSCore.List.FilterByBoolMask(ind,cnt1<1>)["in"];
    	ind3 = DSCore.List.UniqueItems(DSCore.List.Flatten(ind2<1>,-1)<1>);
    	ind4 = DSCore.List.UniqueItems(DSCore.List.Sort(ind3<1>));
    	return = ind4;
    };
10 Likes