#############-------------\-------------#############
#My Default Boiler Plate
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import Selection
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import math
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#############-------------\-------------#############
#UI additional references
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import System
from System.Windows.Forms import *
from System.Drawing import *
import webbrowser #needed to open a url
import System.IO #needed to be able to open a pdf
#from System.Windows.Forms import *
#############-------------\-------------#############
#INPUTS HERE:
listInput1 =tuple(IN[1]) #Combo box requires tuple not list input
listInput2 =tuple(IN[2]) #Combo box requires tuple not list input
listInput3 =tuple(IN[3]) #Combo box requires tuple not list input
linkaddress = IN[4]
logoFile = IN[5]
icon = IN[6]
logoFileB = IN[7]
logoFileC = IN[8]
logoFileD = IN[9]
outA=[]
userOutputDefaultStr = "No selection made, Re-run, and select an item from the dropdown menu" #set default output values for the GUI, that assume form has not run.
# create a instance of the form class called DropDownform.
#In Winforms, any window or a dialog is a Form.
class DropDownForm(Form):
def __init__(self):
self.Text = "Higway Data"
self.Icon = Icon.FromHandle(icon.GetHicon())
self.BackColor = Color.FromArgb(255, 255, 255)
self.WindowState = FormWindowState.Normal
self.CenterToScreen()
self.BringToFront()
self.Topmost = True
screenSize = Screen.GetWorkingArea(self)
self.Width = 550
self.Height = 280
uiWidth = 500
uiHeight = 280
self.FormBorderStyle = FormBorderStyle.FixedDialog
self.userOutput = userOutputDefaultStr
self.runNextOutput = False
#############-------------\-------------#############
spacing = 10 #spacing size for GUI elements to form a consistent border
#creates the text box for a info message
userMessage = Label() #label displays texts
font = Font("Helvetica ", 10)
userMessage.Text = "Select Highway Profile Schedule"
userMessage.Font = font
userMessage.Location = Point(10, 10) #all location require a point object from system.Drawing to set the location.
userMessage.Size = Size(250,20) #size the control with the width of the GUI to ensure it scales with different screen
self.Controls.Add(userMessage) #this adds control element to the GUI
# creates the text box for a info message
userMessage2 = Label() #label displays texts
font = Font("Helvetica ", 10)
userMessage2.Text = "Select Alignment Layer Name"
userMessage2.Font = font
userMessage2.Location = Point(10, 85) #all location require a point object from system.Drawing to set the location.
userMessage2.Size = Size(250,20) #size the control with the width of the GUI to ensure it scales with different screen
self.Controls.Add(userMessage2) #this adds control element to the GUI
# creates the text box for a info message
userMessage3 = Label() #label displays texts
font = Font("Helvetica ", 8)
userMessage3.Text = "Start Station"
userMessage3.Font = font
userMessage3.Location = Point(10, 160) #all location require a point object from system.Drawing to set the location.
userMessage3.Size = Size(70,20) #size the control with the width of the GUI to ensure it scales with different screen
self.Controls.Add(userMessage3) #this adds control element to the GUI
# creates the text box for a info message
userMessage4 = Label() #label displays texts
font = Font("Helvetica ", 8)
userMessage4.Text = "Number Of Spans"
userMessage4.Font = font
userMessage4.Location = Point(120, 160) #all location require a point object from system.Drawing to set the location.
userMessage4.Size = Size(100,20) #size the control with the width of the GUI to ensure it scales with different screen
self.Controls.Add(userMessage4) #this adds control element to the GUI
userMessage5 = Label() #label displays texts
font = Font("Helvetica ", 8)
userMessage5.Text = "Span Length"
userMessage5.Font = font
userMessage5.Location = Point(230, 160) #all location require a point object from system.Drawing to set the location.
userMessage5.Size = Size(100,20) #size the control with the width of the GUI to ensure it scales with different screen
self.Controls.Add(userMessage5) #this adds control element to the GUI
#############-------------\-------------#############
#--------------------------------------logo file--------------------------------------##
self.PictureBox = PictureBox()
self.PictureBox.SizeMode = PictureBoxSizeMode.CenterImage
self.PictureBox.Image = logoFileB
self.PictureBox.Location = Point(350, 20)
self.PictureBox.Size = Size(170, 170)
self.Controls.Add(self.PictureBox)
#############-------------\-------------#############
#combox drop down
cBox = ComboBox() #dropdown control form
cBox.Location = Point(10, 30)
cBox.Width = (320)
cBox.Items.AddRange(listInput1) # Adds an array of items to the list of items for a ComboBox.
cBox.DropDownStyle = ComboBoxStyle.DropDownList #setting to dropdown list prevents users from being able to add aditional text values
cBox.SelectedIndexChanged += self.dropDownOutput #.Click+= registers the press of the button to register the event handler and determine what action takes place when button clicked
self.Controls.Add(cBox)
#combox drop down
cBox2 = ComboBox() #dropdown control form
cBox2.Location = Point(10, 105)
cBox2.Width = (320)
cBox2.Items.AddRange(listInput2) # Adds an array of items to the list of items for a ComboBox.
cBox2.DropDownStyle = ComboBoxStyle.DropDownList #setting to dropdown list prevents users from being able to add aditional text values
cBox2.SelectedIndexChanged += self.dropDownOutput #.Click+= registers the press of the button to register the event handler and determine what action takes place when button clicked
self.Controls.Add(cBox2)
self.tbox1 = TextBox()
self.tbox1.Parent = self
self.tbox1.Text = "0"
self.tbox1.Location = Point(10,180)
self.tbox1.Width = 100
self.tbox2 = TextBox()
self.tbox2.Parent = self
self.tbox2.Text = "0"
self.tbox2.Location = Point(120,180)
self.tbox2.Width = 100
self.tbox3 = TextBox()
self.tbox3.Parent = self
self.tbox3.Text = "0"
self.tbox3.Location = Point(230,180)
self.tbox3.Width = 100
#############-------------\-------------#############
#Create ok button
btnOk = Button() #create a button control
btnOk.Text = "Next"
btnOk.Location = Point(375,210)
btnOk.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right)
btnOk.Click += self.okButtonPressed #Register the event on the button bress to trigger the def okButtonPressed
self.Controls.Add(btnOk)
#Create Cancel Button
btnCancel = Button()
#btnCancel.Parent = self
btnCancel.Text = "Cancel"
btnCancel.Location = Point(450,210)
btnCancel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right)
btnCancel.Click += self.CnlButtonPressed
self.Controls.Add(btnCancel)
#############-------------\-------------#############
#Create a weblink
helplink = LinkLabel()
helplink.Text = "User Guide"
helplink.Tag = linkaddress #tag is the web address
helplink.Click += self.openLink #register click event with event handler
helplink.Location = Point(300,210)
self.Controls.Add(helplink)
helplink.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left)
#----------------------------Panal Color---------------------------####
#######---------------------------------------------------------------------------------------#############
#when a user selects a item in the drop down the dropDownOutput method is called.
def dropDownOutput(self, sender, args):
#self is the instance of the GUI form. Sender is the control/widget. args is the argument/event provided from the control
self.userOutput = sender.SelectedItem
outA.append(self.userOutput)
#outA.append(self.userOutput)
#outA.append(self.userOutput) #output the selected item.
#when a user selects a item in the drop down the dropDownOutput method is called.
def okButtonPressed(self, sender, args):
self.Close()
self.runNextOutput = True
def CnlButtonPressed(self, sender, args):
self.Close()
self.runNextOutput = False
def openLink(self, sender, event):
webbrowser.open(sender.Tag) #open a weblink
self.Close()
self.runNextOutput = False
ddForm = DropDownForm()
if IN[0]:
Application.Run(ddForm)
OUT = outA
2 Likes
Hello,
Can you explain better your problem? (with detail, screenshot, etc…)
2 Likes