# Setting wall parameters using WPF

**URL:** <https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005>\
**Category:** Developers\
**Tags:** python\
**Created:** [October 9, 2024, 8:03am UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005 "2024-10-09T08:03:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [October 9, 2024, 8:03am UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/1 "2024-10-09T08:03:33Z")

</div>

Hi All, @c.poupin

I’m using [pyrevit](https://discourse.pyrevitlabs.io/) and trying to modify the `Unconnected Wall Height` parameter for the selected walls using a WPF window as shown below, but I’m receiving the error message handled by the `except` block in my code as shown below.  
I believe this issue is related to the **input type** for the `Value` label, which likely needs to be defined as a `Double` in either the **xaml file** or the **[pyrevit](https://discourse.pyrevitlabs.io/) script** , but I’m unsure how to set it?

 ![value_error](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/5/f5e2ae47cc7eb330b6475ab932952d87dc370b1c.png)

Please check my [pyrevit](https://discourse.pyrevitlabs.io/) and xaml scripts attached below:

> **My\_tool**
>
> ````auto
> # -*- coding: UTF-8 -*-
> import Autodesk
> from Autodesk.Revit.DB import *
> from Autodesk.Revit.UI import *
> from pyrevit.forms import WPFWindow
> 
> doc = __revit__.ActiveUIDocument.Document
> uidoc = __revit__.ActiveUIDocument
> 
> class ModalForm(WPFWindow):
> def __init__ (self, xaml_file_name):
> WPFWindow. __init__ (self, xaml_file_name)
> self.ShowDialog()
> def select_push_button(self, sender, e):
> self.hide()
> sel = uidoc.Selection.PickObjects(Selection.ObjectType.Element, 'Choose elements')
> self.els = [doc.GetElement(elId) for elId in sel]
> self.ShowDialog()
> 
> def ok_push_button(self, sender, e):
> param_name = self.Text_input.Text
> param_value = self.Value_input.Text
> 
> t = Transaction(doc, 'Change parameter')
> t.Start()
> try:
> for i in self.els:
> i.LookupParameter(param_name).Set(UnitUtils.ConvertToInternalUnits(param_value, UnitTypeId.Meters))
> except:
> TaskDialog.Show('error', 'error message')
> t.Commit()
> self.Close()
> 
> def cancel_button(self, sender, e):
> self.Close()
> 
> form = ModalForm('interface.xaml')```
> 
> ````

> **xaml**
>
> ```auto
> <?xml version="1.0" encoding="utf-8"?>
> <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> Title="regard"
> Height="300"
> Width="300">
> <Grid>
> <Button
> Grid.Column="0"
> Grid.Row="0"
> VerticalAlignment="Bottom"
> Height="25"
> Width="75"
> HorizontalAlignment="Left"
> Margin="20,0,0,15"
> x:Name="ok_button"
> Click="ok_push_button"
> Content="ok" />
> <Button
> Grid.Column="0"
> Grid.Row="0"
> VerticalAlignment="Bottom"
> Width="75"
> HorizontalAlignment="Right"
> Height="25"
> Margin="0,0,107,15"
> x:Name="Select_button"
> Click="select_push_button"
> Content="Select" />
> <Button
> Grid.Column="0"
> Grid.Row="0"
> HorizontalAlignment="Left"
> VerticalAlignment="Bottom"
> Width="75"
> Margin="195,0,0,15"
> Height="25"
> x:Name="Cancel_button"
> Click="cancel_button"
> Content="Cancel" />
> <Label
> Content="Parameter Name"
> Height="25"
> Width="100"
> Margin="25,40,0,0"
> VerticalAlignment="Top"
> HorizontalAlignment="Left"
> Grid.Row="0"
> Grid.Column="0" />
> <TextBox
> Grid.Column="0"
> Grid.Row="0"
> HorizontalAlignment="Right"
> VerticalAlignment="Top"
> RenderTransformOrigin="0.5097,0.45"
> Height="25"
> Margin="0,40,25,0"
> x:Name="Text_input"
> Width="100" />
> <Label
> Grid.Column="0"
> Grid.Row="0"
> HorizontalAlignment="Left"
> VerticalAlignment="Top"
> Margin="25,90,0,0"
> Width="100"
> Height="25"
> Content="Value" />
> <TextBox
> Grid.Column="0"
> Grid.Row="0"
> HorizontalAlignment="Right"
> VerticalAlignment="Top"
> Height="25"
> Width="100"
> Margin="0,90,25,0"
> x:Name="Value_input" />
> </Grid>
> </Window>
> 
> ```

Any help would be appreciated.

Thanks.

---

<div class="post-metadata">

**Author:** ![hoangthanh7897](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@hoangthanh7897](https://forum.dynamobim.com/u/hoangthanh7897)\
**Post date:** [October 9, 2024, 8:48am UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/2 "2024-10-09T08:48:25Z")

</div>

You can not assign the width of wall like that method (LookupParameter).  
Python script:  
width = 1 #The width of wall you want to set  
createSingleLayerCompoundStructure = CompoundStructure.CreateSingleLayerCompoundStructure(MaterialFunctionAssignment.Structure, width, ElementId.InvalidElementId)

setCompoundStructure = wall.WallType.SetCompoundStructure(createSingleLayerCompoundStructure)

I’m not sure but please try above script.

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [October 9, 2024, 9:00am UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/3 "2024-10-09T09:00:16Z")

</div>

@hoangthanh7897

I’m not talking about the wall width…I know to change the width I should access the `CompoundStructure` of the `WallType`… I’m talking about the `Unconnected Wall Height` which I want change its value to 3.00 m and I think it’s doable using `LookupParameter` method

Thanks.

---

<div class="post-metadata">

**Author:** ![hoangthanh7897](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@hoangthanh7897](https://forum.dynamobim.com/u/hoangthanh7897)\
**Post date:** [October 9, 2024, 9:17am UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/4 "2024-10-09T09:17:06Z")

</div>

I’m sorry for that mistake. Did you check the Top Constraint is Unconnected yet, If this is a level, then your code will warn and could not change to your given value.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 9, 2024, 9:32am UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/5 "2024-10-09T09:32:48Z")

</div>

Try converting the result from the WPF form to a double prior to setting the value.

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [October 9, 2024, 10:01am UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/6 "2024-10-09T10:01:54Z")

</div>

@jacob.small

I want to clarify that this is my first time working with WPF, and I’m still learning. I used this [example](https://www.youtube.com/watch?v=xp_FSTRMplQ&t=187s) as a starting point

> [@jacob.small](#):
>
> Try converting the result from the WPF form to a double prior to setting the value.

Could you please provide me with code for that?

Thanks.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 9, 2024, 10:04am UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/7 "2024-10-09T10:04:19Z")

</div>

I don’t have your code so I can’t implement it, but the call is here: [Built-in Functions — Python 3.13.0 documentation](https://docs.python.org/3/library/functions.html#float)

---

<div class="post-metadata">

**Author:** ![staylor](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/staylor/32/94307_2.png) [@staylor](https://forum.dynamobim.com/u/staylor)\
**Post date:** [October 9, 2024, 1:24pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/8 "2024-10-09T13:24:04Z")

</div>

You are already converting the input to a double with the code below. Are you inputting the “Top Offset” as the parameter name? If I am not mistaken, “Unconnected Height” is a read only parameter and cannot be changed and “Top Constraint” is “Levels” input and not a number or string input.

`i.LookupParameter(param_name).Set(UnitUtils.ConvertToInternalUnits(param_value, UnitTypeId.Meters))`

---

<div class="post-metadata">

**Author:** ![Mark.Ackerley](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mark.ackerley/32/79310_2.png) [@Mark.Ackerley](https://forum.dynamobim.com/u/Mark.Ackerley)\
**Post date:** [October 9, 2024, 1:41pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/9 "2024-10-09T13:41:51Z")

</div>

Perhaps like this?

`param_value = float(param_value)`

Maybe that helps,

Mark

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [October 9, 2024, 2:04pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/10 "2024-10-09T14:04:33Z")

</div>

@staylor

> [@staylor](#):
>
> You are already converting the input to a double with the code below. Are you inputting the “Top Offset” as the parameter name? If I am not mistaken, “Unconnected Height” is a read only parameter and cannot be changed and “Top Constraint” is “Levels” input and not a number or string input.

I was very specific in my question and stated that I wanted to change the `Unconnected Wall Height` parameter, which is labeled in French as `Hauteur non contrainte`. I also checked that it is not `Read-only`, and as proof, I was able to modify it as shown below using the following code without WPF.

 ![Unconnected_wall_height](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/e/cea694a85855499a1fe7ad3a6782938ab1b7a826.png)

```auto
import clr
from Autodesk.Revit.DB import *

uidoc = __revit__.ActiveUIDocument

doc = uidoc.Document

# select all walls within the project
walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()

with Transaction(doc, 'change Unconnected Wall Height') as t:
    t.Start()
    for w in walls:
        h_param = w.LookupParameter('Hauteur non contrainte')
        h_param.Set(UnitUtils.ConvertToInternalUnits(3.00, UnitTypeId.Meters))
        print(h_param)
    t.Commit()

```

Thanks.

---

<div class="post-metadata">

**Author:** ![staylor](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/staylor/32/94307_2.png) [@staylor](https://forum.dynamobim.com/u/staylor)\
**Post date:** [October 9, 2024, 2:41pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/11 "2024-10-09T14:41:04Z")

</div>

My responses were based on settings as shown in my test model (see clip). There was also a loss in translation happening.

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/6/96643225ab7d84258ca7466bc99e10c890a44cf1.png)

Try changing the except code to as shown to see if it will return the actual Revit error.

```auto
except Exception as e:
       TaskDialog.Show("error", e)

```

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 9, 2024, 3:31pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/12 "2024-10-09T15:31:32Z")

</div>

@REDO10 in your definition for _ok\_push\_button_ you set the parameter\_value variable to be self.Value\_input.Text. [This value will be a string as per the documentation](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.textbox.text?view=windowsdesktop-8.0).  
If you modify the param\_value to convert it to a double before you attempt to set the parameter I think you’ll be all set. I linked to the documentation on how to do so before, and @Mark.Ackerley followed up by showing it in use.

Have you tried adding `param_value = float(param_value)` at line 23 yet? If so did it work? If not what failed?

---

<div class="post-metadata">

**Author:** ![staylor](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/staylor/32/94307_2.png) [@staylor](https://forum.dynamobim.com/u/staylor)\
**Post date:** [October 9, 2024, 3:35pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/13 "2024-10-09T15:35:10Z")

</div>

Hey @jacob.small , just for my own self awareness, is this part of his code not already converting to a double?

> [@staylor](#):
>
> i.LookupParameter(param\_name).Set(UnitUtils.ConvertToInternalUnits(param\_value, UnitTypeId.Meters))

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 9, 2024, 3:39pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/14 "2024-10-09T15:39:38Z")

</div>

Per that [documentation](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/13) it’s is converting from a double in meters to a double in internal units.

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [October 9, 2024, 3:47pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/15 "2024-10-09T15:47:49Z")

</div>

Hi,

a few additional remarks:

- it would be better if the choice of parameter name were a ComboBox rather than a TextBox
- it’s possible to implement a Binding on the Textbox (Value\_input) with a Converter to ensure that the user actually enters a numeric number
- try-except block incomplete catch the traceback message to show it in TaskDialog

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 9, 2024, 3:56pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/16 "2024-10-09T15:56:18Z")

</div>

Many in the thread are thinking as if the user knows what type of value to put in. I.E. the user is thinking “_the tool is asking me for the unconnected wall height, so I am going to provide a value of 3.573 meters_”. The reality is that the form doesn’t tell the user what the expected input value is.

So we will quickly get the following values in real world testing:

- 3.573 meaning 3.573 meters which would be converted to 11.722441 internal units.
- 3573 meaning 3573 millimeters which would be converted to 11722.44 internal units.
- 3573mm mean3573 millimeters which would fail to convert as there is no such number as `m`.
- 3’-11 1/2" meaning 33.9583 feet which would fail to convert as there is no such number as `'`, `-`, `/`, or `"`.
- Moose, meaning one moose, which would fail to convert as there is no such number as `moose`.

Having worked in support for Autodesk for about 4 years and with BIM tools for ~20 years now I can say with absolute certainty that someone is going to do each of those first three within a week of the tool being used at scale, and within a month you’ll get the moose (or equivalent thereof). And so it’s on you as a developer to validate the input prior to attempt setting the value.

The ComboBox which @c.poupin mentions will prevent the moose and the 3’-11 1/2", but I believe that will prevent you from ever having 3’-11 1/2" as a valid input. My recommendation for UI is to always stay as close to the environment you’re in, which means that parsing the values is a must. That or tell the user to enter the value in meters using the combo box and do a sanity check that triggers a pop-up asking the user “Did you mean to set the wall height to {0} meters, or was there an error in the input?” allowing “ok” or “cancel”. This happens any time the resulting value is greater than a reasonable value (say 5, meaning 5 meters or 5000 mm), and before the conversion to double (which is before the value is brought into the Revit API).

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [October 9, 2024, 4:19pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/17 "2024-10-09T16:19:31Z")

</div>

> [@jacob.small](#):
>
> about 4 years and with BIM tools for ~20 years now

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/0/30c78ef57f4a50492468164015af29cbff299375.png)

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [October 9, 2024, 6:03pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/18 "2024-10-09T18:03:22Z")

</div>

@jacob.small

> [@jacob.small](#):
>
> Have you tried adding `param_value = float(param_value)` at line 23 yet? If so did it work? If not what failed?

Are you talking about the [pyrevit](https://discourse.pyrevitlabs.io/) script, I tried that, but I got this error:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/2/f2cfc973467e4401b4497b778a7a318501fb5e85.png)

I believe the input value needs to be set as a `Double` in the xaml instead of the [pyrevit](https://discourse.pyrevitlabs.io/) script. I’m using SharpDevelop to write the code, and as I mentioned before, I’m not yet familiar with WPF functions and syntax. As you can see in this part of the xaml code, only the `Name` property for `Value_input` is defined, so I’m not sure how to specify its type as `float`, as you suggested.

```auto
<TextBox
   		Grid.Column="0"
   		Grid.Row="0"
   		HorizontalAlignment="Right"
   		VerticalAlignment="Top"
   		Height="25"
   		Width="100"
   		Margin="0,90,25,0"
   		x:Name="Value_input" />

```

After some searching on Google, I found [this](https://learn.microsoft.com/en-us/dotnet/desktop/xaml-services/xtypearguments-directive) code which I believe is for changing the `Type` of the input text. I tried this code, but it’s still not working, and I received the error shown below.

> **code**
>
> ```auto
> <TextBox
> Grid.Column="0"
> Grid.Row="0"
> HorizontalAlignment="Right"
> VerticalAlignment="Top"
> Height="25"
> Width="100"
> Margin="0,90,25,0"
> x:Name="Value_input" 
> x:TypeArguments="x:Int32"/>
> 
> ```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/2/e257e673a93f8a79538133ae9aa5868254c990cf.png)

Thanks.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 9, 2024, 6:47pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/19 "2024-10-09T18:47:21Z")

</div>

I do not have [PyRevit](https://discourse.pyrevitlabs.io/) installed so I can’t test this for you. This means you need to share your updated Python code as otherwise we can’t trace back any error.

Try printing the class of the param\_value (` print(param_value. __class__ )`) before converting to a float. At the point you are calling the float method the object in Python should be a string, and if not you might need to call another method on it (print the methods available to the object `print(dir(param_value))` to see what your options are).

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [October 9, 2024, 9:10pm UTC](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005/20 "2024-10-09T21:10:33Z")

</div>

I finally got it working, but there’s an error related to the try-except block that needs to be fixed as @c.poupin said.  
The error message appears when I click the OK button, and the code execution continues only after I close the error message.

 ![try_except](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/2/02bfb2c45f0107b1349b5fe4434bee7918d60ff2.png)

Here is the correction I made:

```auto
        try:
            for i in self.els:
                i.LookupParameter(param_name).Set(UnitUtils.ConvertToInternalUnits(float(param_value), UnitTypeId.Meters))

```

How can I fix the try-except block to resolve it definitively?

> [@c.poupin](#):
>
> it’s possible to implement a Binding on the Textbox (Value\_input) with a Converter to ensure that the user actually enters a numeric number

Could you please show me an example of how to do that?

Thanks.

[Next page](https://forum.dynamobim.com/t/setting-wall-parameters-using-wpf/105005.md?page=2)
