Showing results 1 to 2 of 2

Thread: Create recipe by function and modify the new recipe in C#

  1. #1
    Join Date
    25.04.2019
    Posts
    1

    Default Create recipe by function and modify the new recipe in C#

    Hi, I would like to create a recipe using a function and edit it in C# right after creating it.
    Creating the recipe by function works using the following command:

    this.RtFunctions().Item("Function_Recipe_Offline_Save_As").Start();

    Modifying an existing recipe works as well using the following code:

    zenOn.IRGMRecipeGroups zRGM;
    zRGM = this.RGMGroups();
    zenOn.IRGMRecipeGroup zRecipeGroup = zRGM.Item("Product_Data");
    zenOn.IRGMRecipe zRecipe;zRecipe = zRecipeGroup.RecipeItem("RecipeName");
    zRecipe.set_DynProperties("RecipeNumber", RequestedID);
    zRecipe.ValueItem(1).set_DynProperties("Type", 2);
    zRecipe.ValueItem(1).set_DynProperties("StringValue", RequestedName);
    zRecipe.ValueItem(2).set_DynProperties("Type", 2);
    zRecipe.ValueItem(2).set_DynProperties("Value", RequestedID);
    zRecipe.Save();

    In both cases the Recept Name comes from a PopUp, that means the name is known in the Project. Instead of the string "RecipeName" it would be a variable RequestedName.
    What doesn't work is to create and change the Receptes in one step. Apparently the currently created Recept is not available yet? Is there someting to be updated? Does anyone have an idea how I can realize this?
    Last edited by StephanJ : 29th April 2019 at 09:12

  2. #2
    Join Date
    02.02.2012
    Posts
    10

    Default Re: Create recipe by function and modify the new recipe in C#

    Hi StephanJ,

    there could be a timing issue between calling the zenon function and trying to access the properties of that newly create recipe. It is possible, that the recipe is not created yet, when you try to access it.

    There are at least two solutions for that:
    1. Instead of calling a zenon function for creating the recipe, you could directly create your recipe from code.
      zenOn.IRGMRecipeGroups zRGM;

      zRGM = this.RGMGroups();

      zenOn.IRGMRecipeGroup zRecipeGroup = zRGM.Item("Product_Data");
      zenOn.IRGMRecipe zRecipe;zRecipe = zRecipeGroup.CreateRecipe("RecipeName");

      zRecipe.set_DynProperties("RecipeNumber", RequestedID);
      zRecipe.ValueItem(1).set_DynProperties("Type", 2);
      zRecipe.ValueItem(1).set_DynProperties("StringValue", RequestedName);
      zRecipe.ValueItem(2).set_DynProperties("Type", 2);
      zRecipe.ValueItem(2).set_DynProperties("Value", RequestedID);
      zRecipe.Save();
    2. You could sign up on the recipe created event of IRGMRecipeGroups.

Similar Threads

  1. Recipe combobox not refreshing after create
    By MOSA_SENMATIC in forum VSTA
    Replies: 2
    Last Post: 17th August 2018, 10:18
  2. Replies: 1
    Last Post: 11th December 2013, 07:15
  3. Recipe value
    By scadavmesnik in forum zenon Supervisor
    Replies: 1
    Last Post: 13th September 2012, 00:13
  4. RGM actual recipe
    By scadavmesnik in forum zenon Supervisor
    Replies: 1
    Last Post: 8th July 2012, 23:56

Tags for this Thread

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •