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.

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?

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

... 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?

Then you can use the methods listed here to change the Curve.
Alternatively, you could stay with the boost code you used and once you done with the first curve delete it using .remove and rename the new one to whatever you need.

The decision towards "already initialized" or "not yet initialized" is made correctly. However, it fails at trying to display coefficient1Constant(). Am I misusing the "get" function? What would fix this?

And if these curves exist, I can do any work I want on them by doing the following:

if model_curve_check.is_initialized and library_curve_check.is_initialized then
model_curve = model_curve_check.get.to_CurveBiquadratic.get
library_curve = library_curve_check.get.to_CurveBiquadratic.get
library_coefficient1 = library_curve.coefficient1Constant()
if library_coefficient1 != "" then
model_curve.setCoefficient1Constant(library_coefficient1)
end
model_chiller.setCoolingCapacityFunctionOfTemperature(model_curve)
end

And if only the library curve exists, then I do the following:

if not model_curve_check.is_initialized and library_curve_check.is_initialized then
library_curve = library_curve_check.get.to_ModelObject.get.clone(model).to_CurveBiquadratic.get
model_chiller.setCoolingCapacityFunctionOfTemperature(library_curve)
end

I even encapsulated this in its own function, one for biquadratic, one for quadratic.