Set plot styles

To set plot styles according to a CSV file

Introduction

This script is a Rhino plugin that allows to set the plot style of layers in Rhino according to a CSV file. It opens a user interface in Rhino that allows the user to select a scale, and reads the corresponding CSV file to set the print color, linetype and thickness of each layer.

Features

  • User interface in Rhino that allows the user to select a scale

  • Reading of CSV files

  • Setting of the print color, linetype and thickness of each layer

Usage

  1. Open Rhino and use the RunPythonScript command to load the script

  2. In the user interface, select the scale you want to apply

  3. The script will read the corresponding CSV file and set the print color, linetype and thickness of each layer

Logic

  1. The script initializes an options variable with the different scales available

  2. A user interface is opened in Rhino that allows the user to select a scale

  3. The script reads the corresponding CSV file according to the user's choice

  4. The script reads each row in the CSV file, and assigns the print color, linetype and thickness of each layer according to the values in the CSV file

Dependencies

  • Rhino

  • rhinoscriptsyntax library (included in Rhino)

  • CSV files containing the plot styles infos

Known issues

  • The script only works for the specific path where the csv files are located, this path should be modified to match the user's path.

  • The script only assigns values to the layers that match the names in the csv file. If a layer in Rhino has a different name than in the csv, the script will not assign any values to that layer.

  • The script assumes that the csv file is structured in a specific way, with the layer name in the first column, the red value in the second column, the green value in the third column, the blue value in the fourth column, the linetype in the fifth column, and the line width in the seventh column. If the csv file is structured differently, the script will not work properly.

  • The script doesn't check if the user inputs a valid scale choice, if the user enters an invalid scale the script will throw an error.

  • The script does not handle if the user cancels the options box and the script will throw an error.

Script

import csv # import csv library to handle csv reading and writing
import rhinoscriptsyntax as rs # import rhinoscriptsyntax to handle rhino actions
path = "/Users/maudlevy/kDrive/Common documents/mlavland/C1-TINA/0-rhinoPlotStylesGit/"

def SetPrintInfo(): # first function : options in a popup in Rhino
	options = ('20e', '20ec', '50e', '50ec', '100e', '200e', '500e', '1000e', )
	if options:
		result = rs.ListBox(options, "Pick an option")
		if result == "20e": # get the option from the user
			filename = path + "20.csv" # fetch the right csv, corresponding to the user's choice
		elif result == "20ec":
			filename = path + "20c.csv"	
		elif result == "50e":
			filename = path + "50.csv"	
		elif result == "50ec":
			filename = path + "50c.csv"	
		elif result == "100e":
			filename = path + "100.csv"
		elif result == "200e":
			filename = path + "200.csv"
		elif result == "500e":
			filename = path + "500.csv"
		elif result == "1000e":
			filename = path + "1000.csv"
		else:
			exit()
		OpenCSV(filename)

def OpenCSV(filename): # second function : open the csv file containing the plot styles infos	
	with open(filename) as csvfile:
		reader = csv.reader(csvfile)
		next(reader) # jump to next line (first line is data headers)
		for row in reader: # iterate through each row
			full_layer_name = row[0] # put the values from the columns in variables
			print_color = rs.CreateColor(row[1], row[2], row[3])
			linetype = row[4]
			thickness = row[6]
			SetLayerPrintValues(full_layer_name, print_color, linetype, thickness) # send variables to the next function

def SetLayerPrintValues(full_layer_name, print_color, linetype, thickness): # third function : assign the values from the csv to the Rhino layers
	layer_names = rs.LayerNames() # create array of existing layers in Rhino
	for layer_name in layer_names:# iterate through each layer
		if layer_name == full_layer_name: # select the layer
			rs.LayerPrintColor(layer_name, print_color) # assign print color
			rs.LayerLinetype(layer_name, linetype) # assign linetype
			rs.LayerPrintWidth(layer_name, float(thickness)) # assign line thickness

if( __name__ == "__main__" ): # perform function
	SetPrintInfo()

Example CSV file

To work, the script must by fed with a CSV file formatted as this example

FullLayerName,R,G,B,Linetype,Thick. (Pt),Thick. (mm),Pattern
01-Dessin,255,255,255,continuous,0.0,0.0,[Sans]
01-Dessin::0-aideDessin,255,255,255,continuous,0.0,0.0,[Sans]
01-Dessin::1-block,255,255,255,continuous,0.1,0.035,Avec
01-Dessin::2-traitCoupe,0,0,0,continuous,0.15,0.053,[Sans]
01-Dessin::3-axe,150,0,0,mlavAxe,0.15,0.053,[Sans]
01-Dessin::4-symbole,0,0,0,continuous,0.15,0.053,[Sans]
01-Dessin::5-personnage,0,0,0,continuous,0.15,0.053,[Sans]
01-Dessin::6-cartouche,0,0,0,continuous,0.15,0.053,[Sans]
01-Dessin::7-layout,0,0,0,continuous,0.0,0.0,[Sans]
02-ReglesNormes,255,255,255,continuous,0.0,0.0,[Sans]
02-ReglesNormes::1-cadastre,0,0,0,continuous,0.15,0.053,[Sans]
02-ReglesNormes::2-gabaritPLU,195,45,135,Dashed,0.15,0.053,[Sans]
02-ReglesNormes::3-limiteTerrain,110,0,255,Border,0.25,0.088,[Sans]
02-ReglesNormes::4-surfaceTerrain,0,0,0,continuous,0.25,0.088,[Sans]csv

Last updated