This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Change values in HAMMER with WaterObjects.NET

Hello,
I've been trying to change the operational (Transient, Valve) Pattern in miy HAMMER project using WO.NET, but I just have been able to see the information, but not to modify anything. I've been looking everywhere in the Hydraulics and Hydrology Forum (because I don't have acces to BDN) and I found this post:

https://communities.bentley.com/products/hydraulics___hydrology/w/hydraulics_and_hydrology__wiki/28467.using-waterobjects-net-for-sewercad

The problem is that at the end they doesn't explain how to edit the values. I already read the WaterObjects.NET Programming Guide, but I couldn't find something useful.

My method I'm building to change the values:

        public void ChangeValveClosure(int ID_CURVE, TorontoProject project)
        {
            
            ISupportElementManager CurveSet = project.DomainDataSet.SupportElementManager((int)SupportElementType.IdahoPatternElementManager);
            
            IUnitizedField CurveField = CurveSet.SupportElementField(StandardFieldName.TransientValveCurve_RelativeClosure) as IUnitizedField;
            IUnitizedField CurveFieldT = CurveSet.SupportElementField(StandardFieldName.TransientValveCurve_TimeFromStart) as IUnitizedField;

            //show values
            IModelingElement CurveElement = CurveSet.Element(ID_CURVE);
            FieldCollection Fields = CurveElement.Manager.SupportedFields();
            IField ClosureCurv = Fields[32];
            CollectionFieldListManagerBase F = (CollectionFieldListManagerBase)ClosureCurv.GetValue(ID_CURVE);
            FieldCollection Fields2 = F.SupportedFields();
            IField TimeCurve = Fields2[0];
            IField ClosureCurve = Fields2[1];
            IDictionary TimeValues = TimeCurve.GetValues();
            IDictionary ClosureValues = ClosureCurve.GetValues();

        }

What am I missing? I don't know what else to do.

Im thankfull with any help,

Juan Sebastian.

  • Hello Juan,

    These two past forum threads appear to be related to the same issue you're encountering:

    Have you tried the suggestions discussed in these threads?

    communities.bentley.com/.../100796

    communities.bentley.com/.../100798


    Regards,

    Jesse Dringoli
    Technical Support Manager, OpenFlows
    Bentley Communities Site Administrator
    Bentley Systems, Inc.

  • Hello Jesse,
    Yes, I am working in the same project, Jessica never finished and I got the task to finish what she couldn't do. Now the project can open the model, get the item IDs and read the history item. That's as far that the threads go. I need now to be able to change the opperational pattern. I have been looking a lot of threads but no one specifies how to acctually modify the item.
    Thank you for your help,
    Juan Sebastian.
  • I will consult with our developers to see if someone can assist.


    Regards,

    Jesse Dringoli
    Technical Support Manager, OpenFlows
    Bentley Communities Site Administrator
    Bentley Systems, Inc.

  • Hi Juan,

    You were actually pretty close but not quite there. Here is a modified version of your method. Note the two additional parameters that were added. Comments were also added to help make it clearer on what is going on.

    If you have any questions, just ask.

    Kris

    public void ChangeValveClosure(int ID_CURVE, TorontoProject project,
    double[] timeFromStart, double[] relativeClosure)
    {
    //Two new parameters were added to this method - timeFromStart and relativeClosure.

    ISupportElementManager patternManager =
    project.DomainDataSet.SupportElementManager((int)SupportElementType.IdahoPatternElementManager);

    IEditField transientValveCurveField =
    patternManager.SupportElementField(StandardFieldName.TransientValveCurve) as IEditField;
    ICollectionFieldListManager cflm = (ICollectionFieldListManager)transientValveCurveField.GetValue(ID_CURVE);

    IUnitizedField CurveField = cflm.Field(StandardFieldName.TransientValveCurve_RelativeClosure) as IUnitizedField;
    IUnitizedField CurveFieldT = cflm.Field(StandardFieldName.TransientValveCurve_TimeFromStart) as IUnitizedField;

    //This loop is just to get any existing values and write them out to the console window. This is not required.
    for(int i = 0; i < cflm.Count; ++i)
    {
    double T = CurveFieldT.GetDoubleValue(i);
    double C = CurveField.GetDoubleValue(i);

    Console.WriteLine(T.ToString() + ", " + C.ToString());
    }

    //Check to make sure that the two arrays have the same number of items and they have more than one item
    //to add to the pattern.
    if(timeFromStart.Length == relativeClosure.Length && timeFromStart.Length > 0)
    {
    //To replace the values in the curve, you need to delete the existing rows and add new ones.
    while(cflm.Count > 0)
    cflm.Delete(0);

    for(int i = 0; i < timeFromStart.Length; ++i)
    {
    int rowID = cflm.Add();
    ((IEditField)CurveFieldT).Setvalue(rowID, timeFromStart[i]);
    ((IEditField)CurveField).SetValue(rowID, relativeClosure[i]);
    }

    //Make sure you set the collection back to the collection field so it is stored in the database correctly.
    transientValveCurveField.SetValue(ID_CURVE, cflm);
    }
    }

    Answer Verified By: Juan Sebastian Gómez Pinto 

  • Hi kris,
    This worked perfectly, but made me realize that I'm not running the engine. I tried using a similar code used in the sewerCad example, but it is not working. I'm trying this line that is a modify version of the example but is not working:

    aparentFormModel.GetActionFactory<Haestad.Toronto.Support.Actions.TorontoActionFactory>();GetOpenAutoComputeAction();.Execute();

    Thanks again for all the help,

    Juan Sebastian