Setting walls parameters issue

Hi All,

I’m trying to modify the Unconnected Wall Height parameter for the selected walls using a WPF window as shown below, but I’m encountering the following error and I don’t know how to solve it?

Here my pyrevit and xaml scripts

My_Tool
# -*- 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()
        slef.Close()

    def cancel_button(self, sender, e):
        self.Close()

form = ModalForm('interface.xaml')```
xaml
<?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.

just glancing at the error id guess you typo’d slef instead of self somewhere

2 Likes

@jpitts

Oh, my bad… I didn’t pay attention to this ridiculous error!!

I corrected this error and tested the code using the ‘Mark’ parameter as an example, and it works. However, it does not work for the Unconnected Wall Height parameter, as it return the error message handled by the except block 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 script, but I’m unsure how to set it?

Thanks.

I would use “SetValueString()” instead of “Set()”, SetValueString interprets the string the same way as when you type it into a parameter field in, so the line would look like:
i.lookupParameter(param_name).SetValueString("{} m".format(param_value))
Adding the m for meters is optional, this would be assumed if the project units are set to meters, leaving it off and accepting a string in your form would allow users to type their own unit to override the units. Also it would be good to get the error from the except and print that in the alert.

1 Like