|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from mailbox import Message |
| 3 | + |
| 4 | +import clr |
| 5 | +import System |
| 6 | +import string |
| 7 | +from rpw.ui.forms import Alert |
| 8 | + |
| 9 | +from SubForm import * |
| 10 | + |
| 11 | +# Importing necessary references for Revit and Windows Forms |
| 12 | +clr.AddReference("RevitServices") |
| 13 | +import RevitServices |
| 14 | +from RevitServices.Persistence import DocumentManager |
| 15 | +from RevitServices.Transactions import TransactionManager |
| 16 | + |
| 17 | +clr.AddReference("RevitNodes") |
| 18 | +import Revit |
| 19 | + |
| 20 | +clr.ImportExtensions(Revit.Elements) |
| 21 | +clr.ImportExtensions(Revit.GeometryConversion) |
| 22 | + |
| 23 | +clr.AddReference("RevitAPIUI") |
| 24 | +from Autodesk.Revit.UI import * |
| 25 | + |
| 26 | +clr.AddReference('RevitAPI') |
| 27 | +from Autodesk.Revit.DB import * |
| 28 | + |
| 29 | +clr.AddReference('System.Windows.Forms') |
| 30 | +clr.AddReference('System.Drawing') |
| 31 | + |
| 32 | +import System.Drawing |
| 33 | +import System.Windows.Forms |
| 34 | +import os |
| 35 | +from System.Drawing import Icon # Import Icon class |
| 36 | +import System.Diagnostics # Open Link when press Button |
| 37 | + |
| 38 | +from System.Drawing import * |
| 39 | +from System.Windows.Forms import * |
| 40 | + |
| 41 | +# Adding a reference to the system to use List |
| 42 | +clr.AddReference('System') |
| 43 | +from System.Collections.Generic import List |
| 44 | + |
| 45 | +"""---------------------------Get active document and view from Revit------------------------""" |
| 46 | +doc = __revit__.ActiveUIDocument.Document |
| 47 | +view = doc.ActiveView |
| 48 | +uidoc = __revit__.ActiveUIDocument |
| 49 | +"""-------------------------------------------------------------------------------------------""" |
| 50 | +comboLst = ["None"] |
| 51 | + |
| 52 | +# Main form class |
| 53 | +class MainForm(Form): |
| 54 | + def __init__(self, nameModel): |
| 55 | + self.nameModel = nameModel |
| 56 | + self.InitializeComponent() |
| 57 | + |
| 58 | + def InitializeComponent(self): |
| 59 | + # Get the directory of the running script |
| 60 | + script_dir = os.path.dirname(__file__) |
| 61 | + |
| 62 | + icon_path = os.path.join(script_dir, "icon.ico") |
| 63 | + |
| 64 | + # Load custom icon (if available) |
| 65 | + if os.path.exists(icon_path): |
| 66 | + self.Icon = Icon(icon_path) |
| 67 | + |
| 68 | + # Initialize components |
| 69 | + self._groupBox1 = System.Windows.Forms.GroupBox() |
| 70 | + self._comboBox1 = System.Windows.Forms.ComboBox() |
| 71 | + self._label1 = System.Windows.Forms.Label() |
| 72 | + self._label2 = System.Windows.Forms.Label() |
| 73 | + self._textBox1 = System.Windows.Forms.TextBox() |
| 74 | + self._okBtn = System.Windows.Forms.Button() |
| 75 | + self._cancelBtn = System.Windows.Forms.Button() |
| 76 | + self._linkLabel1 = System.Windows.Forms.LinkLabel() |
| 77 | + self._linkBtn = System.Windows.Forms.RadioButton() |
| 78 | + self._modelBtn = System.Windows.Forms.RadioButton() |
| 79 | + self._label3 = System.Windows.Forms.Label() |
| 80 | + self._groupBox1.SuspendLayout() |
| 81 | + self.SuspendLayout() |
| 82 | + # |
| 83 | + # groupBox1 |
| 84 | + # |
| 85 | + self._groupBox1.Controls.Add(self._label3) |
| 86 | + self._groupBox1.Controls.Add(self._textBox1) |
| 87 | + self._groupBox1.Controls.Add(self._label1) |
| 88 | + self._groupBox1.Controls.Add(self._label2) |
| 89 | + self._groupBox1.Controls.Add(self._comboBox1) |
| 90 | + self._groupBox1.Location = System.Drawing.Point(12, 12) |
| 91 | + self._groupBox1.Name = "groupBox1" |
| 92 | + self._groupBox1.Size = System.Drawing.Size(490, 137) |
| 93 | + self._groupBox1.TabIndex = 0 |
| 94 | + self._groupBox1.TabStop = False |
| 95 | + self._groupBox1.Text = "Data" |
| 96 | + # |
| 97 | + # comboBox1 |
| 98 | + # |
| 99 | + self._comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList |
| 100 | + self._comboBox1.FormattingEnabled = True |
| 101 | + self._comboBox1.Location = System.Drawing.Point(141, 60) |
| 102 | + self._comboBox1.Name = "comboBox1" |
| 103 | + self._comboBox1.Size = System.Drawing.Size(343, 21) |
| 104 | + self._comboBox1.Items.AddRange(System.Array[System.Object](comboLst)) |
| 105 | + self._comboBox1.SelectedIndex = 0 |
| 106 | + self._comboBox1.TabIndex = 0 |
| 107 | + self._comboBox1.SelectedIndexChanged += self.ComboBox1SelectedIndexChanged |
| 108 | + # |
| 109 | + # label1 |
| 110 | + # |
| 111 | + self._label1.Location = System.Drawing.Point(6, 60) |
| 112 | + self._label1.Name = "label1" |
| 113 | + self._label1.Size = System.Drawing.Size(129, 23) |
| 114 | + self._label1.TabIndex = 1 |
| 115 | + self._label1.Text = "Select Linked Model" |
| 116 | + # |
| 117 | + # label2 |
| 118 | + # |
| 119 | + self._label2.Location = System.Drawing.Point(6, 31) |
| 120 | + self._label2.Name = "label2" |
| 121 | + self._label2.Size = System.Drawing.Size(129, 23) |
| 122 | + self._label2.TabIndex = 1 |
| 123 | + self._label2.Text = "Type ID to Find" |
| 124 | + # |
| 125 | + # textBox1 |
| 126 | + # |
| 127 | + self._textBox1.Location = System.Drawing.Point(141, 28) |
| 128 | + self._textBox1.Name = "textBox1" |
| 129 | + self._textBox1.Size = System.Drawing.Size(343, 20) |
| 130 | + self._textBox1.TabIndex = 2 |
| 131 | + self._textBox1.TextChanged += self.TextBox1TextChanged |
| 132 | + # |
| 133 | + # okBtn |
| 134 | + # |
| 135 | + self._okBtn.Font = System.Drawing.Font("Microsoft Sans Serif", 10, System.Drawing.FontStyle.Regular, |
| 136 | + System.Drawing.GraphicsUnit.Point, 0) |
| 137 | + self._okBtn.Location = System.Drawing.Point(14, 155) |
| 138 | + self._okBtn.Name = "okBtn" |
| 139 | + self._okBtn.Size = System.Drawing.Size(97, 38) |
| 140 | + self._okBtn.TabIndex = 1 |
| 141 | + self._okBtn.Text = "Find" |
| 142 | + self._okBtn.UseVisualStyleBackColor = True |
| 143 | + self._okBtn.Click += self.OkBtnClick |
| 144 | + # |
| 145 | + # cancelBtn |
| 146 | + # |
| 147 | + self._cancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel |
| 148 | + self._cancelBtn.Font = System.Drawing.Font("Microsoft Sans Serif", 10, System.Drawing.FontStyle.Regular, |
| 149 | + System.Drawing.GraphicsUnit.Point, 0) |
| 150 | + self._cancelBtn.Location = System.Drawing.Point(141, 155) |
| 151 | + self._cancelBtn.Name = "cancelBtn" |
| 152 | + self._cancelBtn.Size = System.Drawing.Size(97, 38) |
| 153 | + self._cancelBtn.TabIndex = 1 |
| 154 | + self._cancelBtn.Text = "Cancel" |
| 155 | + self._cancelBtn.UseVisualStyleBackColor = True |
| 156 | + self._cancelBtn.Click += self.CancelBtnClick |
| 157 | + # |
| 158 | + # linkLabel1 |
| 159 | + # |
| 160 | + self._linkLabel1.Font = System.Drawing.Font("Microsoft Sans Serif", 9, System.Drawing.FontStyle.Italic, |
| 161 | + System.Drawing.GraphicsUnit.Point, 0) |
| 162 | + self._linkLabel1.Location = System.Drawing.Point(21, 209) |
| 163 | + self._linkLabel1.Name = "linkLabel1" |
| 164 | + self._linkLabel1.Size = System.Drawing.Size(140, 40) |
| 165 | + self._linkLabel1.TabIndex = 2 |
| 166 | + self._linkLabel1.TabStop = True |
| 167 | + self._linkLabel1.Text = "Help" |
| 168 | + self._linkLabel1.LinkClicked += self.LinkLabel1LinkClicked |
| 169 | + # |
| 170 | + # linkBtn |
| 171 | + # |
| 172 | + |
| 173 | + self._linkBtn.Font = System.Drawing.Font("Microsoft Sans Serif", 10, System.Drawing.FontStyle.Regular, |
| 174 | + System.Drawing.GraphicsUnit.Point, 0) |
| 175 | + self._linkBtn.Location = System.Drawing.Point(274, 159) |
| 176 | + self._linkBtn.Name = "linkBtn" |
| 177 | + self._linkBtn.Size = System.Drawing.Size(111, 31) |
| 178 | + self._linkBtn.TabIndex = 3 |
| 179 | + |
| 180 | + self._linkBtn.Text = "Link File" |
| 181 | + self._linkBtn.UseVisualStyleBackColor = True |
| 182 | + self._linkBtn.CheckedChanged += self.LinkBtnCheckedChanged |
| 183 | + # |
| 184 | + # modelBtn |
| 185 | + # |
| 186 | + self._modelBtn.Checked = True |
| 187 | + self._modelBtn.Font = System.Drawing.Font("Microsoft Sans Serif", 10, System.Drawing.FontStyle.Regular, |
| 188 | + System.Drawing.GraphicsUnit.Point, 0) |
| 189 | + self._modelBtn.Location = System.Drawing.Point(391, 159) |
| 190 | + self._modelBtn.Name = "modelBtn" |
| 191 | + self._modelBtn.Size = System.Drawing.Size(111, 31) |
| 192 | + self._modelBtn.TabIndex = 3 |
| 193 | + self._modelBtn.TabStop = True |
| 194 | + self._modelBtn.Text = "In Model" |
| 195 | + self._modelBtn.UseVisualStyleBackColor = True |
| 196 | + self._modelBtn.CheckedChanged += self.ModelBtnCheckedChanged |
| 197 | + # |
| 198 | + # label3 |
| 199 | + # |
| 200 | + self._label3.Font = System.Drawing.Font("Microsoft Sans Serif", 9, System.Drawing.FontStyle.Regular, |
| 201 | + System.Drawing.GraphicsUnit.Point, 0) |
| 202 | + self._label3.Location = System.Drawing.Point(141, 103) |
| 203 | + self._label3.Name = "label3" |
| 204 | + self._label3.Size = System.Drawing.Size(343, 17) |
| 205 | + self._label3.TabIndex = 3 |
| 206 | + self._label3.Text = '*ID need to be fiiled and can be separated by comma ","' |
| 207 | + # |
| 208 | + # MainForm |
| 209 | + # |
| 210 | + self.AcceptButton = self._okBtn |
| 211 | + self.CancelButton = self._cancelBtn |
| 212 | + self.ClientSize = System.Drawing.Size(515, 236) |
| 213 | + self.Controls.Add(self._modelBtn) |
| 214 | + self.Controls.Add(self._linkBtn) |
| 215 | + self.Controls.Add(self._linkLabel1) |
| 216 | + self.Controls.Add(self._cancelBtn) |
| 217 | + self.Controls.Add(self._okBtn) |
| 218 | + self.Controls.Add(self._groupBox1) |
| 219 | + self.HelpButton = True |
| 220 | + self.MaximumSize = System.Drawing.Size(530, 275) |
| 221 | + self.MinimumSize = System.Drawing.Size(530, 275) |
| 222 | + self.Name = "MainForm" |
| 223 | + self.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent |
| 224 | + self.Text = "Finding Element by ID" |
| 225 | + self._groupBox1.ResumeLayout(False) |
| 226 | + self._groupBox1.PerformLayout() |
| 227 | + self.ResumeLayout(False) |
| 228 | + |
| 229 | + def TextBox1TextChanged(self, sender, e): |
| 230 | + pass |
| 231 | + |
| 232 | + def ComboBox1SelectedIndexChanged(self, sender, e): |
| 233 | + pass |
| 234 | + |
| 235 | + def OkBtnClick(self, sender, e): |
| 236 | + lstId = self._textBox1.Text.strip() |
| 237 | + |
| 238 | + try: |
| 239 | + # Check List Id is empty or not |
| 240 | + if not lstId: |
| 241 | + ShowNotification("Warning", "Please enter a valid ID.") |
| 242 | + return |
| 243 | + |
| 244 | + # Check Id is valid or not |
| 245 | + id = [int(id.strip()) for id in lstId.split(",") if id.strip().isdigit()] |
| 246 | + if not id: |
| 247 | + ShowNotification("Warning", "Vui lòng nhập ít nhất một ID hợp lệ.") |
| 248 | + return |
| 249 | + |
| 250 | + # Check ComboList is valid or not |
| 251 | + if self._comboBox1.SelectedIndex < 0: |
| 252 | + ShowNotification("Warning", "Vui lòng chọn một mô hình từ danh sách.") |
| 253 | + return |
| 254 | + |
| 255 | + # Save and close form |
| 256 | + self.DialogResult = System.Windows.Forms.DialogResult.OK |
| 257 | + self.Close() |
| 258 | + |
| 259 | + |
| 260 | + |
| 261 | + except Exception as ex: |
| 262 | + ShowNotification("Error", "An error occurred: {}".format(ex)) |
| 263 | + |
| 264 | + def CancelBtnClick(self, sender, e): |
| 265 | + self.Close() |
| 266 | + |
| 267 | + def LinkLabel1LinkClicked(self, sender, e): |
| 268 | + System.Diagnostics.Process.Start("https://www.youtube.com/@paper.engineer") |
| 269 | + |
| 270 | + def LinkBtnCheckedChanged(self, sender, e): |
| 271 | + self._comboBox1.Items.Clear() |
| 272 | + self._comboBox1.Items.AddRange(System.Array[System.Object](self.nameModel)) |
| 273 | + self._comboBox1.SelectedIndex = 0 |
| 274 | + |
| 275 | + def ModelBtnCheckedChanged(self, sender, e): |
| 276 | + self._comboBox1.Items.Clear() |
| 277 | + self._comboBox1.Items.AddRange(System.Array[System.Object](comboLst)) |
| 278 | + self._comboBox1.SelectedIndex = 0 |
0 commit comments