Dwg to wall


Hello everyone the groupbydistance is not working with my version of Python. Any idea to group nearest lines? thank you.

What group by distance node? Assuming it is Python based may have to adjust that code as a first step.

1 Like

this node

I recall a Node called Group by Parallel Lines (hint)

1 Like

I don’t have a problem grouping parallel lines. My issue is with grouping by distance. Thank you for your response

“I think I found the solution. I installed the Python 2.7 package and ran the node with that version, and it works now


This is a security issue for many companies. I believe there are a few CVEs which would apply to the underlaying tech (Python 2) if that version was still supported. You would be well served by opening up the custom node, copying out the Python node, converting it to use a supported engine (ideally CPython3), and using that of providing a new DYF/package instead of using the IronPython2 engine.

2 Likes

Hi @hayet.sassi2 i actuelly recommend do these centerlines in acad much easier IMO i just use a lisp.maybe acad has a tool for that inside not sure…, than try with dynamo,can probably work on simple geometry, but if complex, it ill never be fully automated anyway without some really hard sorting where many things can go wrong as well…just me :wink: :wink:

1 Like

Hey,

If you want to use CPython3 in a new python node, this code will work…

#Inspired from the "Group Curves" node by Konrad Sobon
# @arch_laboratory, http://archi-lab.net

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import Geometry

pts = IN[0]
margin = IN[1]
dist1 = Geometry.DistanceTo

Groups, Queue = [], []
while pts:
	group = []
	Queue.append(pts.pop() )
	while Queue:
		p1 = Queue.pop()
		group.append(p1)
		for i in range(len(pts)-1,-1,-1):
			if dist1(p1, pts[i]) <= margin:
				Queue.append(pts.pop(i) )
	Groups.append(group)

OUT = Groups

Hope that helps,

Mark

4 Likes

I noticed you have IFCNodes installed. If you’ve had a chance to try it, I’d love to hear how it’s working for you. No pressure though, just curious.

2 Likes

Hello, thank you. Yes, it’s working thank God for the Dynamo community

3 Likes

other solution with LINQ and serialisation of line orientation

code Python (PythonNet3)

import sys
import clr
import System
from System import Array
from System.Collections.Generic import List, IList, Dictionary

clr.AddReference('ProtoGeometry')
import Autodesk.DesignScript.Geometry as DS
from Autodesk.DesignScript.Geometry import *

clr.AddReference('GeometryColor')
from Modifiers import GeometryColor
clr.AddReference('DSCoreNodes') 
import DSCore
from DSCore import Color as DSColor

clr.AddReference('System.Drawing')
import System.Drawing

clr.AddReference("System.Core")
clr.ImportExtensions(System.Linq)


def bi_direction_representation(line):
    v1 = line.Direction.Normalized()
    v2 = v1.Reverse()
    lst_vect = sorted([v1, v2], key = lambda v : (v.X, v.Y, v.Z))
    vect_repr = "|".join([f"Vect({v.X:.2f},{v.Y:.2f},{v.Z:.2f})" for v in lst_vect])
    return vect_repr.replace("-0.00", "0.00")
    
    
def cluster_by_distance(curves):
    clusters = []
    for c in curves:
        for g in clusters:
            if any(c.DistanceTo(x) <= TOLER for x in g):
                g.Add(c)
                break
        else:
            g = List[DS.Curve]()
            g.Add(c)
            clusters.append(g)
    return List[List[DS.Curve]](clusters)
    
ds_lines = List[DS.Curve](IN[0])
TOLER = IN[1]


groups = ds_lines.GroupBy[DS.Curve, System.String](System.Func[DS.Curve, System.String](
                                    lambda c : bi_direction_representation(c)))\
                            .Select(System.Func[System.Object, System.Object](lambda x : cluster_by_distance(x.ToList()) ))\
                            .SelectMany[System.Object, System.Object](System.Func[System.Object, List[List[DS.Curve]]](lambda p : p ))\
                            .ToList()
                            
# OPTIONAL check the results adding colors
check_lines_color = []

color_values  = System.Enum.GetValues[System.Drawing.KnownColor]()
color_values = [c for idx, c in enumerate(color_values) if 0.5 < System.Drawing.Color.FromKnownColor(c).GetBrightness() < 0.65] * 1000
color_values.reverse()

for group_curves, color_value in zip(groups, color_values):
    temp = []
    color_to_apply = System.Drawing.Color.FromKnownColor(color_value) 
    ds_color = DSColor.ByARGB(color_to_apply.R, 
                            color_to_apply.G, 
                            color_to_apply.B, 
                            0)
    for line in group_curves:
        temp.append(GeometryColor.ByGeometryColor(line, ds_color))
    check_lines_color.append(temp)
OUT = check_lines_color #, groups

For the next step, I suggest you use BoundingBox.ByMinimumVolume.