replace, not clone, a curve?
I was able to use an existing code snippet to create (or clone, if it already exists) a particular curve. However, if a curve of that name (say "Curve") already exists, then this will add another curve (say "Curve 1"), and each time this is called, there will be another (say "Curve 2", etc.) - the meaning of clone, I suppose.
library_Factor2 = curve.get.to_ModelObject.get.clone(model).to_CurveBiquadratic.get
Is there a way to replace (or first delete and then create) that curve, so that I will only ever have a curve named "Curve" in the model? Something like (hopefully it is that easy) the following, perhaps?
library_Factor2 = curve.get.to_ModelObject.get.replace(model).to_CurveBiquadratic.get
Where the replace function would either create or replace, not create or clone?
<<< EDIT <<<
OK, some progress, thanks. I did the following:
model_Curves = model.getCurveBiquadratics
model_Curves.each do |model_Curve|
runner.registerInfo("Is x#{model_Curve.name}x equal to x#{curve_name}x?")
if model_Curve.name == curve_name
runner.registerInfo("Yes, x#{model_Curve.name}x is equal to x#{curve_name}x!")
break
end
end
Unfortunately, it does not quite work, as the result in the image below shows.
It seems to me that "Trane CGAM-120-SE CAPFT" should have been caught and entered the above if comparison, but it does not seem to? Also, should I be able to enter the if comparison, I could then simply use
model_Curve.remove
Is that correct?
Try
if model_Curve.name.to_s == curve_name
.model_Curve.name
is returning an object, so if you're checking equality with a string it won't work. You can make it a string withto_s
.OK, so the following works, whereby model_Curve.name.get and model_Curve.name.to_s seem to give the same results.
... unfortunately, the model_Curve.remove part does not work. I suppose I cannot just delete the curve without also deleting it in the object that references it. I tried to do that with model_chiller.setCoolingCapacityFunctionOfTemperature(), but it does not let me do that. I know I could reassign all the curve entries if the curvealready exists, but the remove/clone approach seems to require less programming.
I'm confused at what the ultimate aim is. Are you trying to add a new curve that might already exist in the model? Or add a curve that is named the same as an existing curve, but contains different data?
If you want to check if a curve named "Curve" exists in the model, you can test if
model.getCurveByName("Curve").is_initialized
returns true, and then not add an additional "Curve".