Not sure why this is giving you a full crash, it would be easier if it just printed an error, but the issue is with your RootFolder
and Imagery
variables: they are not defined in Get_Preview_Image
. Here’s something that works:
import clr
clr.AddReference("Eto")
clr.AddReference("Rhino.UI")
from Rhino.UI import *
from Eto.Forms import *
from Eto.Drawing import *
import os
import scriptcontext
import rhinoscriptsyntax as rs
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
class LuminaireManager(forms.Form):
def __init__(self):
self.Title = "Luminaire Manager"
self.Resizable = False
self.Padding = drawing.Padding(2)
self.Topmost = True
RootFolder =r"C:\Users\pcuvil\Desktop"
self.RootFolder = RootFolder
Luminaires = r"\Luminaires"
Imagery = r"\PreviewImages"
self.Imagery = Imagery
LampDetail = r"\Descriptions"
def Titles(text):
m_label = forms.Label()
m_label.Text = text
m_label.VerticalAlignment = forms.VerticalAlignment.Center
m_label.TextAlignment = forms.TextAlignment.Right
return m_label
self.LumLib = forms.ListBox()
self.LumLib.ToolTip = "A list of the Luminaire objects in the scene containing the designated naming convention."
self.LumLib.Height = 150
self.LumLib.Width = 400
self.LumLib.DataStore = os.listdir(RootFolder + Luminaires)
self.LumLib.SelectedIndexChanged += self.Get_Preview_Image
self.previewimage = ImageView()
self.previewimage.ToolTip = "A preview of the Luminaire."
self.previewimage.Image = Bitmap(RootFolder + Imagery + r"\a.jpg")
self.previewimage.Height = 150
self.previewimage.Width = 150
self.groupbox0 = forms.GroupBox(Text = "Luminaire Library:")
Padding = drawing.Padding(10, 5, 10, 5)
grouplayout0 = forms.DynamicLayout()
grouplayout0.Spacing = drawing.Size(5, 5)
self.groupbox1 = forms.GroupBox(Text = "Luminaire Preview:")
Padding = drawing.Padding(30, 15, 30, 15)
grouplayout1 = forms.DynamicLayout()
grouplayout1.Spacing = drawing.Size(10, 10)
grouplayout0.AddRow(None)
grouplayout0.AddRow(self.LumLib)
grouplayout0.AddRow(None)
self.groupbox0.Content = grouplayout0
grouplayout1.AddRow(None)
grouplayout1.AddRow(self.previewimage)
grouplayout1.AddRow(None)
self.groupbox1.Content = grouplayout1
layout = forms.DynamicLayout(DefaultSpacing = drawing.Size(2,2))
layout.AddRow(self.groupbox0, self.groupbox1)
self.Content = layout;
def Get_Preview_Image(self, sender, e):
LumPreview = r"\PlaceHolder.jpg"
LumPreview = "\\" + self.LumLib.DataStore[self.LumLib.SelectedIndex].replace(".3dm", ".jpg")
image_path = self.RootFolder + self.Imagery + LumPreview
self.previewimage.Image = Bitmap(image_path)
def LuminaireManagerWindow():
dlg = LuminaireManager()
dlg.Show();
if __name__ == "__main__":
LuminaireManagerWindow()
As an aside not directly related to your problem, I think you should try to use Python’s os.path
facilities to deal with paths. Although strings are a good approximation for a static path, joining them and moving around directories will be much safer with os.path
. Also, when dealing with backslashes in strings (and paths-as-strings on Windows), make sure all of them are properly escaped, either with "with\\slash"
or r"with\slash"
, or you will have surprises when your folder names start with some letters.
@curtisw, is there something to look at for you here? I feel like this should not be a complete Rhino crash. I’ve got a report on Raygun, and a minimal example below (crash on the print(crash_rhino)
line):
import Eto.Drawing as drawing
import Eto.Forms as forms
class CrashList(forms.Form):
def __init__(self):
self.listbox = forms.ListBox()
self.listbox.DataStore = ["a", "b", "c"]
self.listbox.SelectedIndexChanged += self.onIndexChanged
self.Content = self.listbox
def onIndexChanged(self, sender, e):
print(self.listbox.SelectedIndex)
print(crash_rhino)
if __name__ == "__main__":
dlg = CrashList()
dlg.Show()