I’m using pyrevit 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 script , but I’m unsure how to set it?
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)
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
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.
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.
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()
@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.
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?
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).
I believe the input value needs to be set as a Double in the xaml instead of the pyrevit 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.
After some searching on Google, I found this 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.
I do not have PyRevit 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).
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.