cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

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

sdumon
1-Newbie

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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
sdumon
1-Newbie
(To: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

View solution in original post

2 REPLIES 2
KaelLizak
14-Alexandrite
(To:sdumon)

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


Kind Regards,
Kael Lizak

Senior Technical Support Engineer
PTC Integrity Lifecycle Manager
sdumon
1-Newbie
(To: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

Top Tags