Hello! Friends, I have two comboboxes. I would like the second drop-down list to change depending on the choice of value in the first. The selection of dropdown lists is in one function. How can we make the code understand that having selected a value in the first list, we need to select another or change the list of the second combobox? I was told that for this it is necessary to launch an event for the combobox, but how to implement this technically?
import clr
import sys
import System
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *
clr.AddReference('RevitAPI')
import Autodesk.Revit.DB as DB
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
clr.AddReference('DSCoreNodes')
import DSCore
from System.Collections.Generic import List
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
doc = DocumentManager.Instance.CurrentDBDocument
from collections import namedtuple
def CatElemTypes(name):
cats = doc.Settings.Categories
catsN = sorted([c.Name for c in cats])
c1 = [i for i in cats if i.Name == name][0]
bc1 = System.Enum.ToObject(DB.BuiltInCategory, c1.Id.IntegerValue)
bc1el = DB.FilteredElementCollector(doc).OfCategory(bc1).WhereElementIsElementType().ToElements()
return bc1el
def Cats(name):
cats = doc.Settings.Categories
catsN = sorted([c.Name for c in cats])
c1 = [i for i in cats if i.Name == name][0]
return c1
class MyItem():
def __init__(self, key, value):
self.Key = key
self.Value = value
list_cats = ['Walls','Doors','Windows','Rooms','Floors','Ceilings','Structural Columns']
list_cats1 = [Cats(i).Name for i in list_cats]
list_cats2 = [1,2,3,4,5,6,7]
list_params = ['Type Name','Type Comments','Description','Type Mark','Width','Height','Sill Height','Base Offset','Unconnected Height','Top Offset','Default Thickness','Height Offset','Family Name','Limit Offset','Wall Finish']
list_params1 = [1,2,3,4,5,6,7,9,10,11,12,13,17,18,20]
if list_cats2==1:
list_params1 = [1,2,3,4,5,9,10,11]
list_ravno = ['<','=','>']
list_ravno1 = [0,1,2]
list_of_items_cats = [MyItem(i,j) for i,j in zip(list_cats1,list_cats2)]
list_of_items_params = [MyItem(i,j) for i,j in zip(list_params,list_params1)]
list_of_items_ravno = [MyItem(i,j) for i,j in zip(list_ravno,list_ravno1)]
OUT = list_params
class MainForm(Form):
def __init__(self):
self.out = []
self.choice = None
self.InitializeComponent()
def InitializeComponent(self):
self.FormBorderStyle = FormBorderStyle.FixedDialog ##Remove the maximize box.
self.MaximizeBox = False ## Set the MinimizeBox to false to remove the minimize box.
self.MinimizeBox = False ## Set the accept button of the form to button1.
self.StartPosition = FormStartPosition.CenterScreen
self.AutoScroll = False
self.ScrollBars = ScrollBars.Vertical
self.ClientSize = System.Drawing.Size(500, 235)
self.Name = "Title"#"Вихідні дані"
self.Text = "Title"#"Вихідні дані"
self.ResumeLayout(True)
#
self._label1 = System.Windows.Forms.Label()
self._label2 = System.Windows.Forms.Label()
self._label3 = System.Windows.Forms.Label()
self._label4 = System.Windows.Forms.Label()
self._label5 = System.Windows.Forms.Label()
self._checkBox1 = System.Windows.Forms.CheckBox()
#
self._label1.Location = System.Drawing.Point(20, 25)
self._label1.Name = "label1"
self._label1.Size = System.Drawing.Size(250, 23)
self._label1.TabIndex = 1
self._label1.Text = "Select Category"#"Виберіть категорію"
self._label1.Font = System.Drawing.Font("Tahoma", 16, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
#
self._label2.Location = System.Drawing.Point(20, 60)
self._label2.Name = "label2"
self._label2.Size = System.Drawing.Size(250, 23)
self._label2.TabIndex = 1
self._label2.Text = "Select Parameter"#"Виберіть параметр"
self._label2.Font = System.Drawing.Font("Tahoma", 16, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
#
self._label3.Location = System.Drawing.Point(20, 95)
self._label3.Name = "label3"
self._label3.Size = System.Drawing.Size(250, 23)
self._label3.TabIndex = 1
self._label3.Text = "Value"#"Введіть дані"
self._label3.Font = System.Drawing.Font("Tahoma", 16, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
#
self._label4.Location = System.Drawing.Point(20, 130)
self._label4.Name = "label4"
self._label4.Size = System.Drawing.Size(250, 23)
self._label4.TabIndex = 1
self._label4.Text = "Equals/Contains"#"Дорівнює/Включає"
self._label4.Font = System.Drawing.Font("Tahoma", 16, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
#
self._label5.Location = System.Drawing.Point(20, 165)
self._label5.Name = "label5"
self._label5.Size = System.Drawing.Size(100, 23)
self._label5.TabIndex = 1
self._label5.Text = "<,=,>"
self._label5.Font = System.Drawing.Font("Tahoma", 16, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
#
self._comboBoxType = System.Windows.Forms.ComboBox()
self.Controls.Add(self._comboBoxType) # move to here
self._comboBoxType.Location = System.Drawing.Point(280, 25)
self._comboBoxType.Size = System.Drawing.Size(200, 20)
self._comboBoxType.DataSource = list_of_items_cats
self._comboBoxType.DisplayMember = "Key"
self._comboBoxType.ValueMember = "Value"
self._comboBoxType.SelectedIndex = 0 # added
#self._comboBoxType.SelectedIndexChanged += self.ComboBox1SelectedIndexChanged
self._comboBoxType.Font = System.Drawing.Font("Tahoma", 14, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
#
self._cb = System.Windows.Forms.ComboBox()
self.Controls.Add(self._cb) # move to here
self._cb.Location = System.Drawing.Point(280, 60)
self._cb.Size = System.Drawing.Size(200, 20)
self._cb.DataSource = list_of_items_params
self._cb.DisplayMember = "Key"
self._cb.ValueMember = "Value"
self._cb.SelectedIndex = 0 # added
#self._cb.SelectedIndexChanged += self.ComboBox1SelectedIndexChanged
self._cb.Font = System.Drawing.Font("Tahoma", 14, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
#
self._text_value = System.Windows.Forms.TextBox()
self._text_value.Location = System.Drawing.Point(280, 95)
self._text_value.Name = "Значення"
self._text_value.Text = ""
self._text_value.Size = System.Drawing.Size(200, 20)
self._text_value.Font = System.Drawing.Font("Tahoma", 14, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
#
self._checkBox1.Name = "checkBox1"
self._checkBox1.Location = System.Drawing.Point(380, 130)
self._checkBox1.Size = System.Drawing.Size(30, 30)
self._checkBox1.TabIndex = 0
self._checkBox1.UseVisualStyleBackColor = True
#self._checkBoxSelectAll.CheckedChanged += self.CheckBoxSelectChecked
#
self._cb1 = System.Windows.Forms.ComboBox()
self.Controls.Add(self._cb1) # move to here
self._cb1.Location = System.Drawing.Point(380, 165)
self._cb1.Size = System.Drawing.Size(100, 20)
self._cb1.DataSource = list_of_items_ravno
self._cb1.DisplayMember = "Key"
self._cb1.ValueMember = "Value"
self._cb1.SelectedIndex = 1 # added #вибирає який по порядку елемент з'являється
#self._cb1.SelectedIndexChanged += self.ComboBox1SelectedIndexChanged
self._cb1.Font = System.Drawing.Font("Tahoma", 14, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
#
self.button = System.Windows.Forms.Button()
self.button.Text = 'Next'
self.button.Location = Point(170,180)
self.button.Width = 150
self.button.Height = 35
self.button.Click += self.button_click
self.button.Font = System.Drawing.Font("Tahoma", 14, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
#
self.Controls.Add(self._label1)
self.Controls.Add(self._label2)
self.Controls.Add(self._label3)
self.Controls.Add(self._label4)
self.Controls.Add(self._label5)
self.Controls.Add(self._text_value)
self.Controls.Add(self._checkBox1)
self.Controls.Add(self.button)
#def ComboBox1SelectedIndexChanged(self, sender, e):
#self.choice = sender.SelectedItem.Value
def button_click(self, sender, event):
self.out.append(self._comboBoxType.SelectedItem.Value)
self.out.append(self._cb.SelectedItem.Value)
self.out.append(self._text_value.Text)
self.out.append(self._checkBox1.CheckState)
self.out.append(self._cb1.SelectedItem.Value)
self.Close()
objForm = MainForm()
objForm.ShowDialog()
result = [objForm.out[0],objForm.out[1],objForm.out[2],objForm.out[3].value__,objForm.out[4]]
OUT = result