Hey all,
New to scripting so fingers crossed this is a simple fix. The gist of what I’m trying to do is automate a process for taking old architectural details imported from CAD and reassign their annotation style to a uniform one with a variable model space scale - that variable model space scale being determined by what the original annotation style is and assigned via a csv file. Generally, I’m able to get everything to work up until the last step - that being assigning the custom scale. Is this possible / am I missing something obvious? Thanks!
import rhinoscriptsyntax as rs
import csv
import Rhino
import System
def reassign_annotation_style():
# Select the object
obj = rs.GetObject("Select an annotation object", rs.filter.annotation)
if not obj:
return
# Get the current annotation style
current_style = rs.DimensionStyle(obj)
# Prompt user to select the CSV file
filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*||"
csv_file = rs.OpenFileName("Select the annotation scales CSV file", filter)
if not csv_file:
print("No CSV file selected. Operation cancelled.")
return
# Read the CSV file for scale information
scale_dict = {}
try:
with open(csv_file, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
scale_dict[row['OriginalStyle']] = float(row['ModelSpaceScale'])
except Exception as e:
print("Error reading CSV file: {}".format(str(e)))
return
# Set the new annotation style
new_style = "Paperspace"
rs.DimensionStyle(obj, new_style)
# Apply the model space scale
if current_style in scale_dict:
scale = scale_dict[current_style]
# Get the dimension style
dim_style = rs.DimensionStyle(new_style)
if dim_style:
# Create a new dimension style with the updated scale
new_style_name = "{}_{}_Scale".format(new_style, scale)
new_dim_style = rs.CopyDimensionStyle(new_style, new_style_name)
# Set the new scale
rs.DimensionScale(new_dim_style, scale)
# Apply the new style to the object
rs.DimensionStyle(obj, new_style_name)
print("Annotation style changed from '{}' to '{}' and scaled by {}".format(current_style, new_style_name, scale))
else:
print("Unable to find the '{}' dimension style.".format(new_style))
else:
print("Annotation style changed from '{}' to '{}', but no scale found in CSV".format(current_style, new_style))
# Update the document
Rhino.RhinoDoc.ActiveDoc.Views.Redraw()
# Run the function
reassign_annotation_style()
annotation style.csv (141 Bytes)
24-01 Typ Sheet Template_5.0.3dm (4.5 MB)