WISH: Make2d Assign Object Name

Can object names be assigned to make2d outputs? Is it possible to do this with a script?

I wrote a code with claude.ai. But it couldn’t assign the block instance name to the make2d object. Does anyone have any idea where the problem is coming from?

Untitled.3dm (77.3 KB)

Script
import rhinoscriptsyntax as rs
import Rhino

def TransferNamesToMake2D():
    # Ask the user to select input objects
    input_objects = rs.GetObjects("Please select source objects for Make2D", preselect=True)
    if not input_objects: return

    # Store the name and bounding box of each input object
    object_names = {}
    for obj in input_objects:
        bbox = rs.BoundingBox(obj)
        if bbox:
            # Check if it's a block and get its name
            if rs.IsBlockInstance(obj):
                # Get the custom name of the instance
                custom_name = rs.ObjectName(obj)
                # Get the block definition name
                instance_name = rs.BlockInstanceName(obj)
                # Use the instance name if it exists, otherwise use the definition name
                final_name = instance_name if instance_name else custom_name
                
                if final_name:
                    object_names[obj] = {
                        "name": final_name,
                        "center": [(bbox[0][i] + bbox[6][i])/2 for i in range(3)]
                    }
                    print(f"Block found - Name used: {final_name}")  # For debugging
            else:
                # Get the name of the normal object
                name = rs.ObjectName(obj)
                if name:
                    object_names[obj] = {
                        "name": name,
                        "center": [(bbox[0][i] + bbox[6][i])/2 for i in range(3)]
                    }
                    print(f"Normal object found - Name: {name}")  # For debugging

    # Execute the Make2D command
    make2d_objects = rs.Command("!_Make2D", echo=False)

    # Find the newly created Make2D objects
    all_objects_after = rs.AllObjects()
    new_objects = [obj for obj in all_objects_after if obj not in input_objects]

    # For each new object, find the closest input object and transfer its name
    for new_obj in new_objects:
        if rs.IsCurve(new_obj):  # Process only curves
            new_center = rs.CurveAreaCentroid(new_obj)[0]
            
            # Find the closest original object
            min_distance = float("inf")
            closest_name = None
            
            for original_data in object_names.values():
                dist = rs.Distance(new_center, original_data["center"])
                if dist < min_distance:
                    min_distance = dist
                    closest_name = original_data["name"]
            
            # Transfer the name
            if closest_name:
                rs.ObjectName(new_obj, closest_name)
                print(f"Name assigned: {closest_name}")  # For debugging

# Run the script
if __name__ == "__main__":
    TransferNamesToMake2D()

I also saw an old request for this, but the yt link doesn’t work.

Hello!

First question - what version of Rhino are you on?

You should be able to use Make2d, then make sure this option is set -

That will inherit the source object’s name - along with other object properties.

hello,
I am using the r8 sr13. I didn’t realize that this option also transfers object names. Thank you.
But the names of block objects are not transferred.