Input window idea

Hi, i look for some pyrevit function to create window for inputs. I look at py docs and i don’t see any fit to my script. (except the Tables but they are in “work in progress”) ( Effective Output/Input — pyRevit 4.5 documentation ). I want get inputs to add insulation to pipes. My idea is to have:

  1. window
    image
  2. save the last used int to avoid write them all the time
  3. reuse of previous parameter setup at the next use

Do you think it is posible and have sense to create such thing? Or better is to use only excel for integers? What function/packages could help in my goal? Thanks for help!

for a MVP, I would go this way _ not tested in half pseudo code / code:

config_in_pyrevit_config_ini = script.get_config()
pipes_insulation_type = revit.query.get_types_by_class(DB.Plumbing.PipeInsulationType)
pipes_types_selected = forms.SelectFromList.show(pipes_insulation_type, button_name='Select Pipe Insulation Type', multiselect=False, name_attr='Type Name')
pipes_picked = revit.pick_element_by_category('OST_Pipes')
for pipe in pipes_picked:
    insulation_thickness = forms.ask_for_number_slider('Select Pipe Insulation Thickness for {}'.format(pipe.Name), 0, 100, 1, 1) # pops for each pipe
    config_in_pyrevit_config_ini.set_attr( 'insulation thick': str(insulation_thickness) )
# then later something like this  to get the config back
config_in_pyrevit_config_ini.get_attr( #blah# )

2 Likes

or go the full flexform way: look at pyChilizer or EF-Tools set of UIs

1 Like

It’s possible :slight_smile:

1 Like

@Tomasz that is teasing!
you will need to share it now :smile_cat:

1 Like

Thanks for your attention. Ok so i know the options, thanks. @Tomasz for create this UI you used only pyrevit or you use some others packages? I saw the pyRevitMEP extension where .xaml was use but i though there is simpler way.@Jean-Marc helpfull as always :smiley:

1 Like

Hi,
I used only xaml (in Visual Studio → wpf app).
No packages required for this one as it’s hard to deploy dependencies to the others.
My tool is in modeless form - at the beginning don’t even try it :smiley: There is no way to debug it (or at least I’m not aware of it) and every mistake = revit crash.

There are some examples and samples in pyrevitMEP package.
and @eirannejad showed on youtube how to create some basic GUI.

1 Like

@PanPawel_1 and if you look at pyTiba or EF_tools extensions or pychilizer, there are plenty of examples for UI

Hi, thank you for your help! I finaly ended the script. There are few things to clean and add(like support other units apart from milimeters) but the script works.

import clr

import sys

import os

from rpw import revit,db

from rpw.ui.forms import TextInput

from Autodesk.Revit.UI.Selection import *

from Autodesk.Revit.DB import *

from pyrevit import DB, forms

doc = revit.doc

uidoc = revit.uidoc

## Class and def

class CustomISelectionFilter(ISelectionFilter):

    def __init__(self, nom_categorie):

        self.nom_categorie = nom_categorie

    def AllowElement(self, e):

        if e.Category.Name in self.nom_categorie:

        # if self.nom_categorie.Contains(e.Category.Name):

        #if e.Category.Name == self.nom_categorie:

            return True

        else:

            return False

    def AllowReference(self, ref, point):

        return true

def Pargetstr(element, name):

    return (element.GetParameters(name))[0].AsValueString()

## Picking elements

with forms.WarningBar(title="Pick elements in model[pipes/pipe fittings"):

    collector = uidoc.Selection.PickObjects(ObjectType.Element,CustomISelectionFilter("Pipes Pipe Fittings"))

filter1=ElementCategoryFilter(BuiltInCategory.OST_PipeInsulations)

ins_list=FilteredElementCollector(doc).OfClass(ElementType).WherePasses(filter1).ToElements()

ins_list_pins=[Element.Name.GetValue(i) for i in ins_list]

rops = forms.CommandSwitchWindow.show(ins_list_pins, message='Select Option',

recognize_access_key=False)

print(rops)

choosen_ins=ins_list[ins_list_pins.index(rops)]

print(choosen_ins)

## Get types of elements to ask for insulation thickness

elements=[]

elements_type=[]

dict={}

for i in collector:

    el=doc.GetElement(i.ElementId)

    elements.append(el)

    elements_type.append(el.Name)

    element_parameters=[]

    for p in el.Parameters:

        element_parameters.append(p.Definition.Name)

    print("=======")

    print(el.Category)

    print(el.Category.Name)

    print(el.Parameters)

   

    if el.Category.Name=="Pipes":

       

        dict.update({Pargetstr(el, "Family and Type") +" "

                    + str(el.Diameter*304.8):0})

    elif "Nominal Diameter 1" in element_parameters:

       

        dict.update({Pargetstr(el, "Family and Type") +" "

                + Pargetstr(el, "Nominal Diameter 1") +" "

                + Pargetstr(el, "Nominal Diameter 2"):0})

    else:

       

        dict.update({Pargetstr(el, "Family and Type") +" "

                    + Pargetstr(el, "Nominal Diameter"):0})

       

    del element_parameters[:]

print(element_parameters)

print(elements)

print(elements_type)

print(dict)

## Ask for insulation thickness

for key in dict:

    t=forms.ask_for_string(prompt='Select Insulation Thickness for {}'.format(key), title="Insulation")

    dict.update({key:t})

print(dict)

transaction = Transaction(doc, 'Transaction')

transaction.Start()

## Set insulation to pipes

for el in elements:

    try:

        for p in el.Parameters:

            element_parameters.append(p.Definition.Name)

       

        if el.Category.Name=="Pipes":

            t=float(dict[Pargetstr(el, "Family and Type") +" "

                    + str(el.Diameter*304.8)])/304.8

            Plumbing.PipeInsulation.Create(doc,el.Id,choosen_ins.Id,t)

            print("=====")

            print(Pargetstr(el, "Family and Type") +" "

                    + str(el.Diameter*304.8)+ " Id: " + str(el.Id))

            print("Insulation thicknes: {}").format(t*304.8)

        elif "Nominal Diameter 1" in element_parameters:

            t=float(dict[Pargetstr(el, "Family and Type") +" "

                + Pargetstr(el, "Nominal Diameter 1") +" "

                + Pargetstr(el, "Nominal Diameter 2")])/304.8

            Plumbing.PipeInsulation.Create(doc,el.Id,choosen_ins.Id,t)

            print("=====")

            print(Pargetstr(el, "Family and Type") +" "

                + Pargetstr(el, "Nominal Diameter 1") +" "

                + Pargetstr(el, "Nominal Diameter 2") + " Id: " + str(el.Id))

            print("Insulation thicknes: {}").format(t*304.8)

        else:

            t=float(dict[Pargetstr(el, "Family and Type") +" "

                    + Pargetstr(el, "Nominal Diameter")])/304.8

            Plumbing.PipeInsulation.Create(doc,el.Id,choosen_ins.Id,t)

            print("=====")

            print(Pargetstr(el, "Family and Type") +" "

                + Pargetstr(el, "Nominal Diameter") + " Id: " + str(el.Id))

            print("Insulation thicknes: {}").format(t*304.8)

        del element_parameters[:]

    except Exception as e:

        print(e)

        print("Error Element Id {}".format(el.Id))

transaction.Commit()

future reader! Next iterations you could get from: GitHub - PawelKinczyk/PYLAB: Python for Revit by using PyRevit extension