Skip to main content
1-Visitor
April 13, 2017
Solved

Is it possible to run script from a c# application?

  • April 13, 2017
  • 2 replies
  • 3695 views

Nowaday, I build c# UI and application to answer to designer's needs.

In order to keep our application as independant as possible, i would like to run scripts contained into a given model from those application.

Do any elements exist to do so?

    Best answer by sdumon

    Hi Kael,

    Sorry for the delay.

    I finally found a solution wich maybe could help the comunity. This solution is not as simple as I expected but works fine.

    This is what i have done :

    1. get the script object present in your model (A), especially the script text.

    2. concat the script text with the following script (B)

    Dim CurrentObject, Dictionary

    Sub Main()

      On Error Resume Next

      Set Studio = CreateObject("Studio.Editor")

      Set Projects = CreateObject("OMTE.Projects")

      if Err.Number > 0 then

      Studio.DisplayOutputWindowMessage Err.Description & " " & Err.Source & vbcrlf

      Err.Clear

      end if

      On Error Resume Next

      Call Studio.OpenModel("%_PROJ_NAME_%")

      modRef = Studio.GetCurrentModelReference()

      Set Project = Projects.Item("Reference", modRef)

      Set CurrentObject = Project.ItemByID("%_PKG_ID_%")

      Set Dictionary = CurrentObject.Item("Dictionary")

      if Err.Number > 0 then

      Studio.DisplayOutputWindowMessage Err.Description & " " & Err.Source & vbcrlf

      Err.Clear

      else

      if RunUtilityUI then

      Project("Transaction") = "Begin"

      On Error Resume Next

      CommitUtility

      if Err.Number > 0 then

      Project("Transaction") = "Abort"

      else

      Project("Transaction") = "Commit"

      end if

      end if

      end if

    End Sub

    Call Main()

         This script open the model in wich the modification should be done, call the utilityUI method of the retreive script text.

    3. Once the concatenation is done, save it into a temporary vbscript file.

    4. Create a process wich execute the CSCript exe, and execute the temporary script previously created.

    5. Finally, observe the modifications.

    This method is a complex one but allow to execute a given script from outside of a model.

    Hope this could help.

    Regards

    2 replies

    16-Pearl
    April 17, 2017

    Hello Stephane Dumon‌,

    I don't have a direct answer for your question, but I'm wondering if this information might be helpful?:

    Which release of Integrity are you using?

    Kind Regards,
    Kael

    sdumon1-VisitorAuthorAnswer
    1-Visitor
    May 15, 2017

    Hi Kael,

    Sorry for the delay.

    I finally found a solution wich maybe could help the comunity. This solution is not as simple as I expected but works fine.

    This is what i have done :

    1. get the script object present in your model (A), especially the script text.

    2. concat the script text with the following script (B)

    Dim CurrentObject, Dictionary

    Sub Main()

      On Error Resume Next

      Set Studio = CreateObject("Studio.Editor")

      Set Projects = CreateObject("OMTE.Projects")

      if Err.Number > 0 then

      Studio.DisplayOutputWindowMessage Err.Description & " " & Err.Source & vbcrlf

      Err.Clear

      end if

      On Error Resume Next

      Call Studio.OpenModel("%_PROJ_NAME_%")

      modRef = Studio.GetCurrentModelReference()

      Set Project = Projects.Item("Reference", modRef)

      Set CurrentObject = Project.ItemByID("%_PKG_ID_%")

      Set Dictionary = CurrentObject.Item("Dictionary")

      if Err.Number > 0 then

      Studio.DisplayOutputWindowMessage Err.Description & " " & Err.Source & vbcrlf

      Err.Clear

      else

      if RunUtilityUI then

      Project("Transaction") = "Begin"

      On Error Resume Next

      CommitUtility

      if Err.Number > 0 then

      Project("Transaction") = "Abort"

      else

      Project("Transaction") = "Commit"

      end if

      end if

      end if

    End Sub

    Call Main()

         This script open the model in wich the modification should be done, call the utilityUI method of the retreive script text.

    3. Once the concatenation is done, save it into a temporary vbscript file.

    4. Create a process wich execute the CSCript exe, and execute the temporary script previously created.

    5. Finally, observe the modifications.

    This method is a complex one but allow to execute a given script from outside of a model.

    Hope this could help.

    Regards