Pass a variable within an IF statement


#1

Here’s an issue I’ve been struggling with for DAYS (aaghhh!!!) - any help would be hugely appreciated :wink:

I have a piece of script I’ve found online and fiddled with - essentially there are two variables; a “Roof Shape Code” and a “Roof Shape Name”. I’m trying to ask Dynamo to check the Sheet Properties of a given sheet for it’s “Roof Shape Code” parameter, and return a value to its “Roof Shape Name”.

If I “hard code” these answers, then there is no problem (i.e., if Roof Shape Code = R3, then return = “This works”); the problem occurs when I want to return a variable (i.e., if Roof Shape Code = R1, then return = r1Ans - whereby “r1Ans” is a property of the Revit Project).

The three small watch windows on the right prove that the script is finding the Project Information parameters I’m looking for; however the large watch on the far right illustrates the problems highlighted with red (null). Similarly, the highlighted box above shows that the “Roof Shape Name” is not being set correctly.

I’ve purposely set the last one (R3) to a fixed value “This works”, to show that this does work - it’s the variables I’m having trouble with (i.e., r1Ans, r2Ans and r3Ans).

(The areas highlighted with blue pen are supposed to be blank, so this is fine :slight_smile:)

Can anyone help??


#2

pass your values you want to return into the function - ie make those parameters of your function - they are null now in the scope of your roofStyle function.

roofStyle(val,r1,r2) etc.


#3

Thanks for your response Michael.

I’ve added the r1Ans and r2Ans fields as per your suggestion, however it’s cause the far right watch list to reduce to just one item (see below)…

I tried removing “, r1Ans, r2Ans,” from the upper code block, however this didn’t work (error says “Warning: Method ‘RoofStyle()’ not found”).


#5

Does this example help you?

What does your input look like?
Try to set an object.type on your input, so you are sure it is a string value you send to the statement.

Home2.dyn (5.4 KB)


#6

Hi erfajo,

I’ve stripped the coding down (it was doing other things besides this), and include a screenshot below…

I’ve checked, and the data being received from “RoofNameR1” et al. are definitely strings (see example within screenshot). I believe the problem is occurring because I’m not stating the Roof Style Name (i.e., “Ridge”) in Dynamo, but within Revit. This is to make it easier for non-Dynamo users.


#7

Could you show what the output is from “Element.GetParameterValueByName” node (from ‘Roof Shape Code’)? Thats the one I am interested in, since that is the value that is being evaluated in the statement. Please add a watch node.


#8

Does this help…?

Thank you for your help :slight_smile:


#9

maybe there is whitespace after those strings? (check the object type and string length)


#10

I believe the issue is that your output from the “Element.GetParameterValueByName” is a list. In your definition of “RoofStyle” there is no rank specified.

Either retrieve the string from the list returned by “Element.GetParameterValueByName” or define your variables with rank.


#11

try to upload your .dyn file and .rvt file, so we can test what might be causing the troubles.


#12

yep, this is a good solution - you can also retrieve the list element by iterating over the list inside your function.


#13

Sounds like you may have hit on something there lsmm - when I replace the “Element.GetParameterValueByName” for each of the “RoofName_R1” etc. sections with a straight forward codeblock string, it works. The difference being that I am inputting a string, rather than a list of strings.

How do I tell Dynamo to convert a list of one item, into a single string?


#14

I believe that List.FirstItem(x)+"" in a code block should do the trick.

Note there shouldn’t be anything between those quotation marks.


#15

Perfect - that’s done the trick!

Thanks to everyone for your help - sweet job!