Add and Remove elements from Eto

I have a Modeless form, and I want to change the contents of it to something else depending on what button is pushed.
I want this section over here to change to other things
lines (52-60)

		# Create a group box for atrButtons
		self.m_groupboxAtr = forms.GroupBox()
		self.m_groupboxAtr.Padding = drawing.Padding(5)

		groupLayoutAtr = forms.DynamicLayout()
		groupLayoutAtr.Spacing = drawing.Size(5, 5)

		groupLayoutAtr.AddRow(self.CreateAtrButtons())
		self.m_groupboxAtr.Content = groupLayoutAtr

it’s pulled by line 84

		layout.AddRow(groupLayoutPartNum, groupLayoutAtr)

When one of the buttons gets clicked I want to remove the groupLayoutAtr and push something else to display in that area.
I know what most of my work is going to happen in OnAtrButtonClick line 180, or AssignAttributes line 184
I just don’t know how to “unload” one group set so I can load something else in there…
I’ve changed everything to one icon file attached here. In case some needs to try and run the script.

btn_test

But here is what it looks like on my end.

AtrForm

import System
import Rhino
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import scriptcontext as sc
import rhinoscriptsyntax as rs
import os
import time

dir = os.path.dirname(__file__)


__commandname__ = "viAttributeTEMP2"

class viAttributeForm(forms.Form):

   def __init__(self):
      self.Initialize()
      self.previousHighlight = set()

   # Basic form initialization
   def Initialize(self):
      self.Title = 'Attribute Form'
      self.Padding = drawing.Padding(5)
      self.Resizable = False
      self.Maximizable = False
      self.Minimizable = False
      self.ShowInTaskbar = True
      self.MinimumSize = drawing.Size(650, 400)

      # Create a group box for PartNum
      self.m_groupboxPtNum = forms.GroupBox()
      self.m_groupboxPtNum.Padding = drawing.Padding(5)

      groupLayoutPartNum = forms.DynamicLayout()
      groupLayoutPartNum.Spacing = drawing.Size(5, 5)

      groupLayoutPartNum.AddRow(self.CreateListBox())
      self.m_groupboxPtNum.Content = groupLayoutPartNum
      
      # Create a group box for Highlite button
      self.m_groupboxHighlight = forms.GroupBox()
      self.m_groupboxHighlight.Padding = drawing.Padding(5)

      groupLayoutHighlight = forms.DynamicLayout()
      groupLayoutHighlight.Spacing = drawing.Size(5, 5)

      groupLayoutHighlight.AddRow(self.CreateHighlightButton())
      self.m_groupboxHighlight.Content = groupLayoutHighlight

      # Create a group box for atrButtons
      self.m_groupboxAtr = forms.GroupBox()
      self.m_groupboxAtr.Padding = drawing.Padding(5)

      groupLayoutAtr = forms.DynamicLayout()
      groupLayoutAtr.Spacing = drawing.Size(5, 5)

      groupLayoutAtr.AddRow(self.CreateAtrButtons())
      self.m_groupboxAtr.Content = groupLayoutAtr

      # Create a group box for Default Buttons
      self.m_groupboxDefaultButtons = forms.GroupBox()
      self.m_groupboxDefaultButtons.Padding = drawing.Padding(5)

      groupDefaultButtons = forms.DynamicLayout()
      groupDefaultButtons.Spacing = drawing.Size(5, 5)

      groupDefaultButtons.AddRow(self.CreateDefaultButtons())
      self.m_groupboxDefaultButtons.Content = groupDefaultButtons


      # Create a label control
      labelParts = forms.Label()
      labelParts.Text = 'Parts'
      lableAtr = forms.Label()
      lableAtr.Text = 'Attributes'
      # Create dynamic layout control
      layout = forms.DynamicLayout()
      layout.Padding = drawing.Padding(5)
      layout.Spacing = drawing.Size(5, 5)
      # Add controls to layout
      layout.AddRow(labelParts, lableAtr)
      layout.AddRow(groupLayoutPartNum, groupLayoutAtr)
      layout.AddRow(groupLayoutHighlight, groupDefaultButtons)

      # Set the dialog content
      self.Content = layout

      # FormClosed event handler
      self.Closed += self.OnFormClosed

   def CreateListBox(self):
      #Create ListBox
      listbox = forms.ListBox()
      listbox.DataStore = self.organizedKeys()
      listbox.SelectedIndex = 0
      listbox.Size = drawing.Size(100,300)
      self.m_listbox = listbox
      return self.m_listbox

   def GetSelectedPartsGUIDs(self):
      ### Need a way to check if there is anything in the scea, or if anything got selected
      ### Otherwise a lot of stuff will be crashing
      ### As it relies on this selection
      # Grab the list box data
      listBoxData = self.m_listbox.DataStore
      # Grab selected index
      selectedIndex = self.m_listbox.SelectedIndex
      # Get part number from list box based on selection index
      objTofind = listBoxData[selectedIndex]
      # Find objects in dictionary based on part number
      foundObj = self.mainDictionary.get(str(objTofind))
      return foundObj, objTofind
   
   def OnHighlightButtonClick(self, sender, e):
      foundObj = self.GetSelectedPartsGUIDs()[0]
      currentHighlight = set(foundObj)
      # If something was found
      if foundObj != None:
         # if previousHighlight set is not empty and currentHighlight is not same as previousHighlight
         if not not self.previousHighlight and currentHighlight != self.previousHighlight:
            # Set all objects to color by layer
            for priv_obj in self.previousHighlight:
               rs.ObjectColorSource(priv_obj, source=0)
            # Clear out previousHighlight set
            self.previousHighlight.clear()
            # Change color to highlight and add them to previousHighlight set
            for obj in foundObj:
               rs.ObjectColor(obj, color=(117,255,127))
               self.previousHighlight.add(obj)
         else:
            # For every object found run loop
            for obj in foundObj:
               ColorSource = rs.ObjectColorSource(obj)
               # If color source is 0 (by layer), change to green 
               # If color source is something else, change to layer source
               if ColorSource == 0:
                  rs.ObjectColor(obj, color=(117,255,127))
                  self.previousHighlight.add(obj)
               else:
                  rs.ObjectColorSource(obj, source=0)
                  self.previousHighlight.discard(obj)

   # OK button click handler
   def OnOkButtonClick(self, sender, e):
      self.m_selected_index = self.m_listbox.SelectedIndex
      self.Close()
   
   # Cancel button click handler
   def OnCancelButtonClick(self, sender, e):
      self.Close()

   # Create button controls
   def CreateDefaultButtons(self):
      # 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.OnCancelButtonClick
      # Create button layout
      button_layout = forms.DynamicLayout()
      button_layout.Spacing = drawing.Size(5, 5)
      button_layout.AddRow(None, self.DefaultButton, self.AbortButton, None)
      return button_layout
   
   # Create button controls
   def CreateHighlightButton(self):
      # Create the highlight button
      self.HighlightButton = forms.Button(Text = 'Highlight')
      self.HighlightButton.Click += self.OnHighlightButtonClick
      # Create button layout
      button_layout = forms.DynamicLayout()
      button_layout.Spacing = drawing.Size(5, 5)
      button_layout.AddRow(None, self.HighlightButton, None)
      return button_layout

   # Atr button click handler
   def OnAtrButtonClick(self, sender, e):
      atrClass = sender.Tag 
      self.AssignAttributes(atrClass)

   def AssignAttributes(self, atrClass):
      print 'Class: {}'.format(atrClass)
      PartNum = self.GetSelectedPartsGUIDs()[1]
      print 'PartNum',PartNum
      GUIDs = self.GetSelectedPartsGUIDs()[0]
      print 'GUIDs',GUIDs

   # Create button controls
   def CreateAtrButtons(self):
      # wood image icon
      image_btn_wood = forms.ImageView()
      image_btn_wood.Size = drawing.Size(50, 50)
      image_btn_wood.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # angle image icon
      image_btn_angle = forms.ImageView()
      image_btn_angle.Size = drawing.Size(50, 50)
      image_btn_angle.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # flatStock image icon
      image_btn_flatStock = forms.ImageView()
      image_btn_flatStock.Size = drawing.Size(50, 50)
      image_btn_flatStock.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # tubeRect image icon
      image_btn_tubeRect = forms.ImageView()
      image_btn_tubeRect.Size = drawing.Size(50, 50)
      image_btn_tubeRect.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # tubeSquare image icon
      image_btn_tubeSquare = forms.ImageView()
      image_btn_tubeSquare.Size = drawing.Size(50, 50)
      image_btn_tubeSquare.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # tubeRound image icon
      image_btn_tubeRound = forms.ImageView()
      image_btn_tubeRound.Size = drawing.Size(50, 50)
      image_btn_tubeRound.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))


      # solidSquare image icon
      image_btn_solidSquare = forms.ImageView()
      image_btn_solidSquare.Size = drawing.Size(50, 50)
      image_btn_solidSquare.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # solidRound image icon
      image_btn_solidRound = forms.ImageView()
      image_btn_solidRound.Size = drawing.Size(50, 50)
      image_btn_solidRound.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # solidHalf image icon
      image_btn_solidHalf = forms.ImageView()
      image_btn_solidHalf.Size = drawing.Size(50, 50)
      image_btn_solidHalf.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # mesh image icon
      image_btn_mesh = forms.ImageView()
      image_btn_mesh.Size = drawing.Size(50, 50)
      image_btn_mesh.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # pipe image icon
      image_btn_pipe = forms.ImageView()
      image_btn_pipe.Size = drawing.Size(50, 50)
      image_btn_pipe.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # tBar image icon
      image_btn_tBar = forms.ImageView()
      image_btn_tBar.Size = drawing.Size(50, 50)
      image_btn_tBar.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))


      # iBeam image icon
      image_btn_iBeam = forms.ImageView()
      image_btn_iBeam.Size = drawing.Size(50, 50)
      image_btn_iBeam.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # cChan image icon
      image_btn_cChan = forms.ImageView()
      image_btn_cChan.Size = drawing.Size(50, 50)
      image_btn_cChan.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # plate image icon
      image_btn_plate = forms.ImageView()
      image_btn_plate.Size = drawing.Size(50, 50)
      image_btn_plate.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # cust image icon
      image_btn_cust = forms.ImageView()
      image_btn_cust.Size = drawing.Size(50, 50)
      image_btn_cust.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))
      # stock image icon
      image_btn_stock = forms.ImageView()
      image_btn_stock.Size = drawing.Size(50, 50)
      image_btn_stock.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_test.png'))

      # Create button
      self.WoodButton = forms.Button(Text = 'Wood', Tag='000')
      self.WoodButton.Click += self.OnAtrButtonClick
      # Create button
      self.AngleButton = forms.Button(Text = 'Angle', Tag='100')
      self.AngleButton.Click += self.OnAtrButtonClick
      # Create button
      self.FlatStockButton = forms.Button(Text = 'Flat Stock', Tag='101')
      self.FlatStockButton.Click += self.OnAtrButtonClick
      # Create button
      self.TubeRectButton = forms.Button(Text = 'Tube Rect', Tag='102')
      self.TubeRectButton.Click += self.OnAtrButtonClick
      # Create button
      self.TubeSquareButton = forms.Button(Text = 'Tube Square', Tag='103')
      self.TubeSquareButton.Click += self.OnAtrButtonClick
      # Create button
      self.TubeRoundButton = forms.Button(Text = 'Tube Round', Tag='104')
      self.TubeRoundButton.Click += self.OnAtrButtonClick

      # Create button
      self.SolidSquareButton = forms.Button(Text = 'Solid Square', Tag='105')
      self.SolidSquareButton.Click += self.OnAtrButtonClick
      # Create button
      self.SolidRoundButton = forms.Button(Text = 'Solid Round', Tag='106')
      self.SolidRoundButton.Click += self.OnAtrButtonClick
      # Create button
      self.SolidHalfButton = forms.Button(Text = 'Half Round', Tag='107')
      self.SolidHalfButton.Click += self.OnAtrButtonClick
      # Create button
      self.MeshButton = forms.Button(Text = 'Mesh', Tag='108')
      self.MeshButton.Click += self.OnAtrButtonClick
      # Create button
      self.PipeButton = forms.Button(Text = 'Pipe', Tag='109')
      self.PipeButton.Click += self.OnAtrButtonClick
      # Create button
      self.TBarButton = forms.Button(Text = 'T-Bar', Tag='110')
      self.TBarButton.Click += self.OnAtrButtonClick

      # Create button
      self.IBeamButton = forms.Button(Text = 'I-Beam', Tag='111')
      self.IBeamButton.Click += self.OnAtrButtonClick
      # Create button
      self.CChanButton = forms.Button(Text = 'C-Channel', Tag='112')
      self.CChanButton.Click += self.OnAtrButtonClick
      # Create button
      self.PlateButton = forms.Button(Text = 'Plate', Tag='200')
      self.PlateButton.Click += self.OnAtrButtonClick
      # Create button
      self.CustButton = forms.Button(Text = 'Custom', Tag='300')
      self.CustButton.Click += self.OnAtrButtonClick
      # Create button
      self.StockButton = forms.Button(Text = 'Stock', Tag='400')
      self.StockButton.Click += self.OnAtrButtonClick


      # Create button layout
      atr_button_layout = forms.DynamicLayout()
      atr_button_layout.Spacing = drawing.Size(5, 5)
      atr_button_layout.Size = drawing.Size(550,300)
      atr_button_layout.AddRow(image_btn_wood, image_btn_angle, image_btn_flatStock, image_btn_tubeRect, image_btn_tubeSquare, image_btn_tubeRound)
      atr_button_layout.AddRow(self.WoodButton, self.AngleButton, self.FlatStockButton, self.TubeRectButton, self.TubeSquareButton, self.TubeRoundButton)
      atr_button_layout.AddRow(None, None, None, None, None, None)
      atr_button_layout.AddRow(None, None, None, None, None, None)
      atr_button_layout.AddRow(image_btn_solidSquare, image_btn_solidRound, image_btn_solidHalf, image_btn_mesh, image_btn_pipe, image_btn_tBar)
      atr_button_layout.AddRow(self.SolidSquareButton, self.SolidRoundButton, self.SolidHalfButton, self.MeshButton, self.PipeButton, self.TBarButton)
      atr_button_layout.AddRow(None, None, None, None, None, None)
      atr_button_layout.AddRow(None, None, None, None, None, None)
      atr_button_layout.AddRow(image_btn_iBeam, image_btn_cChan, image_btn_plate, image_btn_cust, image_btn_stock, None)
      atr_button_layout.AddRow(self.IBeamButton, self.CChanButton, self.PlateButton, self.CustButton, self.StockButton, None)
      atr_button_layout.AddRow(None, None, None, None, None, None)
      atr_button_layout.AddRow(None, None, None, None, None, None)
      return atr_button_layout


   # Find all objects with a beetle_PartNum partNum_key
   def findObjects(self):
      # Get all objects in file
      ids = rs.AllObjects(include_lights=False, include_grips=False)
      
      # Set some variables
      partNum_key = 'beetle_PartNum'
   
      PartNumAndGUIDs = {}
      # for every id given run part finding
      for id in ids:
         # Get partNum from every object
         partNumFound = rs.GetUserText(id, partNum_key, False)
         # If part number is not empty make a dictionary 
         if partNumFound != None:
            # Make a dictionary with part Number as Key and GUIDs as a list of values
            PartNumAndGUIDs.setdefault(partNumFound, []).append(id)
      
      # Return dictionary once loop is over
      return PartNumAndGUIDs

   def organizedKeys(self):
      self.mainDictionary = self.findObjects()
      # Get all keys from dictionary and organize them by numerical value
      organizedKeys = sorted(list(self.mainDictionary), key=int)
      return organizedKeys

   # Form Closed event handler
   def OnFormClosed(self, sender, e):
      # Remove the events added in the initializer
      #self.RemoveEvents()
      # Dispose of the form and remove it from the sticky dictionary
      if sc.sticky.has_key('attribute_form'):
         form = sc.sticky['attribute_form']
         if form:
            #form.Dispose()
            form = None
         sc.sticky.Remove('attribute_form')

################################################################################
# Creating a dialog instance and displaying the dialog.
################################################################################
def TestViAttributeForm():
   # See if the form is already visible
   if sc.sticky.has_key('attribute_form'):
      return
   
   # Create and show form
   form = viAttributeForm()
   form.Owner = Rhino.UI.RhinoEtoApp.MainWindow
   form.Show()
   # Add the form to the sticky dictionary so it
   # survives when the main function ends.
   sc.sticky['attribute_form'] = form


# 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__



   # For every organized key print guids
   #for key in organizedKeys:
      
   #  print 'Part #: {} | Qty: {} | GUIDs: {}'.format(key, len(mainDictionary.get(key)), mainDictionary.get(key))
   #return sorted(removeDup, key=int)

   TestViAttributeForm()

if __name__ == "__main__":
   RunCommand(True)

If anyone could nudge me in the right direction, that be much appreciated. I don’t expect anyone to do a full reworked code for me. I just posted my stuff so the conversation can be a bit more direct.
I’m sure I will need to move some stuff around. I just don’t really know where to even start on this one.
If someone has an example of simple form updating it’s button layout contents be awesome to see. It’ll help to start figuring out how to figure my stuff out. :smile:

If I follow along correctly it sounds like you just need to set yourself up panels that have each “section” of controls that you want to display. Then simply have a main panel on the right side of your form where you can change its Panel.Content = SomeOtherPanel when your buttons are pressed. Hopefully that makes sense.

@Trav Thanks for some information.
I was trying to look up panel stuff and it seems like the links are broken for that
Goes to 404
https://github.com/picoe/Eto/blob/develop/Source/Eto/Forms/Controls/Panel.cs
from this article


and from this one as well

Do you know if there is any documentation or a small example on this somewhere else? Be nice if it was in python. But beggars can’t be choosers. I’ll take whatever I can get at this point.

Lots of controls can perform as a panel. In your case you can use the GroupBox like you already are as your panel. Its just a container for your controls.

1 Like

@Trav Thank you for the nudge!
Just got it working.
Not sure if that’s the best way to do it. I’m sure there is some other better way to do it. But I think it’s going to work for me.
If anyone is looking for same type of solution here is what I did

import System
import Rhino
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import scriptcontext as sc
import rhinoscriptsyntax as rs
import os
import time

dir = os.path.dirname(__file__)


__commandname__ = "viAttributeTEMP2"

class viAttributeForm(forms.Form):

	def __init__(self):
		self.showPanel = 'Default'
		self.Initialize()
		self.previousHighlight = set()

	# Basic form initialization
	def Initialize(self):
		self.Title = 'Attribute Form'
		self.Padding = drawing.Padding(5)
		self.Resizable = False
		self.Maximizable = False
		self.Minimizable = False
		self.ShowInTaskbar = True
		self.MinimumSize = drawing.Size(650, 400)

		# Create a group box for PartNum
		self.m_groupboxPtNum = forms.GroupBox()
		self.m_groupboxPtNum.Padding = drawing.Padding(5)

		self.groupLayoutPartNum = forms.DynamicLayout()
		self.groupLayoutPartNum.Spacing = drawing.Size(5, 5)

		self.groupLayoutPartNum.AddRow(self.CreateListBox())
		self.m_groupboxPtNum.Content = self.groupLayoutPartNum
		
		# Create a group box for Highlite button
		self.m_groupboxHighlight = forms.GroupBox()
		self.m_groupboxHighlight.Padding = drawing.Padding(5)

		self.groupLayoutHighlight = forms.DynamicLayout()
		self.groupLayoutHighlight.Spacing = drawing.Size(5, 5)

		self.groupLayoutHighlight.AddRow(self.CreateHighlightButton())
		self.m_groupboxHighlight.Content = self.groupLayoutHighlight


		# Create a group box for Default Buttons
		self.m_groupboxDefaultButtons = forms.GroupBox()
		self.m_groupboxDefaultButtons.Padding = drawing.Padding(5)

		self.groupDefaultButtons = forms.DynamicLayout()
		self.groupDefaultButtons.Spacing = drawing.Size(5, 5)

		self.groupDefaultButtons.AddRow(self.CreateDefaultButtons())
		self.m_groupboxDefaultButtons.Content = self.groupDefaultButtons

		self.displayMainPanel()

	def displayMainPanel(self):
		# Create a label control
		labelParts = forms.Label()
		labelParts.Text = 'Parts'
		lableAtr = forms.Label()
		lableAtr.Text = 'Attributes'
		# Create dynamic layout control
		layout = forms.DynamicLayout()
		layout.Padding = drawing.Padding(5)
		layout.Spacing = drawing.Size(5, 5)
		# Add controls to layout
		layout.AddRow(labelParts, lableAtr)
		layout.AddRow(self.groupLayoutPartNum, self.panelToShow())#groupLayoutAtr
		layout.AddRow(self.groupLayoutHighlight, self.groupDefaultButtons)

		# Set the dialog content
		self.Content = layout

		# FormClosed event handler
		self.Closed += self.OnFormClosed

	def panelToShow(self):
		if self.showPanel == '000':
			print 'Got here'
			# Create a group box for atrButtons
			self.m_groupboxAtr000 = forms.GroupBox()
			self.m_groupboxAtr000.Padding = drawing.Padding(5)

			groupLayoutAtr000 = forms.DynamicLayout()
			groupLayoutAtr000.Spacing = drawing.Size(5, 5)

			groupLayoutAtr000.AddRow(None)
			self.m_groupboxAtr000.Content = groupLayoutAtr000
			print 'Got here 2'
			return groupLayoutAtr000
		elif self.showPanel == 'Default':
			# Create a group box for atrButtons
			self.m_groupboxAtr = forms.GroupBox()
			self.m_groupboxAtr.Padding = drawing.Padding(5)

			groupLayoutAtr = forms.DynamicLayout()
			groupLayoutAtr.Spacing = drawing.Size(5, 5)

			groupLayoutAtr.AddRow(self.CreateAtrButtons())
			self.m_groupboxAtr.Content = groupLayoutAtr
			return groupLayoutAtr

	def CreateListBox(self):
		#Create ListBox
		listbox = forms.ListBox()
		listbox.DataStore = self.organizedKeys()
		if not listbox.DataStore:
			message = 'No parts attributes where found\nI will crash your Rhino if you try to use me. >:)'
			rs.MessageBox(message, buttons=0, title='ERROR')
		listbox.SelectedIndex = 0
		listbox.Size = drawing.Size(100,300)
		self.m_listbox = listbox
		return self.m_listbox

	def GetSelectedPartsGUIDs(self):
		### Need a way to check if there is anything in the scea, or if anything got selected
		### Otherwise a lot of stuff will be crashing
		### As it relies on this selection
		# Grab the list box data
		listBoxData = self.m_listbox.DataStore
		# Grab selected index
		selectedIndex = self.m_listbox.SelectedIndex
		# Get part number from list box based on selection index
		objTofind = listBoxData[selectedIndex]
		# Lose the qty
		split = objTofind.split('  |',1)[0]
		# Lose all the spaces
		cleanObjNum = split.strip()
		#print 'cleanObjNum',cleanObjNum
		# Find objects in dictionary based on part number
		foundObj = self.mainDictionary.get(str(cleanObjNum))
		return foundObj, cleanObjNum
	
	def OnHighlightButtonClick(self, sender, e):
		foundObj = self.GetSelectedPartsGUIDs()[0]
		currentHighlight = set(foundObj)
		# If something was found
		if foundObj != None:
			# if previousHighlight set is not empty and currentHighlight is not same as previousHighlight
			if not not self.previousHighlight and currentHighlight != self.previousHighlight:
				# Set all objects to color by layer
				for priv_obj in self.previousHighlight:
					rs.ObjectColorSource(priv_obj, source=0)
				# Clear out previousHighlight set
				self.previousHighlight.clear()
				# Change color to highlight and add them to previousHighlight set
				for obj in foundObj:
					rs.ObjectColor(obj, color=(117,255,127))
					self.previousHighlight.add(obj)
			else:
				# For every object found run loop
				for obj in foundObj:
					ColorSource = rs.ObjectColorSource(obj)
					# If color source is 0 (by layer), change to green 
					# If color source is something else, change to layer source
					if ColorSource == 0:
						rs.ObjectColor(obj, color=(117,255,127))
						self.previousHighlight.add(obj)
					else:
						rs.ObjectColorSource(obj, source=0)
						self.previousHighlight.discard(obj)

	# OK button click handler
	def OnOkButtonClick(self, sender, e):
		self.showPanel = 'Default'
		self.displayMainPanel()
		#self.m_selected_index = self.m_listbox.SelectedIndex
		#self.Close()
	
	# Cancel button click handler
	def OnCancelButtonClick(self, sender, e):
		self.Close()

	# Create button controls
	def CreateDefaultButtons(self):
		# 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.OnCancelButtonClick
		# Create button layout
		button_layout = forms.DynamicLayout()
		button_layout.Spacing = drawing.Size(5, 5)
		button_layout.AddRow(None, self.DefaultButton, self.AbortButton, None)
		return button_layout
	
	# Create button controls
	def CreateHighlightButton(self):
		# Create the highlight button
		self.HighlightButton = forms.Button(Text = 'Highlight')
		self.HighlightButton.Click += self.OnHighlightButtonClick
		# Create button layout
		button_layout = forms.DynamicLayout()
		button_layout.Spacing = drawing.Size(5, 5)
		button_layout.AddRow(None, self.HighlightButton, None)
		return button_layout

	# Atr button click handler
	def OnAtrButtonClick(self, sender, e):
		atrClass = sender.Tag 
		self.AssignAttributes(atrClass)
		self.showPanel = atrClass
		self.displayMainPanel()

	def AssignAttributes(self, atrClass):
		print 'Class: {}'.format(atrClass)
		PartNum = self.GetSelectedPartsGUIDs()[1]
		print 'PartNum',PartNum
		GUIDs = self.GetSelectedPartsGUIDs()[0]
		print 'GUIDs',GUIDs

	# Create button controls
	def CreateAtrButtons(self):
		# wood image icon
		image_btn_wood = forms.ImageView()
		image_btn_wood.Size = drawing.Size(50, 50)
		image_btn_wood.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_wood.png'))
		# angle image icon
		image_btn_angle = forms.ImageView()
		image_btn_angle.Size = drawing.Size(50, 50)
		image_btn_angle.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_angle.png'))
		# flatStock image icon
		image_btn_flatStock = forms.ImageView()
		image_btn_flatStock.Size = drawing.Size(50, 50)
		image_btn_flatStock.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_flatStock.png'))
		# tubeRect image icon
		image_btn_tubeRect = forms.ImageView()
		image_btn_tubeRect.Size = drawing.Size(50, 50)
		image_btn_tubeRect.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_tubeRect.png'))
		# tubeSquare image icon
		image_btn_tubeSquare = forms.ImageView()
		image_btn_tubeSquare.Size = drawing.Size(50, 50)
		image_btn_tubeSquare.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_tubeSquare.png'))
		# tubeRound image icon
		image_btn_tubeRound = forms.ImageView()
		image_btn_tubeRound.Size = drawing.Size(50, 50)
		image_btn_tubeRound.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_tubeRound.png'))


		# solidSquare image icon
		image_btn_solidSquare = forms.ImageView()
		image_btn_solidSquare.Size = drawing.Size(50, 50)
		image_btn_solidSquare.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_solidSquare.png'))
		# solidRound image icon
		image_btn_solidRound = forms.ImageView()
		image_btn_solidRound.Size = drawing.Size(50, 50)
		image_btn_solidRound.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_solidRound.png'))
		# solidHalf image icon
		image_btn_solidHalf = forms.ImageView()
		image_btn_solidHalf.Size = drawing.Size(50, 50)
		image_btn_solidHalf.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_solidHalf.png'))
		# mesh image icon
		image_btn_mesh = forms.ImageView()
		image_btn_mesh.Size = drawing.Size(50, 50)
		image_btn_mesh.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_mesh.png'))
		# pipe image icon
		image_btn_pipe = forms.ImageView()
		image_btn_pipe.Size = drawing.Size(50, 50)
		image_btn_pipe.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_pipe.png'))
		# tBar image icon
		image_btn_tBar = forms.ImageView()
		image_btn_tBar.Size = drawing.Size(50, 50)
		image_btn_tBar.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_tBar.png'))


		# iBeam image icon
		image_btn_iBeam = forms.ImageView()
		image_btn_iBeam.Size = drawing.Size(50, 50)
		image_btn_iBeam.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_iBeam.png'))
		# cChan image icon
		image_btn_cChan = forms.ImageView()
		image_btn_cChan.Size = drawing.Size(50, 50)
		image_btn_cChan.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_cChan.png'))
		# plate image icon
		image_btn_plate = forms.ImageView()
		image_btn_plate.Size = drawing.Size(50, 50)
		image_btn_plate.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_plate.png'))
		# cust image icon
		image_btn_cust = forms.ImageView()
		image_btn_cust.Size = drawing.Size(50, 50)
		image_btn_cust.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_cust.png'))
		# stock image icon
		image_btn_stock = forms.ImageView()
		image_btn_stock.Size = drawing.Size(50, 50)
		image_btn_stock.Image = drawing.Bitmap(os.path.join(dir, 'icons','btn_stock.png'))

		# Create button
		self.WoodButton = forms.Button(Text = 'Wood', Tag='000')
		self.WoodButton.Click += self.OnAtrButtonClick
		# Create button
		self.AngleButton = forms.Button(Text = 'Angle', Tag='100')
		self.AngleButton.Click += self.OnAtrButtonClick
		# Create button
		self.FlatStockButton = forms.Button(Text = 'Flat Stock', Tag='101')
		self.FlatStockButton.Click += self.OnAtrButtonClick
		# Create button
		self.TubeRectButton = forms.Button(Text = 'Tube Rect', Tag='102')
		self.TubeRectButton.Click += self.OnAtrButtonClick
		# Create button
		self.TubeSquareButton = forms.Button(Text = 'Tube Square', Tag='103')
		self.TubeSquareButton.Click += self.OnAtrButtonClick
		# Create button
		self.TubeRoundButton = forms.Button(Text = 'Tube Round', Tag='104')
		self.TubeRoundButton.Click += self.OnAtrButtonClick

		# Create button
		self.SolidSquareButton = forms.Button(Text = 'Solid Square', Tag='105')
		self.SolidSquareButton.Click += self.OnAtrButtonClick
		# Create button
		self.SolidRoundButton = forms.Button(Text = 'Solid Round', Tag='106')
		self.SolidRoundButton.Click += self.OnAtrButtonClick
		# Create button
		self.SolidHalfButton = forms.Button(Text = 'Half Round', Tag='107')
		self.SolidHalfButton.Click += self.OnAtrButtonClick
		# Create button
		self.MeshButton = forms.Button(Text = 'Mesh', Tag='108')
		self.MeshButton.Click += self.OnAtrButtonClick
		# Create button
		self.PipeButton = forms.Button(Text = 'Pipe', Tag='109')
		self.PipeButton.Click += self.OnAtrButtonClick
		# Create button
		self.TBarButton = forms.Button(Text = 'T-Bar', Tag='110')
		self.TBarButton.Click += self.OnAtrButtonClick

		# Create button
		self.IBeamButton = forms.Button(Text = 'I-Beam', Tag='111')
		self.IBeamButton.Click += self.OnAtrButtonClick
		# Create button
		self.CChanButton = forms.Button(Text = 'C-Channel', Tag='112')
		self.CChanButton.Click += self.OnAtrButtonClick
		# Create button
		self.PlateButton = forms.Button(Text = 'Plate', Tag='200')
		self.PlateButton.Click += self.OnAtrButtonClick
		# Create button
		self.CustButton = forms.Button(Text = 'Custom', Tag='300')
		self.CustButton.Click += self.OnAtrButtonClick
		# Create button
		self.StockButton = forms.Button(Text = 'Stock', Tag='400')
		self.StockButton.Click += self.OnAtrButtonClick


		# Create button layout
		atr_button_layout = forms.DynamicLayout()
		atr_button_layout.Spacing = drawing.Size(5, 5)
		atr_button_layout.Size = drawing.Size(550,300)
		atr_button_layout.AddRow(image_btn_wood, image_btn_angle, image_btn_flatStock, image_btn_tubeRect, image_btn_tubeSquare, image_btn_tubeRound)
		atr_button_layout.AddRow(self.WoodButton, self.AngleButton, self.FlatStockButton, self.TubeRectButton, self.TubeSquareButton, self.TubeRoundButton)
		atr_button_layout.AddRow(None, None, None, None, None, None)
		atr_button_layout.AddRow(None, None, None, None, None, None)
		atr_button_layout.AddRow(image_btn_solidSquare, image_btn_solidRound, image_btn_solidHalf, image_btn_mesh, image_btn_pipe, image_btn_tBar)
		atr_button_layout.AddRow(self.SolidSquareButton, self.SolidRoundButton, self.SolidHalfButton, self.MeshButton, self.PipeButton, self.TBarButton)
		atr_button_layout.AddRow(None, None, None, None, None, None)
		atr_button_layout.AddRow(None, None, None, None, None, None)
		atr_button_layout.AddRow(image_btn_iBeam, image_btn_cChan, image_btn_plate, image_btn_cust, image_btn_stock, None)
		atr_button_layout.AddRow(self.IBeamButton, self.CChanButton, self.PlateButton, self.CustButton, self.StockButton, None)
		atr_button_layout.AddRow(None, None, None, None, None, None)
		atr_button_layout.AddRow(None, None, None, None, None, None)
		return atr_button_layout


	# Find all objects with a beetle_PartNum partNum_key
	def findObjects(self):
		# Get all objects in file
		ids = rs.AllObjects(include_lights=False, include_grips=False)
		
		# Set some variables
		partNum_key = 'beetle_PartNum'
	
		PartNumAndGUIDs = {}
		# for every id given run part finding
		for id in ids:
			# Get partNum from every object
			partNumFound = rs.GetUserText(id, partNum_key, False)
			# If part number is not empty make a dictionary 
			if partNumFound != None:
				# Make a dictionary with part Number as Key and GUIDs as a list of values
				PartNumAndGUIDs.setdefault(partNumFound, []).append(id)
		
		# Return dictionary once loop is over
		return PartNumAndGUIDs

	def organizedKeys(self):
		self.mainDictionary = self.findObjects()
		# Get all keys from dictionary and organize them by numerical value
		organizedKeys = sorted(list(self.mainDictionary), key=int)
		organizedKeysAndQty = []
		for i, key in enumerate(organizedKeys):
			qty = len(self.mainDictionary.get(key))
			keyDigitLength = len(organizedKeys[i])
			if keyDigitLength == 1:
				text = '     {}  |  Qt: {}'.format(organizedKeys[i], qty)
				organizedKeysAndQty.append(text)
			elif keyDigitLength == 2:
				text = '   {}  |  Qt: {}'.format(organizedKeys[i], qty)
				organizedKeysAndQty.append(text)
			elif keyDigitLength == 3:
				text = ' {}  |  Qt: {}'.format(organizedKeys[i], qty)
				organizedKeysAndQty.append(text)
		return organizedKeysAndQty

	# Form Closed event handler
	def OnFormClosed(self, sender, e):
		# Remove the events added in the initializer
		#self.RemoveEvents()
		# Dispose of the form and remove it from the sticky dictionary
		if sc.sticky.has_key('attribute_form'):
			form = sc.sticky['attribute_form']
			if form:
				#form.Dispose()
				form = None
			sc.sticky.Remove('attribute_form')

################################################################################
# Creating a dialog instance and displaying the dialog.
################################################################################
def TestViAttributeForm():
	# See if the form is already visible
	if sc.sticky.has_key('attribute_form'):
		return
	
	# Create and show form
	form = viAttributeForm()
	form.Owner = Rhino.UI.RhinoEtoApp.MainWindow
	form.Show()
	# Add the form to the sticky dictionary so it
	# survives when the main function ends.
	sc.sticky['attribute_form'] = form


# 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__



	# For every organized key print guids
	#for key in organizedKeys:
		
	#	print 'Part #: {} | Qty: {} | GUIDs: {}'.format(key, len(mainDictionary.get(key)), mainDictionary.get(key))
	#return sorted(removeDup, key=int)

	TestViAttributeForm()

if __name__ == "__main__":
	RunCommand(True)

part of Initialize triggers displayMainPanel() which calls self.panelToShow()
It looks to see what self.showPanel is set to, and pull up a corresponding layout.
And that get’s triggered by OnAtrButtonClick().
So with a button press I am recalling the displayMainPanel()
at the start of the script I have self.showPanel set to a default value, and after OnAtrButtonClick() it changes it to something else. And OnOkButtonClick() I set that value back to default.

Hope it makes sense… :roll_eyes::thinking: