Nathan, Not sure if I understood correctly.
If I run the command, I do get the gui to come up but I am not seeing any of the data pulled from Document User Text
If I run it in editor, I am getting
Message: global name ‘CustName_val’ is not defined
Here is what I am running now.
import Rhino
import scriptcontext
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs
__commandname__ = "viProjectSettings"
################################################################################
# Sample dialog class extending the Eto Dialog()
# A guide for Rhino.Python Eto Dialog can be found at:
# http://developer.rhino3d.com/guides/rhinopython/eto-controls-python/
################################################################################
class viProjectSettingsDialog(forms.Dialog[bool]):
CustName_key = "beetle_CustomerName"
ProdName_key = "beetle_ProductName"
Qty_key = "beetle_Quantity"
InvNum_key = "beetle_InvoiceNumber"
ProjNum_key = "beetle_ProjectNumber"
DesBy_key = "beetle_DesignDrawnBy"
DesDate_key = "beetle_DesignDrawnDate"
AppxWeight_key = "beetle_ApproxWeight"
ShopBy_key = "beetle_ShopDrawnBy"
ShopDate_key = "beetle_ShopDrawnDate"
TypHole_key = "beetle_CommonHoleSize"
Tol_key = "beetle_Tolerance"
CustName_val = rs.GetDocumentUserText(CustName_key)
ProdName_val = rs.GetDocumentUserText(ProdName_key)
Qty_val = rs.GetDocumentUserText(Qty_key)
InvNum_val = rs.GetDocumentUserText(InvNum_key)
ProjNum_val = rs.GetDocumentUserText(ProjNum_key)
DesBy_val = rs.GetDocumentUserText(DesBy_key)
DesDate_val = rs.GetDocumentUserText(DesDate_key)
AppoxWeight_val = rs.GetDocumentUserText(AppxWeight_key)
ShopBy_val = rs.GetDocumentUserText(ShopBy_key)
ShopDate_val = rs.GetDocumentUserText(ShopDate_key)
TypHole_val = rs.GetDocumentUserText(TypHole_key)
Tol_val = rs.GetDocumentUserText(Tol_key)
Notes_val = rs.Notes()
def __init__(self):
# Initialize dialog box
self.Title = 'Project Settings'
#self.ClientSize = drawing.Size(500, 500)
self.Padding = drawing.Padding(10)
self.Resizable = False
# Create controls for the dialog
self.custName_label = forms.Label(Text = 'Customer Name:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.custName_textbox = forms.TextBox(Text = CustName_val)
self.prodName_label = forms.Label(Text = 'Product Name:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.prodName_textbox = forms.TextBox(Text = ProdName_val)
self.qty_label = forms.Label(Text = 'Quantity:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.qty_textbox = forms.TextBox(Text = Qty_val)
self.invoice_label = forms.Label(Text = 'Invoice Number:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.inv_textbox = forms.TextBox(Text = InvNum_val)
self.projNumber_label = forms.Label(Text = 'Project Number:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.projNum_textbox = forms.TextBox(Text = ProjNum_val)
self.desBy_label = forms.Label(Text = 'Design Drawn By:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.desBy_textbox = forms.TextBox(Text = DesBy_val)
self.desRevDate_label = forms.Label(Text = 'Design Rev. Date:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.desDate_textbox = forms.TextBox(Text = DesDate_val)
self.appxWeight_label = forms.Label(Text = 'Approx Weight:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.appxWeight_textbox = forms.TextBox(Text = AppoxWeight_val)
self.shopBy_label = forms.Label(Text = 'Shop Drawn By:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.shopBy_textbox = forms.TextBox(Text = ShopBy_val)
self.shopRevDate_label = forms.Label(Text = 'Shop Rev. Date:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.shopDate_textbox = forms.TextBox(Text = ShopDate_val)
self.typHole_label = forms.Label(Text = 'Common Hole Size:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.typHole_textbox = forms.TextBox(Text = TypHole_val)
self.tolerance_label = forms.Label(Text = 'Tolerance:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.tol_textbox = forms.TextBox(Text = Tol_val)
# Create Text Area Box
self.notes = forms.TextArea(Text = Notes_val)
self.notes.Size = drawing.Size(240, 100)
self.notes_lable = forms.Label(Text = 'Notes:', VerticalAlignment = forms.VerticalAlignment.Top, TextAlignment = forms.TextAlignment.Right)
# Create the default button
self.DefaultButton = forms.Button(Text = 'OK')
self.DefaultButton.Click += self.OnOKButtonClick
# Create the abort button
self.AbortButton = forms.Button(Text = 'Cancel')
self.AbortButton.Click += self.OnCloseButtonClick
# Create a table layout and add all the controls
layout = forms.DynamicLayout()
layout.Spacing = drawing.Size(5, 5)
layout.AddRow(self.custName_label, self.custName_textbox)
layout.AddRow(self.prodName_label, self.prodName_textbox)
layout.AddRow(self.qty_label, self.qty_textbox)
layout.AddRow(self.invoice_label, self.inv_textbox)
layout.AddRow(self.projNumber_label, self.projNum_textbox)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.appxWeight_label, self.appxWeight_textbox)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.desBy_label, self.desBy_textbox)
layout.AddRow(self.desRevDate_label, self.desDate_textbox)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.shopBy_label, self.shopBy_textbox)
layout.AddRow(self.shopRevDate_label, self.shopDate_textbox)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.typHole_label, self.typHole_textbox)
layout.AddRow(self.tolerance_label, self.tol_textbox)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.notes_lable , self.notes)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.DefaultButton, self.AbortButton)
# Set the dialog content
self.Content = layout
# Start of the class functions
# Get the value of the textbox
def GetText(self):
rs.SetDocumentUserText(CustName_key, self.custName_textbox.Text)
rs.SetDocumentUserText(ProdName_key, self.prodName_textbox.Text)
rs.SetDocumentUserText(Qty_key, self.qty_textbox.Text)
rs.SetDocumentUserText(InvNum_key, self.inv_textbox.Text)
rs.SetDocumentUserText(ProjNum_key, self.projNum_textbox.Text)
rs.SetDocumentUserText(DesBy_key, self.desBy_textbox.Text)
rs.SetDocumentUserText(DesDate_key, self.desDate_textbox.Text)
rs.SetDocumentUserText(AppxWeight_key, self.appxWeight_textbox.Text)
rs.SetDocumentUserText(ShopBy_key, self.shopBy_textbox.Text)
rs.SetDocumentUserText(ShopDate_key, self.shopDate_textbox.Text)
rs.SetDocumentUserText(TypHole_key, self.typHole_textbox.Text)
rs.SetDocumentUserText(Tol_key, self.tol_textbox.Text)
rs.Notes(self.notes.Text)
# Close button click handler
def OnCloseButtonClick(self, sender, e):
#self.custName_textbox.Text = ""
self.Close(False)
# OK button click handler
def OnOKButtonClick(self, sender, e):
if (self.custName_textbox.Text == "") or (self.custName_textbox.Text == " "):
rs.MessageBox ("Customer Name is empty!", 48)
if (self.prodName_textbox.Text == "") or (self.prodName_textbox.Text == " "):
rs.MessageBox ("Project Number is empty!", 48)
if (self.qty_textbox.Text == "") or (self.qty_textbox.Text == " "):
rs.MessageBox ("Quantity is empty!", 48)
if (self.inv_textbox.Text == "") or (self.inv_textbox.Text == " "):
rs.MessageBox ("Inoice Number is empty!", 48)
if (self.projNum_textbox.Text == "") or (self.projNum_textbox.Text == " "):
rs.MessageBox ("Project Number is empty!", 48)
if (self.desBy_textbox.Text == "") or (self.desBy_textbox.Text == " "):
rs.MessageBox ("Design Drawn By is empty!", 48)
if (self.desDate_textbox.Text == "") or (self.desDate_textbox.Text == " "):
rs.MessageBox ("Design Rev Date is empty!", 48)
if (self.appxWeight_textbox.Text == "") or (self.appxWeight_textbox.Text == " "):
rs.MessageBox ("Approximate Weight is empty!", 48)
if (self.shopBy_textbox.Text == "") or (self.shopBy_textbox.Text == " "):
rs.MessageBox ("Shop Drawn By is empty!", 48)
if (self.shopDate_textbox.Text == "") or (self.shopDate_textbox.Text == " "):
rs.MessageBox ("Shop Rev Date is empty!", 48)
if (self.typHole_textbox.Text == "") or (self.typHole_textbox.Text == " "):
rs.MessageBox ("Common Hole Size is empty!", 48)
if (self.tol_textbox.Text == "") or (self.tol_textbox.Text == " "):
rs.MessageBox ("Tolerance is empty!", 48)
else:
self.Close(True)
## End of Dialog Class ##
################################################################################
# Creating a dialog instance and displaying the dialog.
################################################################################
# The script that will be using the dialog.
def RequestProjectSettings():
dialog = viProjectSettingsDialog();
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if (rc):
dialog.GetText()
print "Beetle Updated Project Settings"
else:
print "Beetle did NOT update Project Settings"
# RunCommand is the called when the user enters the command name in Rhino.
# The command name is defined by the filname minus "_cmd.py"
def RunCommand( is_interactive ):
print "Running", __commandname__
RequestProjectSettings()
################################################################################
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
################################################################################
if __name__ == "__main__":
RequestProjectSettings()
#print "At the end"
#return 0
#RunCommand(True)
However, if I keep the _key and _val outside of the class I am getting to run correctly in the editor and from command.
import Rhino
import scriptcontext
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs
__commandname__ = "viProjectSettings"
CustName_key = "beetle_CustomerName"
ProdName_key = "beetle_ProductName"
Qty_key = "beetle_Quantity"
InvNum_key = "beetle_InvoiceNumber"
ProjNum_key = "beetle_ProjectNumber"
DesBy_key = "beetle_DesignDrawnBy"
DesDate_key = "beetle_DesignDrawnDate"
AppxWeight_key = "beetle_ApproxWeight"
ShopBy_key = "beetle_ShopDrawnBy"
ShopDate_key = "beetle_ShopDrawnDate"
TypHole_key = "beetle_CommonHoleSize"
Tol_key = "beetle_Tolerance"
CustName_val = rs.GetDocumentUserText(CustName_key)
ProdName_val = rs.GetDocumentUserText(ProdName_key)
Qty_val = rs.GetDocumentUserText(Qty_key)
InvNum_val = rs.GetDocumentUserText(InvNum_key)
ProjNum_val = rs.GetDocumentUserText(ProjNum_key)
DesBy_val = rs.GetDocumentUserText(DesBy_key)
DesDate_val = rs.GetDocumentUserText(DesDate_key)
AppoxWeight_val = rs.GetDocumentUserText(AppxWeight_key)
ShopBy_val = rs.GetDocumentUserText(ShopBy_key)
ShopDate_val = rs.GetDocumentUserText(ShopDate_key)
TypHole_val = rs.GetDocumentUserText(TypHole_key)
Tol_val = rs.GetDocumentUserText(Tol_key)
Notes_val = rs.Notes()
################################################################################
# Sample dialog class extending the Eto Dialog()
# A guide for Rhino.Python Eto Dialog can be found at:
# http://developer.rhino3d.com/guides/rhinopython/eto-controls-python/
################################################################################
class viProjectSettingsDialog(forms.Dialog[bool]):
def __init__(self):
# Initialize dialog box
self.Title = 'Project Settings'
#self.ClientSize = drawing.Size(500, 500)
self.Padding = drawing.Padding(10)
self.Resizable = False
# Create controls for the dialog
self.custName_label = forms.Label(Text = 'Customer Name:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.custName_textbox = forms.TextBox(Text = CustName_val)
self.prodName_label = forms.Label(Text = 'Product Name:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.prodName_textbox = forms.TextBox(Text = ProdName_val)
self.qty_label = forms.Label(Text = 'Quantity:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.qty_textbox = forms.TextBox(Text = Qty_val)
self.invoice_label = forms.Label(Text = 'Invoice Number:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.inv_textbox = forms.TextBox(Text = InvNum_val)
self.projNumber_label = forms.Label(Text = 'Project Number:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.projNum_textbox = forms.TextBox(Text = ProjNum_val)
self.desBy_label = forms.Label(Text = 'Design Drawn By:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.desBy_textbox = forms.TextBox(Text = DesBy_val)
self.desRevDate_label = forms.Label(Text = 'Design Rev. Date:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.desDate_textbox = forms.TextBox(Text = DesDate_val)
self.appxWeight_label = forms.Label(Text = 'Approx Weight:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.appxWeight_textbox = forms.TextBox(Text = AppoxWeight_val)
self.shopBy_label = forms.Label(Text = 'Shop Drawn By:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.shopBy_textbox = forms.TextBox(Text = ShopBy_val)
self.shopRevDate_label = forms.Label(Text = 'Shop Rev. Date:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.shopDate_textbox = forms.TextBox(Text = ShopDate_val)
self.typHole_label = forms.Label(Text = 'Common Hole Size:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.typHole_textbox = forms.TextBox(Text = TypHole_val)
self.tolerance_label = forms.Label(Text = 'Tolerance:', VerticalAlignment = forms.VerticalAlignment.Center, TextAlignment = forms.TextAlignment.Right)
self.tol_textbox = forms.TextBox(Text = Tol_val)
# Create Text Area Box
self.notes = forms.TextArea(Text = Notes_val)
self.notes.Size = drawing.Size(240, 100)
self.notes_lable = forms.Label(Text = 'Notes:', VerticalAlignment = forms.VerticalAlignment.Top, TextAlignment = forms.TextAlignment.Right)
# Create the default button
self.DefaultButton = forms.Button(Text = 'OK')
self.DefaultButton.Click += self.OnOKButtonClick
# Create the abort button
self.AbortButton = forms.Button(Text = 'Cancel')
self.AbortButton.Click += self.OnCloseButtonClick
# Create a table layout and add all the controls
layout = forms.DynamicLayout()
layout.Spacing = drawing.Size(5, 5)
layout.AddRow(self.custName_label, self.custName_textbox)
layout.AddRow(self.prodName_label, self.prodName_textbox)
layout.AddRow(self.qty_label, self.qty_textbox)
layout.AddRow(self.invoice_label, self.inv_textbox)
layout.AddRow(self.projNumber_label, self.projNum_textbox)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.appxWeight_label, self.appxWeight_textbox)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.desBy_label, self.desBy_textbox)
layout.AddRow(self.desRevDate_label, self.desDate_textbox)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.shopBy_label, self.shopBy_textbox)
layout.AddRow(self.shopRevDate_label, self.shopDate_textbox)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.typHole_label, self.typHole_textbox)
layout.AddRow(self.tolerance_label, self.tol_textbox)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.notes_lable , self.notes)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.DefaultButton, self.AbortButton)
# Set the dialog content
self.Content = layout
# Start of the class functions
# Get the value of the textbox
def GetText(self):
rs.SetDocumentUserText(CustName_key, self.custName_textbox.Text)
rs.SetDocumentUserText(ProdName_key, self.prodName_textbox.Text)
rs.SetDocumentUserText(Qty_key, self.qty_textbox.Text)
rs.SetDocumentUserText(InvNum_key, self.inv_textbox.Text)
rs.SetDocumentUserText(ProjNum_key, self.projNum_textbox.Text)
rs.SetDocumentUserText(DesBy_key, self.desBy_textbox.Text)
rs.SetDocumentUserText(DesDate_key, self.desDate_textbox.Text)
rs.SetDocumentUserText(AppxWeight_key, self.appxWeight_textbox.Text)
rs.SetDocumentUserText(ShopBy_key, self.shopBy_textbox.Text)
rs.SetDocumentUserText(ShopDate_key, self.shopDate_textbox.Text)
rs.SetDocumentUserText(TypHole_key, self.typHole_textbox.Text)
rs.SetDocumentUserText(Tol_key, self.tol_textbox.Text)
rs.Notes(self.notes.Text)
# Close button click handler
def OnCloseButtonClick(self, sender, e):
#self.custName_textbox.Text = ""
self.Close(False)
# OK button click handler
def OnOKButtonClick(self, sender, e):
if (self.custName_textbox.Text == "") or (self.custName_textbox.Text == " "):
rs.MessageBox ("Customer Name is empty!", 48)
if (self.prodName_textbox.Text == "") or (self.prodName_textbox.Text == " "):
rs.MessageBox ("Project Number is empty!", 48)
if (self.qty_textbox.Text == "") or (self.qty_textbox.Text == " "):
rs.MessageBox ("Quantity is empty!", 48)
if (self.inv_textbox.Text == "") or (self.inv_textbox.Text == " "):
rs.MessageBox ("Inoice Number is empty!", 48)
if (self.projNum_textbox.Text == "") or (self.projNum_textbox.Text == " "):
rs.MessageBox ("Project Number is empty!", 48)
if (self.desBy_textbox.Text == "") or (self.desBy_textbox.Text == " "):
rs.MessageBox ("Design Drawn By is empty!", 48)
if (self.desDate_textbox.Text == "") or (self.desDate_textbox.Text == " "):
rs.MessageBox ("Design Rev Date is empty!", 48)
if (self.appxWeight_textbox.Text == "") or (self.appxWeight_textbox.Text == " "):
rs.MessageBox ("Approximate Weight is empty!", 48)
if (self.shopBy_textbox.Text == "") or (self.shopBy_textbox.Text == " "):
rs.MessageBox ("Shop Drawn By is empty!", 48)
if (self.shopDate_textbox.Text == "") or (self.shopDate_textbox.Text == " "):
rs.MessageBox ("Shop Rev Date is empty!", 48)
if (self.typHole_textbox.Text == "") or (self.typHole_textbox.Text == " "):
rs.MessageBox ("Common Hole Size is empty!", 48)
if (self.tol_textbox.Text == "") or (self.tol_textbox.Text == " "):
rs.MessageBox ("Tolerance is empty!", 48)
else:
self.Close(True)
## End of Dialog Class ##
################################################################################
# Creating a dialog instance and displaying the dialog.
################################################################################
# The script that will be using the dialog.
def RequestProjectSettings():
dialog = viProjectSettingsDialog();
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if (rc):
dialog.GetText()
print "Beetle Updated Project Settings"
else:
print "Beetle did NOT update Project Settings"
# RunCommand is the called when the user enters the command name in Rhino.
# The command name is defined by the filname minus "_cmd.py"
def RunCommand( is_interactive ):
print "Running", __commandname__
RequestProjectSettings()
################################################################################
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
################################################################################
if __name__ == "__main__":
RequestProjectSettings()
#print "At the end"
#return 0
#RunCommand(True)
Outside of it working is that ^^^ the correct way of doing this? Or am I just getting lucky?
To me, it makes sense, cause I am pulling data above the class and the class is able to populate itself. But then again, 1st time “working” with classes.
Thanks for your patience!