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.

Parents
  • 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
  • Hi Kris,

    I Installed HAMMER CONNECT edition, I deleted all the late changes you sugested and tried the loadResults method. unfortunately I didn't work.

    What I'm trying to do is get the nodes history Head and Flow transient results, in the nodes the first one, and in the valve the second one. The methods who do that are HistoryPipes, that gets the head, and HistoryNodes, that get the Flow (The names are a bit weird, because I was thinking the methods differente in the begining, and I haven't change it).

    Juan Sebastian.
  • Hello Juan,

    Can you provide some details on what happens in the CONNECT Edition? Please feel free to send me your source code via Private Message if needed and I will pass it along to Kris.


    Regards,

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

  • hello Jesse,

    I donwloaded the CONNECT edition as Kris recommended to use the ProjectContext.LoadResults method, but is not loading any changes after I use the ComputeHammer method. Here is the code that I'm running and is similiar to the one you send me before:

    public bool Execute(double[] CurvaTiempo, double[] CurvaCierre, int i)

    {

    TorontoProject project = (TorontoProject)aparentFormModel.CurrentProject;

    bool itDidIt = true;

    junctionIds = NodesID();

    TCVvalveIds = TCVValvesID();

    ID_CURVE = GetIDCurve(TCVvalveIds);

    ChangeValveClosure((int)ID_CURVE, project, CurvaTiempo, CurvaCierre);

    if (i != 1)

    {

    try

    {

                       //aparentFormModel.Validate();

                       aparentFormModel.ComputeHammer(true,

                           aparentFormModel.CurrentGraphicalProject.DomainDataSet.ScenarioManager.ActiveScenarioID, false);

                   }

    catch (Exception ex)

    {

    string a = ex.StackTrace;

    MethodBase b = ex.TargetSite;

    string c = ex.Message;

    int line = (new StackTrace(ex, true)).GetFrame(0).GetFileLineNumber();

    itDidIt = false;

    }

    }

               projectContext.LoadResults(project.DomainDataSet.ScenarioManager.ActiveScenarioID);

               historicalPipes = HistoryPipes(projectContext);

    HistoricalNodes = HistoryNodes(projectContext);

    CloseResults();

    return itDidIt;

    }

    I highligthed the only change I made and it isn't loading the canges made after the compute.


    Thank you for your help,

    Juan Sebastian.

  • Hi Jesse and Kris,

    I found a way to make it work. I added this two lines at the beginning of the method and it worked:

    projectContext.ResetHMRResultsDictionary(true);
    projectContext.ResetHOFResultsDictionary(true);

    I think now everything is fine and I can make the program run completely. If I have any problem I'll let you know.

    I want to thank you both for all your help, without you I would have find it really hard to complete the program in time.

    Juan Sebastian.
  • Hi Juan,

    That is excellent news! It is very satisfying when you find the solution to a problem you are trying to solve.

    If you have any other questions or problems please do not hesitate to write a new post.

    It has been a pleasure assisting you.

    Kris
Reply Children
No Data