It did not work Geometries

Thanks you

1 Like

Sorry, it did not work

Sorry, it did not work

don’t sort the center points by their x & y values?

Sorry, it did not work

Hello,

As @Rickson said, if you don’t sort the list then the objects will be numbered in the order you selected:

import rhinoscriptsyntax as rs

def main():
    objects = rs.GetObjects("Select objects to label")
    if not objects:
        return
        
    if len(objects) > 1:
        # Get the objects center points
        center_pts = []
        for obj in objects:
            # Get the area centroid for closed, planar curves    
            if rs.IsCurve(obj) and rs.IsCurveClosed(obj) and rs.IsCurvePlanar(obj):
                center_pt = rs.CurveAreaCentroid(obj)[0]
            # Get the bounding box center point for all other objects
            else:
                bbox = rs.BoundingBox(obj)
                if bbox:
                   center_pt = (bbox[0] + bbox[6]) * 0.5
            center_pts.append(center_pt)
        
        # Dont sort the center points by their y- and x-values
        sorted_cpts = center_pts #  [p for p, o in sorted(zip(center_pts, objects), key=lambda k: [k[0].Y, k[0].X])]
        sorted_objs = objects #  [o for p, o in sorted(zip(center_pts, objects), key=lambda k: [k[0].Y, k[0].X])]
        
        # Parse the prefix
        prefix = rs.GetString("Prefix for labels, press Enter for none")
        if prefix is None: 
            prefix = ""
        
        # Label the objects
        for i in xrange(len(sorted_cpts)):
            # Parse the suffix as zero padded number
            suffix = str(i+1).zfill(len(str(len(sorted_cpts))))
            dot = rs.AddTextDot(prefix + suffix, sorted_cpts[i])
            rs.ObjectName(sorted_objs[i], prefix + suffix)

if __name__ == '__main__':
    main()
1 Like

Sorry, it did not work

Sorry, it did not work

import rhinoscriptsyntax as rs

def main():
    objects = rs.GetObjects("Select objects to label")
    if not objects:
        return
        
    if len(objects) > 1:
        # Get the objects center points
        center_pts = []
        for obj in objects:
            # Get the area centroid for closed, planar curves    
            if rs.IsCurve(obj) and rs.IsCurveClosed(obj) and rs.IsCurvePlanar(obj):
                center_pt = rs.CurveAreaCentroid(obj)[0]
            # Get the bounding box center point for all other objects
            else:
                bbox = rs.BoundingBox(obj)
                if bbox:
                   center_pt = (bbox[0] + bbox[6]) * 0.5
            center_pts.append(center_pt)
        
        # Dont sort the center points by their y- and x-values
        sorted_cpts = center_pts #  [p for p, o in sorted(zip(center_pts, objects), key=lambda k: [k[0].Y, k[0].X])]
        sorted_objs = objects #  [o for p, o in sorted(zip(center_pts, objects), key=lambda k: [k[0].Y, k[0].X])]
        
        # Parse the prefix
        prefix = rs.GetString("Prefix for labels, press Enter for none")
        if prefix is None: 
            prefix = ""
        # Get Start Value
        start = rs.GetInteger("Starting Number")
        if start is None: 
            start = 1
        # Label the objects
        for i in xrange(len(sorted_cpts)):
            # Parse the suffix as zero padded number
            suffix = str(start+i).zfill(len(str(len(sorted_cpts))))
            dot = rs.AddTextDot(prefix + suffix, sorted_cpts[i])
            rs.ObjectName(sorted_objs[i], prefix + suffix)

if __name__ == '__main__':
    main()
1 Like