hexagon logo

Saving Subroutine Math with External Script

Good morning,

I hope someone can help me. First of all I apologize for my English, but I'm using google translator.

My question is:   I have an external script in Basic that, if called at the end of a measurement routine, is used to save the mathematics of the prg it has just run.

The script in question is as follows

Option Explicit

Dim App As Object
Dim PP As Object

Sub Main (FN As String,Suffix As String)
  Dim retval As Boolean
  Dim FNOri As String

  Set App = CreateObject("PCDLRN.Application")
  Set Part = App.ActivePartProgram

  If FN="" Then
      FN= Part.Path & Part.Name
  Else
      FN=FN
  End If

  FNOri=FN

  If Suffix="" Then 
      FN=FN
  Else
      If ucase(right(FN,4))=".PRG" Then 
         FN=left(FN,len(FN)-4) & "_" & Suffix & ".prg"
      Else
         FN=FN & "_" & Suffix & ".prg"
      End If
  End If

  retval= Part.SaveAs (FN)
  If FN<>FNOri Then
     retval= Part.SaveAs (FNOri)
  End If

End Sub

The script works great if I put it at the end of every single measurement routine.

The problem arose when I wanted to create a main measurement routine that was intended to invoke other subroutines. I prepared each subroutine so that it was enclosed by the create and end subroutine commands (giving it a name). And I put in each subroutine, before the end of subroutine command, the aforementioned script. In the main measurement routine I have only included the recall of the necessary subroutines. Now, when I run the main routine, everything works as expected except for the script, which instead of saving me the math of the subroutines that have run, saves me the math of the main routine (which is actually just a subroutine container). What I guess is that surely the script was created to save the math of the main routine. Since I don't know the Basic language, I don't know how to modify it so that it saves the math of the invoked subroutines. I have also tried using AI such as Copilot and ChatGPT but with poor results. Is there anyone in the forum who knows the Basic language who can help me modify the script so that it saves the math of the invoked subroutines?

Parents Reply Children
No Data