Description

Exporte les informations de calques dans un fichier .csv.

Voir aussi le script CreateLayerTree et la Hiérarchie de modélisation.

Le script suivant fonctionne sur :

  • Rhino pour Windows ;
  • Rhino pour macOS.

Script par MLAV.LAND, sous licence GNU GPL 3.

Code

import rhinoscriptsyntax as rs
import csv
 
def export_layers_to_csv():
    # Define the path for the CSV file
    filename = rs.SaveFileName("Save CSV file", "CSV Files (*.csv)|*.csv||")
    if not filename:
        return
 
    # Gather all layers by their IDs
    layer_ids = rs.LayerIds()
    if not layer_ids:
        print "No layers found."
        return
 
    # Create a list to hold layer data
    layer_data = []
    for layer_id in layer_ids:
        # Get the full layer path
        full_layer_path = rs.LayerName(layer_id, fullpath=True)
        # Skip layers with specific names
        if full_layer_path.endswith("By Parent") or full_layer_path.endswith("VisualARQ Locked Levels"):
            continue
        # Get the layer color
        color = rs.LayerColor(layer_id)
        # Get the print color (returns None if color is ByLayer, convert to a readable format)
        print_color = rs.LayerPrintColor(layer_id)
        if print_color is None:
            print_color = "ByLayer"
        else:
            print_color = (print_color.R, print_color.G, print_color.B)
        # Get the linetype
        linetype = rs.LayerLinetype(layer_id)
        # Get the print width (returns None if print width is ByLayer or Default, convert to a readable format)
        print_width = rs.LayerPrintWidth(layer_id)
        if print_width is None:
            print_width = "ByLayer/Default"
        
        # Prepare the row to be written to the CSV
        row = [
            full_layer_path,
            color.R, color.G, color.B,
            print_color if print_color == "ByLayer" else "{} {} {}".format(*print_color),
            linetype,
            print_width
        ]
        layer_data.append(row)
 
    # Write data to CSV
    with open(filename, 'wb') as csvfile:
        writer = csv.writer(csvfile)
        # Header
        writer.writerow(["FullLayerName", "R", "G", "B", "PrintColor", "Linetype", "PrintWidth"])
        writer.writerows(layer_data)
    
    print "Layer data exported successfully to %s :)" % filename
 
export_layers_to_csv()