Same code in nodes (give accurate results) and Python behave differently with different geometry scaling preference settings

Hello all, I wrote a code for filtering some points using nodes it works perfectly and gives the same result with all the geometry scaling preferences small, medium, large and extra large and now I tried writing that in python i am not getting all the output points for some it is showing the values even tried with all the geometry scaling settings nothing is working.


Points sort.dyn (26.8 KB)
I cant able to upload the rvt file because of file size.
To recreate the issue open a new rvt prj place some random tees in MEP Fabrication Pipework Category. Thanks

Share a screenshot of the nodal version in action with the output you expect and paste the python code here as preformatted text (</>) so we can see what you’re working with. Also, always pin the node preview bubbles whenever you share a screenshot.

There will be some “minor” differences between the two languages based on what you’re doing - specifically with things like rounding and direct comparisons. The list logic may also vary between list levels and looping. We need to see what you’re doing in order to have an idea though.

Hi @Nick_Boyts the orange one i am refering as python version and the red one as nodal version and the codes have been attached in the dynamo file in the above texts.

PY-filtering the Tee Points code is this

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

import itertools

def ptscentroid(pts):
    px,py,pz=[],[],[]
    for p in pts:
        px.append(p.X)
        py.append(p.Y)
        pz.append(p.Z)
    return Point.ByCoordinates(sum(px)/len(pts),sum(py)/len(pts),sum(pz)/len(pts))

def teecenterpoints(pts):
    groupedpts=[]
    gps,cps=[],[]
    #group points by x
    iterator = itertools.groupby(pts, lambda pt : str(pt.X))
    for key, group in iterator:  
        gps.append(list(group))
    #group points by y
    iterator = itertools.groupby(pts, lambda pt : str(pt.Y))
    for key, group in iterator:
        gps.append(list(group))
    #group points by z
    iterator = itertools.groupby(pts, lambda pt : str(pt.Z))
    for key, group in iterator:
        gps.append(list(group))

    #filtering the 2 points with the 2 points in the group 
    for gp in gps:
        if len(gp)==2:
            return ptscentroid(gp)
            break
    del gps
    

# The inputs to this node will be stored as a list in the IN variables.
points = IN[0]

o=[]
# Place your code below this line
for pts in points:
    o.append(teecenterpoints(pts))
            


# Assign your output to the OUT variable.
OUT = o

Try rounding your x, y, and z values before grouping. Even for points that are otherwise identical, there can often be internal rounding issues at the nth decimal point that result in =/= point comparisons.