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

Export layers in csv

$
0
0

Hello,
I would like to compare the names of the layers present on several files in the same directory.
For this I made a code in Python which works but I get blank lines between each data.
I tried to add the newline=‘’ argument in the open function but Rhino said: ‘open() got unexpected keyword argument ‘newline’’

import rhinoscriptsyntax as rs
import os
import Rhino
import csv

# Chemin du repertoire contenant les fichiers .3dm
folder_path = "C:\Users\Utilisateur\AppData\Roaming\Z-Kreat\Moules_simp"

Fichiers = []
Calque = []
Calques = []

# Parcourir les fichiers dans le repertoire
for filename in os.listdir(folder_path):
    # Verifier que le fichier est un fichier .3dm
    if filename.endswith(".3dm"):
        # Ouvrir le fichier
        file_path = os.path.join(folder_path, filename)
        rs.DocumentModified(False) # Desactive la sauvegarde auto
        rs.Command("_-Open " + '"' + file_path + '"' + " _Enter") # Ouvre le fichier
        rs.Command("_-SelAll _Enter") # Selectionne tous les objets
        rs.Command("_-Properties _Enter") # Ouvre la fenetre des proprietes
        Fichiers.append(filename)
        #list of layer names
        layers = rs.LayerIds()
        # Recuperer les noms des calques
        for layer in layers:
            Calque=[(rs.LayerName(layer))]
            Calques.append(Calque)

print(Fichiers)
print(Calques)

with open('Calques.csv',"w", newline='') as f:
    writer = csv.writer(f)
    writer.writerow(Fichiers)
    writer.writerows(Calques)

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles