Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4171

Get an exported list of ID's of selected objects

$
0
0

Hello,

As a bit of a continuation of my last post, I’m trying to make a script work that based on a selection of objects gives me a list (either CSV or txt) that I can later use to read with another script to re select these objects again.

It is similar to the function “export selected - Object properties” with only Object ID selected.

I tried the following in python but that did not seem to work:

import rhinoscriptsyntax as rs

def main():
    # Prompt the user to select objects
    objects = rs.GetObjects("Select objects")
    
    if objects:
        # Create a new file to write the object IDs to
        file_path = rs.SaveFileName("Save object IDs as", "*.txt")
        
        if file_path:
            # Write the object IDs to the file
            with open(file_path, "w") as f:
                for obj in objects:
                    f.write(str(obj) + "\n")

Then I also tried this:

import rhinoscriptsyntax as rs

def main():
    # Prompt the user to select objects
    objects = rs.GetObjects("Select objects")
    
    if objects:
        # Get the IDs of the selected objects as a list
        object_ids = [rs.ObjectName(obj) for obj in objects]

        # Export the selected objects to a CSV file
        file_path = rs.SaveFileName("Export selected to CSV", "*.csv")
        rs.Command("_-Export {} _Enter _Objects {} _Enter".format(file_path, ",".join(object_ids)))

Also did not work.

Any help is greatly appreciated.

Best regards,
Bastiaan van Oudheusden

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4171

Latest Images

Trending Articles



Latest Images