Hello,
I’m updating some of my older scripts and having an issue in Python 3 related to the following lines, I have a single input value in an input “T” for “Thickness”, the input Type is an Int with List Access.
This code works fine in the old script component. Is this a Python2 → Python3 syntax thing or related to the script editor? @eirannejad
The intent is to draw curves with a custom lineweight and thickness to the foreground of the viewport.
thickness = self.t[i % len(self.t)] if self.t else None
Error:
1. Error running script: 'int' object is not subscriptable
Full Code:
from ghpythonlib.componentbase import executingcomponent as component
import Rhino
import System
__author__ = "Michael Vollrath"
__version__ = "2023.08.01"
# Made With <3 In Dallas, TX
# Modification of script originally created by Seghier Khaled
ghenv.Component.Name = "Custom Preview Lineweight"
ghenv.Component.NickName = "CPL"
ghenv.Component.Description = "Custom Preview component allowing thickness and color preview of curves"
ghenv.Component.Params.Input[0].Name = "Curve"
ghenv.Component.Params.Input[0].NickName = "C"
ghenv.Component.Params.Input[0].Description = "Input Curves"
ghenv.Component.Params.Input[1].Name = "Thickness"
ghenv.Component.Params.Input[1].NickName = "T"
ghenv.Component.Params.Input[1].Description = "Curve Thickness"
ghenv.Component.Params.Input[2].Name = "Color"
ghenv.Component.Params.Input[2].NickName = "Pc"
ghenv.Component.Params.Input[2].Description = "Preview Color"
class CurveColor(component):
def RunScript(self, C, T, Pc):
self.C = C
self.RGB = Pc
self.t = T
if not self.C:
return
def DrawViewportWires(self, arg):
if not self.C:
return
# Check if self.C is a list
if isinstance(self.C, list):
for i, curve in enumerate(self.C):
# Get the corresponding thickness and RGB values using modulo to wrap the lists
thickness = self.t[i % len(self.t)] if self.t else None
rgb = self.RGB[i % len(self.RGB)] if self.RGB else None
self.DrawCurveWithColor(arg, curve, thickness, rgb)
else:
# Single curve case
self.DrawCurveWithColor(arg, self.C, self.t[0] if self.t else None, self.RGB[0] if self.RGB else None)
def DrawCurveWithColor(self, arg, curve, thickness=None, rgb=None):
if not curve:
return
if thickness is None:
thickness = self.t
if rgb is None:
rgb = self.RGB
arg.Display.DrawCurve(curve, rgb, thickness)
# Handle Draw Foreground Events
def __exit__(self):
Rhino.Display.DisplayPipeline.DrawForeground -= self.DrawViewportWires
def __enter__(self):
Rhino.Display.DisplayPipeline.DrawForeground += self.DrawViewportWires
@AndersDeleuran have you come across this by chance?
Thank you all for your response!
10 posts - 5 participants