Hi!
As this is my first topic, before I start i would like to thank all the people on this forum for the help they have provided me learning Dynamo, even though I’ve never been part of their conversations. I am just a beginner and have found this forum very helpful!
I was working on an experiment where is would like to start on generative design. (Withouth Autodesk Refinery) To do this I was planning to itterate over different variations of a design and then read some results of that design to pick the best option. As this will obviously need to be done in the correct sequence I looked at Imperative designscript to get me where I need to be, unfortunately I do not get it to work for even a simple example as I always read the data from before the change is made. The result is that i can only read the correct data when i Run twice.
I’ve reduced the sample to the following situation: My model contains a single wall which length is dependant on the global parameter “Width”. After Dynamo changed the parameter I would like to read the Area of the wall. (see image)
Now I was trying to change the global Parameter based on a number slider, which works fine. Then I would like to select the walls and read the new area. Here I hit a bumb: I can’t seem to find a way to select the walls using designscript, so I’ve used a function block instead. Reading the data from that point on does not seem to always give me the updated data.
More specifically; when I am using Element.GetParameterValueByName() to get the data I won’t get the latest results. But when I am using Revit.Elements.Parameter.ParameterByName() I will get the latest result! (Yay!) Unfortunately the latter gives me a value with units, which prevents me from doing some basic math.(Which i will need later in the design)
I am not sure what the issue is with the first function but it might have to do with the selection outside of the imperative scope? Is there a method to create a selection within the imperative scope?
Alternatively; would it be possible to remove the units from the value of the second function? I have not found a way to remove values and Parameter.Value() does not seem to work in Imperative code?
My script(s):
reqWidth;
[Imperative] {
// Update Global parameter
paramName = GlobalParameter.FindByName("Width");
GlobalParameter.SetValue(paramName, reqWidth);
// Find walls
return = Category.ByName("Walls");
// Return functon as selection cannot be done
// in Designscript.
};
and:
walls;
[Imperative]{
_area = Element.GetParameterValueByName(walls[0], "Area");
return = _area;
//_area_test1 = Revit.Elements.Parameter.ParameterByName(walls, "Area");
};
Any help would be greatly appreciated!
Kind regards