Jump to content

Setting pen colours using scripting


Recommended Posts

I don't know if anyone can help with this. I have been trying to use python scripting to create new classes by importing data from a .cvs file with the class name, lineweight, and pen colour. The script is able to import the name and linewights correctly without any problems. However, when it comes to setting the pen colour it doesn't work and either has  just black and white, or semmingly random colours. And help into what i am missing here would be greatly appreciated.

 

 

import csv
import vs

# Prompt the user to select the CSV file
file_path = vs.GetFile()

# Check if a file was selected
if file_path:
    # Read the CSV file
    with open(file_path, mode='r') as file:
        csv_reader = csv.DictReader(file)
        for row in csv_reader:
            class_name = row['Class Name']
            line_weight_mm = float(row['Line Thickness (mm)'])
            pen_r = int(row['Pen Color (R)'])
            pen_g = int(row['Pen Color (G)'])
            pen_b = int(row['Pen Color (B)'])

            # Convert line weight to mils
            line_weight_mils = round(line_weight_mm / 0.0254)

            # Create class and set attributes
            vs.NameClass(class_name)
            vs.SetClUseGraphic(class_name, True)
            vs.SetClLW(class_name, int(line_weight_mils))  # Set line weight
            vs.SetClPenFore(class_name, pen_r, pen_g, pen_b)
            vs.SetClPenBack(class_name, pen_r, pen_g, pen_b)
            vs.SetClFPat(class_name, 0)

    vs.AlrtDialog('Classes created successfully with correct line weights from the selected CSV file!')
else:
    vs.AlrtDialog('No file was selected. Operation canceled.')

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...