Moldflow Insight Forum
Welcome to Autodesk’s Moldflow Insight Forums. Share your knowledge, ask questions, and explore popular Moldflow Insight topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help with API to extract Mesh Information from Mesh Log

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
mantd
716 Views, 9 Replies

Need help with API to extract Mesh Information from Mesh Log

Hello everyone,
I'm trying to output "Mesh type and global edge length" from an ".out" file using the "cmmessage". 
I understand the MSCD formatting to some extent (through the API examples 
here) to be able to extract information from the log.  
Because mesh information from the Mesh Log file, I can not use StudyDoc.GetResultPrefix go with ("Flow"),("Cool") or ("Warp") . I tried StudyDoc.GetResultPrefix("Mesh Log") but it did not work. 

 

Any help to understand how to work with Mesh Log would be appreciated.

Thanks in advance.

My script below:

 

'%RunPerInstance
'@
'@ DESCRIPTION
'@ This script shows how to extract information from the screen out (.out) file.
'@ Several examples are shown
'@
'@ This script perfoms a similar function to the studyrlt command
'@ studyrlt  <study> -message <sequence>  <message ID> <occurrence> <item>

'@ Some knowledge of the  format used in the .out file is required.
'@ please see details in the ..../data/dat/cmmesage.dat  for details
'@ Some know of the analysis sequences is required.
'@ please see details in the ..../data/dat/process.dat  for details
'@
'@ SYNTAX
'@ RaadScreenOutput
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@ Assumes a Flow analysis has been run and the required study file is selected and open.
'@ Some knowledge of the MSCD format as defined in message.dat  is required
'@ Limited error checking is performed
'@
'@@
Option Explicit
SetLocale("en-us")
Dim Synergy
Dim SynergyGetter
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
  Set Synergy = SynergyGetter.GetSASynergy
Else
  Set Synergy = CreateObject("amiws.Synergy")
End If

Dim StudyDoc
Set StudyDoc = Synergy.StudyDoc()

' Get the name of the .out file associated with the flow results.
' Note:  This assumes a Flow analysis sequence was run.
Dim lName
lName = StudyDoc.GetResultPrefix("Flow")
Dim lOutName
lOutName = lName & ".out"

' Create and Populate the ScreenOutput Class for the lOutName
Dim lMessages
Set lMessages = New ScreenOutput
lMessages.LoadOutputFile(lOutName)

Dim MM, lStr

'MSCD 1902014 1 0 0 0 0 1 1
'      Mesh type:     
Set MM = lMessages.GetMessage(1902014,0)
lStr = " Mesh type = " & CStr(MM.GetString(0)) 
MsgBox CStr(lStr)

'MSCD 1902003 1 0 0 0 0 0 1
'      Global edge length:                                   %11.4G
'    m,1,1
Set MM = lMessages.GetMessage(1902003,0)
lStr = "Global edge length = " & CStr(MM.GetFloat(0)*1000)
MsgBox CStr(lStr)




' ---- Message class
Class Message
  Private mMSCD   ' MSCD Message ID
  Private mNumString    ' Number of Strings associated with the Message
  Private mNumFloat     ' Number of Floats  Associated with the Message
  Private mStrings()    ' The Strings Associated with the Message
  Private mFloats()  ' The Numerical Values Associated with the Message

  Public Sub SetMSCD(aMSCD)
    mMSCD = aMSCD
  End Sub

  Public Sub SetNumString(aNumString)
    mNumString = aNumString
  End Sub

  Public Sub SetNumFloat(aNumFloat)
    mNumFloat = aNumFloat
  End Sub

  Public Sub AddFloat(aFloat)
    mNumFloat = mNumFloat + 1
    ReDim Preserve mFloats(mNumFloat)
    mFloats(mNumFloat-1) = aFloat
  End Sub

  Public Sub AddString(aString)
    mNumString = mNumString + 1
    ReDim Preserve mStrings(mNumString)
    mStrings(mNumString-1) = aString
  End Sub

  Public Function GetMSCD()
    GetMSCD = mMSCD
  End Function
  Public Function GetString(aIndex)
    GetString = ""
    If aIndex >= 0 And aIndex < mNumString Then
       GetString = mStrings(aIndex)
    End if
  End Function

  Public Function GetFloat(aIndex)
    GetFloat = ""
    If aIndex >= 0 And aIndex < mNumFloat Then
       GetFloat = mFloats(aIndex)
    End if
  End Function

  Public Function GetNumString()
    GetNumString = mNumString
  End Function

  Public Function GetNumFloat()
    GetNumFloat = mNumFloat
  End Function

  Private Sub Class_Initialize
    mMSCD = -1
    mNumString = 0
    mNumFloat = 0
  End Sub
End Class

Class ScreenOutput

 Private mMessages()  ' Array of Messages associate with the screen output File
 Private mNumMessages  ' Number of messages in the screen output file

  Public Function LoadOutputFile(aFile)
    Const ForReading = 1
    Dim FS
    Set FS = CreateObject("Scripting.FileSystemObject")
    Dim File
    Set File = FS.OpenTextFile(aFile, ForReading)
        While Not File.AtEndOfStream
      Dim ID
      ID = -1
        ' Read the MSCD
        Dim Line,lenLine
    Line = File.ReadLine
    lenLine = len(Line)
    If Not File.AtEndOfStream or lenLine >= 1 Then
      ID = Line
      Dim curMessage
      Set curMessage = New Message
      curMessage.SetMSCD(ID)
      ' Read the number of strings
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numString
        numString = Line
        ' Read Strings
        Dim i
        For i = 1 To numString
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
            CurMessage.AddString(Line)
          End if
        Next
      End if
      ' Read the number of floats
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numFloat
        numFloat = Line
        ' Read Floats
        For i = 1 To numFloat
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
           CurMessage.AddFloat(Line)
          End if
        Next
      End If
      ' Add current message to the list
      AddMessage(CurMessage)
    End If
  Wend
    File.Close
  End Function

  Public Sub AddMessage(aMessage)
  mNumMessages = mNumMessages + 1
    ReDim Preserve mMessages(mNumMessages)
    Set mMessages(mNumMessages-1) = aMessage
  End Sub

  Public Function GetNumMessages()
    GetNumMessages = mNumMessages
  End Function

  Public Function GetMessage(aMSCD,aOccur)
    Set GetMessage = Nothing
    Dim j
    Dim lFindInstance
    lFindInstance = aOccur
    If aOccur < 0 Then
      lFindInstance = 0
    End if
    Dim Count
    Count = 0
    For j = 0 To mNumMessages-1
      'MsgBox mMessages(j).GetMSCD &"|"& aMSCD
      If CStr(mMessages(j).GetMSCD) = CStr(aMSCD) Then
         Count = Count + 1
         If Count >= lFindInstance Then
           Set GetMessage = mMessages(j)
           Exit Function
         End if
      End if
    Next
  End Function

  Private Sub Class_Initialize
  mNumMessages = 0
  End Sub
End Class

 



 

Tags (4)
9 REPLIES 9
Message 2 of 10
bernor_mf
in reply to: mantd

Hi,
I believe this is a limitation.

 

As stated in code:
'@ This script shows how to extract information from the screen out (.out) file.

 

So you extract data from .out.
This means data from tab Analysis Log.
Hence using "Flow" to ensure the .out and data is there.
Basically only information about mesh from log information "Model details :".

 

Further, the tab "Mesh Log" could be saved to .txt-file by right-click in area and do a "Save As..."
But, unfortunately there is no API code to do this automatically.
Otherwise that could have been a workaround.

 

To get mesh type this piece of code does the job.
(Note: Mesh type "Dual Domain" is named and hard coded to "Fusion", hence a change of mesh type name.)

 

SetLocale("en-us")
Dim SynergyGetter, Synergy
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
	Set Synergy = SynergyGetter.GetSASynergy
Else
	Set Synergy = CreateObject("synergy.Synergy")
End If
Synergy.SetUnits "Metric"

Dim StudyDoc
Set StudyDoc = Synergy.StudyDoc()
Dim CurrentMeshType
CurrentMeshType = StudyDoc.MeshType

If (CurrentMeshType = "Fusion" ) Then
  CurrentMeshType = "Dual Domain"
End If

Msgbox "Current Mesh Type : " & CurrentMeshType ,,"CurrentMeshType"


So I have no solution to your request due to limitations. Sorry.
Regards,
Berndt

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
Message 3 of 10
mantd
in reply to: mantd

thank for your attention. @bernor_mf 
actually I solved this case.

find and read the "mesh.out" in folder and it worked well

 

 

 

 

Dim lOutName_mesh
If fso.FileExists(StudyName & "~7Mesh" & ".out") = True then
    lOutName_mesh = StudyName & "~7Mesh" & ".out"
ElseIf fso.FileExists(StudyName & "~9Mesh" & ".out") = True Then
    lOutName_mesh = StudyName & "~9Mesh" & ".out"
ElseIf fso.FileExists(StudyName & "~1Mesh" & ".out") = True Then
    lOutName_mesh = StudyName & "~1Mesh" & ".out"
ElseIf fso.FileExists(StudyName & "~3Mesh" & ".out") = True Then
    lOutName_mesh = StudyName & "~3Mesh" & ".out"
Else
    ' Default case (if none of the specific mesh folders exist)
    lOutName_mesh = StudyName & "~Mesh" & ".out"
End If

' Create and Populate the ScreenOutput Class for lOutName_mesh
Dim lMessages_mesh
Set lMessages_mesh = New ScreenOutput
lMessages_mesh.LoadOutputFile(lOutName_mesh)

'MSCD 1902003 1 0 0 0 0 0 1
'      Global edge length:                                   %11.4G
'    m,1,1
Set MM = lMessages_mesh.GetMessage(1902003,0)
lStr = "Global edge = " & CStr(MM.GetFloat(0)*1000)
MsgBox CStr(lStr)

 

 

 

 

Message 4 of 10
bernor_mf
in reply to: mantd

@mantd 

Hi,

happy to hear you resolved the issue. 🙂

And thank you for sharing your creative solution with the community.

Very much appreciated.

 

Regards,

Berndt

 

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
Message 5 of 10
bernor_mf
in reply to: mantd

@mantd 

Hi,

I found your workaround interesting.

Made an improvement, as id of mesh file varies, and sometimes does not exist.

Basically look for first connected "*.mesh.out", if existing.

'%RunPerInstance
'@
'@ DESCRIPTION
'@ This script shows how to extract information from the screen out (.out) file.
'@ Several examples are shown
'@
'@ This script perfoms a similar function to the studyrlt command
'@ studyrlt  <study> -message <sequence>  <message ID> <occurrence> <item>

'@ Some knowledge of the  format used in the .out file is required.
'@ please see details in the ..../data/dat/cmmesage.dat  for details
'@ Some know of the analysis sequences is required.
'@ please see details in the ..../data/dat/process.dat  for details
'@
'@ SYNTAX
'@ RaadScreenOutput
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@ Assumes a Flow analysis has been run and the required study file is selected and open.
'@ Some knowledge of the MSCD format as defined in message.dat  is required
'@ Limited error checking is performed
'@
'@@
Option Explicit
SetLocale("en-us")
Dim Synergy
Dim SynergyGetter
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
  Set Synergy = SynergyGetter.GetSASynergy
Else
  Set Synergy = CreateObject("amiws.Synergy")
End If

Dim StudyDoc
Set StudyDoc = Synergy.StudyDoc()

Dim fso, lOutName_mesh, StudyName
StudyName = left(StudyDoc.StudyName, len(StudyDoc.StudyName)-4)
Set fso = CreateObject("Scripting.FileSystemObject")

Dim strPattern , StudyNameMesh
strPattern = StudyName & "*mesh.out"
StudyNameMesh = GetFiles( strPattern )
'There should only be one file. Split and read the first.
StudyNameMesh = Split( Mid( StudyNameMesh, 2 ), ";" )
If Not (Ubound(StudyNameMesh)) = -1 Then
    lOutName_mesh = StudyNameMesh(0)
Else
  MsgBox "No mesh output file found.",,"Information"
  Wscript.Quit
End If
 
Function GetFiles( strFilespec )
 
	Dim colFiles, objFile, objFSO, objRE, wshShell
	Dim strFiles, strPattern
 
	' Return "Error" on missing or invalid filespec
	GetFiles = Array( "Error" )
	If Trim( strFilespec ) = ""  Then Exit Function
	If InStr( strFilespec, "\" ) Then Exit Function
 
	Set wshShell = CreateObject( "WScript.Shell" )
	Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
	Set objRE    = New RegExp
 
	' Convert DOS wildcards to regex pattern
	objRE.Pattern    = "([\.\(\)\[\]\{\}\$])"
	objRE.Global     = True
	objRE.IgnoreCase = True
	strPattern       = objRE.Replace( strFilespec, "\$1" )
	strPattern       = Replace( strPattern,  "?", "[^\\]"  )
	strPattern       = Replace( strPattern,  "*", "[^\\]*" )
	objRE.Pattern    = "(^|\\)" & strPattern & "$"
 
	' Get a collection of files
	Set colFiles  = objFSO.GetFolder( wshShell.CurrentDirectory ).Files
	strFiles = ""
	' Iterate through the list of files
	For Each objFile In colFiles
		' Check if the file name matches filespec
		If objRE.Test( objFile.Path ) Then
			' Add the file to the list
			strFiles = strFiles & ";" & objFile.Name
		End If
	Next
 
	' Return the list of files as an array
	'GetFiles = Split( Mid( strFiles, 2 ), ";" )
	GetFiles = strFiles

	' Cleanup
	Set colFiles  = Nothing
	Set objRE     = Nothing
	Set objFSO    = Nothing
	Set wshShell  = Nothing
End Function


' Create and Populate the ScreenOutput Class for lOutName_mesh
Dim lMessages_mesh
Set lMessages_mesh = New ScreenOutput
lMessages_mesh.LoadOutputFile(lOutName_mesh)

Dim MM, lStr

'MSCD 1902003 1 0 0 0 0 0 1
'      Global edge length:                                   %11.4G
'    m,1,1
Set MM = lMessages_mesh.GetMessage(1902003,0)
lStr = "Global edge = " & CStr(MM.GetFloat(0)*1000)
MsgBox CStr(lStr)

' ---- Message class
Class Message
  Private mMSCD   ' MSCD Message ID
  Private mNumString    ' Number of Strings associated with the Message
  Private mNumFloat     ' Number of Floats  Associated with the Message
  Private mStrings()    ' The Strings Associated with the Message
  Private mFloats()  ' The Numerical Values Associated with the Message

  Public Sub SetMSCD(aMSCD)
    mMSCD = aMSCD
  End Sub

  Public Sub SetNumString(aNumString)
    mNumString = aNumString
  End Sub

  Public Sub SetNumFloat(aNumFloat)
    mNumFloat = aNumFloat
  End Sub

  Public Sub AddFloat(aFloat)
    mNumFloat = mNumFloat + 1
    ReDim Preserve mFloats(mNumFloat)
    mFloats(mNumFloat-1) = aFloat
  End Sub

  Public Sub AddString(aString)
    mNumString = mNumString + 1
    ReDim Preserve mStrings(mNumString)
    mStrings(mNumString-1) = aString
  End Sub

  Public Function GetMSCD()
    GetMSCD = mMSCD
  End Function
  Public Function GetString(aIndex)
    GetString = ""
    If aIndex >= 0 And aIndex < mNumString Then
       GetString = mStrings(aIndex)
    End if
  End Function

  Public Function GetFloat(aIndex)
    GetFloat = ""
    If aIndex >= 0 And aIndex < mNumFloat Then
       GetFloat = mFloats(aIndex)
    End if
  End Function

  Public Function GetNumString()
    GetNumString = mNumString
  End Function

  Public Function GetNumFloat()
    GetNumFloat = mNumFloat
  End Function

  Private Sub Class_Initialize
    mMSCD = -1
    mNumString = 0
    mNumFloat = 0
  End Sub
End Class

Class ScreenOutput

 Private mMessages()  ' Array of Messages associate with the screen output File
 Private mNumMessages  ' Number of messages in the screen output file

  Public Function LoadOutputFile(aFile)
    Const ForReading = 1
    Dim FS
    Set FS = CreateObject("Scripting.FileSystemObject")
    Dim File
    Set File = FS.OpenTextFile(aFile, ForReading)
        While Not File.AtEndOfStream
      Dim ID
      ID = -1
        ' Read the MSCD
        Dim Line,lenLine
    Line = File.ReadLine
    lenLine = len(Line)
    If Not File.AtEndOfStream or lenLine >= 1 Then
      ID = Line
      Dim curMessage
      Set curMessage = New Message
      curMessage.SetMSCD(ID)
      ' Read the number of strings
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numString
        numString = Line
        ' Read Strings
        Dim i
        For i = 1 To numString
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
            CurMessage.AddString(Line)
          End if
        Next
      End if
      ' Read the number of floats
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numFloat
        numFloat = Line
        ' Read Floats
        For i = 1 To numFloat
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
           CurMessage.AddFloat(Line)
          End if
        Next
      End If
      ' Add current message to the list
      AddMessage(CurMessage)
    End If
  Wend
    File.Close
  End Function

  Public Sub AddMessage(aMessage)
  mNumMessages = mNumMessages + 1
    ReDim Preserve mMessages(mNumMessages)
    Set mMessages(mNumMessages-1) = aMessage
  End Sub

  Public Function GetNumMessages()
    GetNumMessages = mNumMessages
  End Function

  Public Function GetMessage(aMSCD,aOccur)
    Set GetMessage = Nothing
    Dim j
    Dim lFindInstance
    lFindInstance = aOccur
    If aOccur < 0 Then
      lFindInstance = 0
    End if
    Dim Count
    Count = 0
    For j = 0 To mNumMessages-1
      'MsgBox mMessages(j).GetMSCD &"|"& aMSCD
      If CStr(mMessages(j).GetMSCD) = CStr(aMSCD) Then
         Count = Count + 1
         If Count >= lFindInstance Then
           Set GetMessage = mMessages(j)
           Exit Function
         End if
      End if
    Next
  End Function

  Private Sub Class_Initialize
  mNumMessages = 0
  End Sub
End Class

Regards,

Berndt

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
Message 6 of 10
bernor_mf
in reply to: mantd

@mantd 

Hi,
I found your workaround interesting.
Made some improvements, as the id of mesh.out varies.
It basically finds the "*mesh.out" connected to study, and also if not existing.
Paste it in here:

'%RunPerInstance
'@
'@ DESCRIPTION
'@ This script shows how to extract information from the screen out (.out) file.
'@ Several examples are shown
'@
'@ This script perfoms a similar function to the studyrlt command
'@ studyrlt  <study> -message <sequence>  <message ID> <occurrence> <item>

'@ Some knowledge of the  format used in the .out file is required.
'@ please see details in the ..../data/dat/cmmesage.dat  for details
'@ Some know of the analysis sequences is required.
'@ please see details in the ..../data/dat/process.dat  for details
'@
'@ SYNTAX
'@ RaadScreenOutput
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@ Assumes a Flow analysis has been run and the required study file is selected and open.
'@ Some knowledge of the MSCD format as defined in message.dat  is required
'@ Limited error checking is performed
'@
'@@
Option Explicit
SetLocale("en-us")
Dim Synergy
Dim SynergyGetter
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
  Set Synergy = SynergyGetter.GetSASynergy
Else
  Set Synergy = CreateObject("amiws.Synergy")
End If

Dim StudyDoc
Set StudyDoc = Synergy.StudyDoc()

Dim fso, lOutName_mesh, StudyName
StudyName = left(StudyDoc.StudyName, len(StudyDoc.StudyName)-4)
Set fso = CreateObject("Scripting.FileSystemObject")

Dim strPattern , StudyNameMesh
strPattern = StudyName & "*mesh.out"
StudyNameMesh = GetFiles( strPattern )
'There should only be one file. Split and read the first.
StudyNameMesh = Split( Mid( StudyNameMesh, 2 ), ";" )
If Not (Ubound(StudyNameMesh)) = -1 Then
    lOutName_mesh = StudyNameMesh(0)
Else
  MsgBox "No mesh output file found.",,"Information"
  Wscript.Quit
End If
 
Function GetFiles( strFilespec )
 
	Dim colFiles, objFile, objFSO, objRE, wshShell
	Dim strFiles, strPattern
 
	' Return "Error" on missing or invalid filespec
	GetFiles = Array( "Error" )
	If Trim( strFilespec ) = ""  Then Exit Function
	If InStr( strFilespec, "\" ) Then Exit Function
 
	Set wshShell = CreateObject( "WScript.Shell" )
	Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
	Set objRE    = New RegExp
 
	' Convert DOS wildcards to regex pattern
	objRE.Pattern    = "([\.\(\)\[\]\{\}\$])"
	objRE.Global     = True
	objRE.IgnoreCase = True
	strPattern       = objRE.Replace( strFilespec, "\$1" )
	strPattern       = Replace( strPattern,  "?", "[^\\]"  )
	strPattern       = Replace( strPattern,  "*", "[^\\]*" )
	objRE.Pattern    = "(^|\\)" & strPattern & "$"
 
	' Get a collection of files
	Set colFiles  = objFSO.GetFolder( wshShell.CurrentDirectory ).Files
	strFiles = ""
	' Iterate through the list of files
	For Each objFile In colFiles
		' Check if the file name matches filespec
		If objRE.Test( objFile.Path ) Then
			' Add the file to the list
			strFiles = strFiles & ";" & objFile.Name
		End If
	Next
 
	' Return the list of files as an array
	'GetFiles = Split( Mid( strFiles, 2 ), ";" )
	GetFiles = strFiles

	' Cleanup
	Set colFiles  = Nothing
	Set objRE     = Nothing
	Set objFSO    = Nothing
	Set wshShell  = Nothing
End Function


' Create and Populate the ScreenOutput Class for lOutName_mesh
Dim lMessages_mesh
Set lMessages_mesh = New ScreenOutput
lMessages_mesh.LoadOutputFile(lOutName_mesh)

Dim MM, lStr

'MSCD 1902003 1 0 0 0 0 0 1
'      Global edge length:                                   %11.4G
'    m,1,1
Set MM = lMessages_mesh.GetMessage(1902003,0)
lStr = "Global edge = " & CStr(MM.GetFloat(0)*1000)
MsgBox CStr(lStr)

' ---- Message class
Class Message
  Private mMSCD   ' MSCD Message ID
  Private mNumString    ' Number of Strings associated with the Message
  Private mNumFloat     ' Number of Floats  Associated with the Message
  Private mStrings()    ' The Strings Associated with the Message
  Private mFloats()  ' The Numerical Values Associated with the Message

  Public Sub SetMSCD(aMSCD)
    mMSCD = aMSCD
  End Sub

  Public Sub SetNumString(aNumString)
    mNumString = aNumString
  End Sub

  Public Sub SetNumFloat(aNumFloat)
    mNumFloat = aNumFloat
  End Sub

  Public Sub AddFloat(aFloat)
    mNumFloat = mNumFloat + 1
    ReDim Preserve mFloats(mNumFloat)
    mFloats(mNumFloat-1) = aFloat
  End Sub

  Public Sub AddString(aString)
    mNumString = mNumString + 1
    ReDim Preserve mStrings(mNumString)
    mStrings(mNumString-1) = aString
  End Sub

  Public Function GetMSCD()
    GetMSCD = mMSCD
  End Function
  Public Function GetString(aIndex)
    GetString = ""
    If aIndex >= 0 And aIndex < mNumString Then
       GetString = mStrings(aIndex)
    End if
  End Function

  Public Function GetFloat(aIndex)
    GetFloat = ""
    If aIndex >= 0 And aIndex < mNumFloat Then
       GetFloat = mFloats(aIndex)
    End if
  End Function

  Public Function GetNumString()
    GetNumString = mNumString
  End Function

  Public Function GetNumFloat()
    GetNumFloat = mNumFloat
  End Function

  Private Sub Class_Initialize
    mMSCD = -1
    mNumString = 0
    mNumFloat = 0
  End Sub
End Class

Class ScreenOutput

 Private mMessages()  ' Array of Messages associate with the screen output File
 Private mNumMessages  ' Number of messages in the screen output file

  Public Function LoadOutputFile(aFile)
    Const ForReading = 1
    Dim FS
    Set FS = CreateObject("Scripting.FileSystemObject")
    Dim File
    Set File = FS.OpenTextFile(aFile, ForReading)
        While Not File.AtEndOfStream
      Dim ID
      ID = -1
        ' Read the MSCD
        Dim Line,lenLine
    Line = File.ReadLine
    lenLine = len(Line)
    If Not File.AtEndOfStream or lenLine >= 1 Then
      ID = Line
      Dim curMessage
      Set curMessage = New Message
      curMessage.SetMSCD(ID)
      ' Read the number of strings
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numString
        numString = Line
        ' Read Strings
        Dim i
        For i = 1 To numString
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
            CurMessage.AddString(Line)
          End if
        Next
      End if
      ' Read the number of floats
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numFloat
        numFloat = Line
        ' Read Floats
        For i = 1 To numFloat
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
           CurMessage.AddFloat(Line)
          End if
        Next
      End If
      ' Add current message to the list
      AddMessage(CurMessage)
    End If
  Wend
    File.Close
  End Function

  Public Sub AddMessage(aMessage)
  mNumMessages = mNumMessages + 1
    ReDim Preserve mMessages(mNumMessages)
    Set mMessages(mNumMessages-1) = aMessage
  End Sub

  Public Function GetNumMessages()
    GetNumMessages = mNumMessages
  End Function

  Public Function GetMessage(aMSCD,aOccur)
    Set GetMessage = Nothing
    Dim j
    Dim lFindInstance
    lFindInstance = aOccur
    If aOccur < 0 Then
      lFindInstance = 0
    End if
    Dim Count
    Count = 0
    For j = 0 To mNumMessages-1
      'MsgBox mMessages(j).GetMSCD &"|"& aMSCD
      If CStr(mMessages(j).GetMSCD) = CStr(aMSCD) Then
         Count = Count + 1
         If Count >= lFindInstance Then
           Set GetMessage = mMessages(j)
           Exit Function
         End if
      End if
    Next
  End Function

  Private Sub Class_Initialize
  mNumMessages = 0
  End Sub
End Class


Regards,
Berndt

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
Message 7 of 10
bernor_mf
in reply to: mantd

@mantd 

Hi,
I found your workaround interesting.
Made some improvements, as the id of mesh.out varies.
It basically finds the "*mesh.out" connected to study, and also if not existing.
Paste it in here:

 

'%RunPerInstance
'@
'@ DESCRIPTION
'@ This script shows how to extract information from the screen out (.out) file.
'@ Several examples are shown
'@
'@ This script perfoms a similar function to the studyrlt command
'@ studyrlt  <study> -message <sequence>  <message ID> <occurrence> <item>

'@ Some knowledge of the  format used in the .out file is required.
'@ please see details in the ..../data/dat/cmmesage.dat  for details
'@ Some know of the analysis sequences is required.
'@ please see details in the ..../data/dat/process.dat  for details
'@
'@ SYNTAX
'@ RaadScreenOutput
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@ Assumes a Flow analysis has been run and the required study file is selected and open.
'@ Some knowledge of the MSCD format as defined in message.dat  is required
'@ Limited error checking is performed
'@
'@@
Option Explicit
SetLocale("en-us")
Dim Synergy
Dim SynergyGetter
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
  Set Synergy = SynergyGetter.GetSASynergy
Else
  Set Synergy = CreateObject("amiws.Synergy")
End If

Dim StudyDoc
Set StudyDoc = Synergy.StudyDoc()

Dim fso, lOutName_mesh, StudyName
StudyName = left(StudyDoc.StudyName, len(StudyDoc.StudyName)-4)
Set fso = CreateObject("Scripting.FileSystemObject")

Dim strPattern , StudyNameMesh
strPattern = StudyName & "*mesh.out"
StudyNameMesh = GetFiles( strPattern )
'There should only be one file. Split and read the first.
StudyNameMesh = Split( Mid( StudyNameMesh, 2 ), ";" )
If Not (Ubound(StudyNameMesh)) = -1 Then
    lOutName_mesh = StudyNameMesh(0)
Else
  MsgBox "No mesh output file found.",,"Information"
  Wscript.Quit
End If
 
Function GetFiles( strFilespec )
 
	Dim colFiles, objFile, objFSO, objRE, wshShell
	Dim strFiles, strPattern
 
	' Return "Error" on missing or invalid filespec
	GetFiles = Array( "Error" )
	If Trim( strFilespec ) = ""  Then Exit Function
	If InStr( strFilespec, "\" ) Then Exit Function
 
	Set wshShell = CreateObject( "WScript.Shell" )
	Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
	Set objRE    = New RegExp
 
	' Convert DOS wildcards to regex pattern
	objRE.Pattern    = "([\.\(\)\[\]\{\}\$])"
	objRE.Global     = True
	objRE.IgnoreCase = True
	strPattern       = objRE.Replace( strFilespec, "\$1" )
	strPattern       = Replace( strPattern,  "?", "[^\\]"  )
	strPattern       = Replace( strPattern,  "*", "[^\\]*" )
	objRE.Pattern    = "(^|\\)" & strPattern & "$"
 
	' Get a collection of files
	Set colFiles  = objFSO.GetFolder( wshShell.CurrentDirectory ).Files
	strFiles = ""
	' Iterate through the list of files
	For Each objFile In colFiles
		' Check if the file name matches filespec
		If objRE.Test( objFile.Path ) Then
			' Add the file to the list
			strFiles = strFiles & ";" & objFile.Name
		End If
	Next
 
	' Return the list of files as an array
	'GetFiles = Split( Mid( strFiles, 2 ), ";" )
	GetFiles = strFiles

	' Cleanup
	Set colFiles  = Nothing
	Set objRE     = Nothing
	Set objFSO    = Nothing
	Set wshShell  = Nothing
End Function


' Create and Populate the ScreenOutput Class for lOutName_mesh
Dim lMessages_mesh
Set lMessages_mesh = New ScreenOutput
lMessages_mesh.LoadOutputFile(lOutName_mesh)

Dim MM, lStr

'MSCD 1902003 1 0 0 0 0 0 1
'      Global edge length:                                   %11.4G
'    m,1,1
Set MM = lMessages_mesh.GetMessage(1902003,0)
lStr = "Global edge = " & CStr(MM.GetFloat(0)*1000)
MsgBox CStr(lStr)

' ---- Message class
Class Message
  Private mMSCD   ' MSCD Message ID
  Private mNumString    ' Number of Strings associated with the Message
  Private mNumFloat     ' Number of Floats  Associated with the Message
  Private mStrings()    ' The Strings Associated with the Message
  Private mFloats()  ' The Numerical Values Associated with the Message

  Public Sub SetMSCD(aMSCD)
    mMSCD = aMSCD
  End Sub

  Public Sub SetNumString(aNumString)
    mNumString = aNumString
  End Sub

  Public Sub SetNumFloat(aNumFloat)
    mNumFloat = aNumFloat
  End Sub

  Public Sub AddFloat(aFloat)
    mNumFloat = mNumFloat + 1
    ReDim Preserve mFloats(mNumFloat)
    mFloats(mNumFloat-1) = aFloat
  End Sub

  Public Sub AddString(aString)
    mNumString = mNumString + 1
    ReDim Preserve mStrings(mNumString)
    mStrings(mNumString-1) = aString
  End Sub

  Public Function GetMSCD()
    GetMSCD = mMSCD
  End Function
  Public Function GetString(aIndex)
    GetString = ""
    If aIndex >= 0 And aIndex < mNumString Then
       GetString = mStrings(aIndex)
    End if
  End Function

  Public Function GetFloat(aIndex)
    GetFloat = ""
    If aIndex >= 0 And aIndex < mNumFloat Then
       GetFloat = mFloats(aIndex)
    End if
  End Function

  Public Function GetNumString()
    GetNumString = mNumString
  End Function

  Public Function GetNumFloat()
    GetNumFloat = mNumFloat
  End Function

  Private Sub Class_Initialize
    mMSCD = -1
    mNumString = 0
    mNumFloat = 0
  End Sub
End Class

Class ScreenOutput

 Private mMessages()  ' Array of Messages associate with the screen output File
 Private mNumMessages  ' Number of messages in the screen output file

  Public Function LoadOutputFile(aFile)
    Const ForReading = 1
    Dim FS
    Set FS = CreateObject("Scripting.FileSystemObject")
    Dim File
    Set File = FS.OpenTextFile(aFile, ForReading)
        While Not File.AtEndOfStream
      Dim ID
      ID = -1
        ' Read the MSCD
        Dim Line,lenLine
    Line = File.ReadLine
    lenLine = len(Line)
    If Not File.AtEndOfStream or lenLine >= 1 Then
      ID = Line
      Dim curMessage
      Set curMessage = New Message
      curMessage.SetMSCD(ID)
      ' Read the number of strings
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numString
        numString = Line
        ' Read Strings
        Dim i
        For i = 1 To numString
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
            CurMessage.AddString(Line)
          End if
        Next
      End if
      ' Read the number of floats
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numFloat
        numFloat = Line
        ' Read Floats
        For i = 1 To numFloat
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
           CurMessage.AddFloat(Line)
          End if
        Next
      End If
      ' Add current message to the list
      AddMessage(CurMessage)
    End If
  Wend
    File.Close
  End Function

  Public Sub AddMessage(aMessage)
  mNumMessages = mNumMessages + 1
    ReDim Preserve mMessages(mNumMessages)
    Set mMessages(mNumMessages-1) = aMessage
  End Sub

  Public Function GetNumMessages()
    GetNumMessages = mNumMessages
  End Function

  Public Function GetMessage(aMSCD,aOccur)
    Set GetMessage = Nothing
    Dim j
    Dim lFindInstance
    lFindInstance = aOccur
    If aOccur < 0 Then
      lFindInstance = 0
    End if
    Dim Count
    Count = 0
    For j = 0 To mNumMessages-1
      'MsgBox mMessages(j).GetMSCD &"|"& aMSCD
      If CStr(mMessages(j).GetMSCD) = CStr(aMSCD) Then
         Count = Count + 1
         If Count >= lFindInstance Then
           Set GetMessage = mMessages(j)
           Exit Function
         End if
      End if
    Next
  End Function

  Private Sub Class_Initialize
  mNumMessages = 0
  End Sub
End Class

 


Regards,
Berndt

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
Message 8 of 10
bernor_mf
in reply to: mantd

Hi,
I found your workaround interesting.
Made some improvements, as the id of mesh.out varies.
It basically finds the "*mesh.out" connected to study, and also if not existing.
Paste it in here:

 

'%RunPerInstance
'@
'@ DESCRIPTION
'@ This script shows how to extract information from the screen out (.out) file.
'@ Several examples are shown
'@
'@ This script perfoms a similar function to the studyrlt command
'@ studyrlt  <study> -message <sequence>  <message ID> <occurrence> <item>

'@ Some knowledge of the  format used in the .out file is required.
'@ please see details in the ..../data/dat/cmmesage.dat  for details
'@ Some know of the analysis sequences is required.
'@ please see details in the ..../data/dat/process.dat  for details
'@
'@ SYNTAX
'@ RaadScreenOutput
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@ Assumes a Flow analysis has been run and the required study file is selected and open.
'@ Some knowledge of the MSCD format as defined in message.dat  is required
'@ Limited error checking is performed
'@
'@@
Option Explicit
SetLocale("en-us")
Dim Synergy
Dim SynergyGetter
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
  Set Synergy = SynergyGetter.GetSASynergy
Else
  Set Synergy = CreateObject("amiws.Synergy")
End If

Dim StudyDoc
Set StudyDoc = Synergy.StudyDoc()

Dim fso, lOutName_mesh, StudyName
StudyName = left(StudyDoc.StudyName, len(StudyDoc.StudyName)-4)
Set fso = CreateObject("Scripting.FileSystemObject")

Dim strPattern , StudyNameMesh
strPattern = StudyName & "*mesh.out"
StudyNameMesh = GetFiles( strPattern )
'There should only be one file. Split and read the first.
StudyNameMesh = Split( Mid( StudyNameMesh, 2 ), ";" )
If Not (Ubound(StudyNameMesh)) = -1 Then
    lOutName_mesh = StudyNameMesh(0)
Else
  MsgBox "No mesh output file found.",,"Information"
  Wscript.Quit
End If
 
Function GetFiles( strFilespec )
 
	Dim colFiles, objFile, objFSO, objRE, wshShell
	Dim strFiles, strPattern
 
	' Return "Error" on missing or invalid filespec
	GetFiles = Array( "Error" )
	If Trim( strFilespec ) = ""  Then Exit Function
	If InStr( strFilespec, "\" ) Then Exit Function
 
	Set wshShell = CreateObject( "WScript.Shell" )
	Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
	Set objRE    = New RegExp
 
	' Convert DOS wildcards to regex pattern
	objRE.Pattern    = "([\.\(\)\[\]\{\}\$])"
	objRE.Global     = True
	objRE.IgnoreCase = True
	strPattern       = objRE.Replace( strFilespec, "\$1" )
	strPattern       = Replace( strPattern,  "?", "[^\\]"  )
	strPattern       = Replace( strPattern,  "*", "[^\\]*" )
	objRE.Pattern    = "(^|\\)" & strPattern & "$"
 
	' Get a collection of files
	Set colFiles  = objFSO.GetFolder( wshShell.CurrentDirectory ).Files
	strFiles = ""
	' Iterate through the list of files
	For Each objFile In colFiles
		' Check if the file name matches filespec
		If objRE.Test( objFile.Path ) Then
			' Add the file to the list
			strFiles = strFiles & ";" & objFile.Name
		End If
	Next
 
	' Return the list of files as an array
	'GetFiles = Split( Mid( strFiles, 2 ), ";" )
	GetFiles = strFiles

	' Cleanup
	Set colFiles  = Nothing
	Set objRE     = Nothing
	Set objFSO    = Nothing
	Set wshShell  = Nothing
End Function


' Create and Populate the ScreenOutput Class for lOutName_mesh
Dim lMessages_mesh
Set lMessages_mesh = New ScreenOutput
lMessages_mesh.LoadOutputFile(lOutName_mesh)

Dim MM, lStr

'MSCD 1902003 1 0 0 0 0 0 1
'      Global edge length:                                   %11.4G
'    m,1,1
Set MM = lMessages_mesh.GetMessage(1902003,0)
lStr = "Global edge = " & CStr(MM.GetFloat(0)*1000)
MsgBox CStr(lStr)

' ---- Message class
Class Message
  Private mMSCD   ' MSCD Message ID
  Private mNumString    ' Number of Strings associated with the Message
  Private mNumFloat     ' Number of Floats  Associated with the Message
  Private mStrings()    ' The Strings Associated with the Message
  Private mFloats()  ' The Numerical Values Associated with the Message

  Public Sub SetMSCD(aMSCD)
    mMSCD = aMSCD
  End Sub

  Public Sub SetNumString(aNumString)
    mNumString = aNumString
  End Sub

  Public Sub SetNumFloat(aNumFloat)
    mNumFloat = aNumFloat
  End Sub

  Public Sub AddFloat(aFloat)
    mNumFloat = mNumFloat + 1
    ReDim Preserve mFloats(mNumFloat)
    mFloats(mNumFloat-1) = aFloat
  End Sub

  Public Sub AddString(aString)
    mNumString = mNumString + 1
    ReDim Preserve mStrings(mNumString)
    mStrings(mNumString-1) = aString
  End Sub

  Public Function GetMSCD()
    GetMSCD = mMSCD
  End Function
  Public Function GetString(aIndex)
    GetString = ""
    If aIndex >= 0 And aIndex < mNumString Then
       GetString = mStrings(aIndex)
    End if
  End Function

  Public Function GetFloat(aIndex)
    GetFloat = ""
    If aIndex >= 0 And aIndex < mNumFloat Then
       GetFloat = mFloats(aIndex)
    End if
  End Function

  Public Function GetNumString()
    GetNumString = mNumString
  End Function

  Public Function GetNumFloat()
    GetNumFloat = mNumFloat
  End Function

  Private Sub Class_Initialize
    mMSCD = -1
    mNumString = 0
    mNumFloat = 0
  End Sub
End Class

Class ScreenOutput

 Private mMessages()  ' Array of Messages associate with the screen output File
 Private mNumMessages  ' Number of messages in the screen output file

  Public Function LoadOutputFile(aFile)
    Const ForReading = 1
    Dim FS
    Set FS = CreateObject("Scripting.FileSystemObject")
    Dim File
    Set File = FS.OpenTextFile(aFile, ForReading)
        While Not File.AtEndOfStream
      Dim ID
      ID = -1
        ' Read the MSCD
        Dim Line,lenLine
    Line = File.ReadLine
    lenLine = len(Line)
    If Not File.AtEndOfStream or lenLine >= 1 Then
      ID = Line
      Dim curMessage
      Set curMessage = New Message
      curMessage.SetMSCD(ID)
      ' Read the number of strings
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numString
        numString = Line
        ' Read Strings
        Dim i
        For i = 1 To numString
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
            CurMessage.AddString(Line)
          End if
        Next
      End if
      ' Read the number of floats
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numFloat
        numFloat = Line
        ' Read Floats
        For i = 1 To numFloat
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
           CurMessage.AddFloat(Line)
          End if
        Next
      End If
      ' Add current message to the list
      AddMessage(CurMessage)
    End If
  Wend
    File.Close
  End Function

  Public Sub AddMessage(aMessage)
  mNumMessages = mNumMessages + 1
    ReDim Preserve mMessages(mNumMessages)
    Set mMessages(mNumMessages-1) = aMessage
  End Sub

  Public Function GetNumMessages()
    GetNumMessages = mNumMessages
  End Function

  Public Function GetMessage(aMSCD,aOccur)
    Set GetMessage = Nothing
    Dim j
    Dim lFindInstance
    lFindInstance = aOccur
    If aOccur < 0 Then
      lFindInstance = 0
    End if
    Dim Count
    Count = 0
    For j = 0 To mNumMessages-1
      'MsgBox mMessages(j).GetMSCD &"|"& aMSCD
      If CStr(mMessages(j).GetMSCD) = CStr(aMSCD) Then
         Count = Count + 1
         If Count >= lFindInstance Then
           Set GetMessage = mMessages(j)
           Exit Function
         End if
      End if
    Next
  End Function

  Private Sub Class_Initialize
  mNumMessages = 0
  End Sub
End Class


Regards,
Berndt

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
Message 9 of 10
bernor_mf
in reply to: bernor_mf

@mantd 

Hi,
I found your workaround interesting.
Made some improvements, as the id of mesh.out varies.
It basically finds the "*mesh.out" connected to study, and also if not existing.
Paste it in here:

'%RunPerInstance
'@
'@ DESCRIPTION
'@ This script shows how to extract information from the screen out (.out) file.
'@ Several examples are shown
'@
'@ This script perfoms a similar function to the studyrlt command
'@ studyrlt  <study> -message <sequence>  <message ID> <occurrence> <item>

'@ Some knowledge of the  format used in the .out file is required.
'@ please see details in the ..../data/dat/cmmesage.dat  for details
'@ Some know of the analysis sequences is required.
'@ please see details in the ..../data/dat/process.dat  for details
'@
'@ SYNTAX
'@ RaadScreenOutput
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@ Assumes a Flow analysis has been run and the required study file is selected and open.
'@ Some knowledge of the MSCD format as defined in message.dat  is required
'@ Limited error checking is performed
'@
'@@
Option Explicit
SetLocale("en-us")
Dim Synergy
Dim SynergyGetter
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
  Set Synergy = SynergyGetter.GetSASynergy
Else
  Set Synergy = CreateObject("amiws.Synergy")
End If

Dim StudyDoc
Set StudyDoc = Synergy.StudyDoc()

Dim fso, lOutName_mesh, StudyName
StudyName = left(StudyDoc.StudyName, len(StudyDoc.StudyName)-4)
Set fso = CreateObject("Scripting.FileSystemObject")

Dim strPattern , StudyNameMesh
strPattern = StudyName & "*mesh.out"
StudyNameMesh = GetFiles( strPattern )
'There should only be one file. Split and read the first.
StudyNameMesh = Split( Mid( StudyNameMesh, 2 ), ";" )
If Not (Ubound(StudyNameMesh)) = -1 Then
    lOutName_mesh = StudyNameMesh(0)
Else
  MsgBox "No mesh output file found.",,"Information"
  Wscript.Quit
End If
 
Function GetFiles( strFilespec )
 
	Dim colFiles, objFile, objFSO, objRE, wshShell
	Dim strFiles, strPattern
 
	' Return "Error" on missing or invalid filespec
	GetFiles = Array( "Error" )
	If Trim( strFilespec ) = ""  Then Exit Function
	If InStr( strFilespec, "\" ) Then Exit Function
 
	Set wshShell = CreateObject( "WScript.Shell" )
	Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
	Set objRE    = New RegExp
 
	' Convert DOS wildcards to regex pattern
	objRE.Pattern    = "([\.\(\)\[\]\{\}\$])"
	objRE.Global     = True
	objRE.IgnoreCase = True
	strPattern       = objRE.Replace( strFilespec, "\$1" )
	strPattern       = Replace( strPattern,  "?", "[^\\]"  )
	strPattern       = Replace( strPattern,  "*", "[^\\]*" )
	objRE.Pattern    = "(^|\\)" & strPattern & "$"
 
	' Get a collection of files
	Set colFiles  = objFSO.GetFolder( wshShell.CurrentDirectory ).Files
	strFiles = ""
	' Iterate through the list of files
	For Each objFile In colFiles
		' Check if the file name matches filespec
		If objRE.Test( objFile.Path ) Then
			' Add the file to the list
			strFiles = strFiles & ";" & objFile.Name
		End If
	Next
 
	' Return the list of files as an array
	'GetFiles = Split( Mid( strFiles, 2 ), ";" )
	GetFiles = strFiles

	' Cleanup
	Set colFiles  = Nothing
	Set objRE     = Nothing
	Set objFSO    = Nothing
	Set wshShell  = Nothing
End Function


' Create and Populate the ScreenOutput Class for lOutName_mesh
Dim lMessages_mesh
Set lMessages_mesh = New ScreenOutput
lMessages_mesh.LoadOutputFile(lOutName_mesh)

Dim MM, lStr

'MSCD 1902003 1 0 0 0 0 0 1
'      Global edge length:                                   %11.4G
'    m,1,1
Set MM = lMessages_mesh.GetMessage(1902003,0)
lStr = "Global edge = " & CStr(MM.GetFloat(0)*1000)
MsgBox CStr(lStr)

' ---- Message class
Class Message
  Private mMSCD   ' MSCD Message ID
  Private mNumString    ' Number of Strings associated with the Message
  Private mNumFloat     ' Number of Floats  Associated with the Message
  Private mStrings()    ' The Strings Associated with the Message
  Private mFloats()  ' The Numerical Values Associated with the Message

  Public Sub SetMSCD(aMSCD)
    mMSCD = aMSCD
  End Sub

  Public Sub SetNumString(aNumString)
    mNumString = aNumString
  End Sub

  Public Sub SetNumFloat(aNumFloat)
    mNumFloat = aNumFloat
  End Sub

  Public Sub AddFloat(aFloat)
    mNumFloat = mNumFloat + 1
    ReDim Preserve mFloats(mNumFloat)
    mFloats(mNumFloat-1) = aFloat
  End Sub

  Public Sub AddString(aString)
    mNumString = mNumString + 1
    ReDim Preserve mStrings(mNumString)
    mStrings(mNumString-1) = aString
  End Sub

  Public Function GetMSCD()
    GetMSCD = mMSCD
  End Function
  Public Function GetString(aIndex)
    GetString = ""
    If aIndex >= 0 And aIndex < mNumString Then
       GetString = mStrings(aIndex)
    End if
  End Function

  Public Function GetFloat(aIndex)
    GetFloat = ""
    If aIndex >= 0 And aIndex < mNumFloat Then
       GetFloat = mFloats(aIndex)
    End if
  End Function

  Public Function GetNumString()
    GetNumString = mNumString
  End Function

  Public Function GetNumFloat()
    GetNumFloat = mNumFloat
  End Function

  Private Sub Class_Initialize
    mMSCD = -1
    mNumString = 0
    mNumFloat = 0
  End Sub
End Class

Class ScreenOutput

 Private mMessages()  ' Array of Messages associate with the screen output File
 Private mNumMessages  ' Number of messages in the screen output file

  Public Function LoadOutputFile(aFile)
    Const ForReading = 1
    Dim FS
    Set FS = CreateObject("Scripting.FileSystemObject")
    Dim File
    Set File = FS.OpenTextFile(aFile, ForReading)
        While Not File.AtEndOfStream
      Dim ID
      ID = -1
        ' Read the MSCD
        Dim Line,lenLine
    Line = File.ReadLine
    lenLine = len(Line)
    If Not File.AtEndOfStream or lenLine >= 1 Then
      ID = Line
      Dim curMessage
      Set curMessage = New Message
      curMessage.SetMSCD(ID)
      ' Read the number of strings
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numString
        numString = Line
        ' Read Strings
        Dim i
        For i = 1 To numString
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
            CurMessage.AddString(Line)
          End if
        Next
      End if
      ' Read the number of floats
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numFloat
        numFloat = Line
        ' Read Floats
        For i = 1 To numFloat
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
           CurMessage.AddFloat(Line)
          End if
        Next
      End If
      ' Add current message to the list
      AddMessage(CurMessage)
    End If
  Wend
    File.Close
  End Function

  Public Sub AddMessage(aMessage)
  mNumMessages = mNumMessages + 1
    ReDim Preserve mMessages(mNumMessages)
    Set mMessages(mNumMessages-1) = aMessage
  End Sub

  Public Function GetNumMessages()
    GetNumMessages = mNumMessages
  End Function

  Public Function GetMessage(aMSCD,aOccur)
    Set GetMessage = Nothing
    Dim j
    Dim lFindInstance
    lFindInstance = aOccur
    If aOccur < 0 Then
      lFindInstance = 0
    End if
    Dim Count
    Count = 0
    For j = 0 To mNumMessages-1
      'MsgBox mMessages(j).GetMSCD &"|"& aMSCD
      If CStr(mMessages(j).GetMSCD) = CStr(aMSCD) Then
         Count = Count + 1
         If Count >= lFindInstance Then
           Set GetMessage = mMessages(j)
           Exit Function
         End if
      End if
    Next
  End Function

  Private Sub Class_Initialize
  mNumMessages = 0
  End Sub
End Class


Regards,
Berndt

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
Message 10 of 10
bernor_mf
in reply to: mantd

@mantd 

Hi,
I found your workaround interesting.
Made some improvements, as the id of mesh.out varies.
It basically finds the "*mesh.out" connected to study, and also if not existing.
Paste it piece of code in here:

Dim StudyDoc
Set StudyDoc = Synergy.StudyDoc()

Dim fso, lOutName_mesh, StudyName
StudyName = left(StudyDoc.StudyName, len(StudyDoc.StudyName)-4)
Set fso = CreateObject("Scripting.FileSystemObject")

Dim strPattern , StudyNameMesh
strPattern = StudyName & "*mesh.out"
StudyNameMesh = GetFiles( strPattern )
'There should only be one file. Split and read the first.
StudyNameMesh = Split( Mid( StudyNameMesh, 2 ), ";" )
If Not (Ubound(StudyNameMesh)) = -1 Then
 
  lOutName_mesh = StudyNameMesh(0)
Else
  MsgBox "No mesh output file found.",,"Information"
  Wscript.Quit
End If
 
Function GetFiles( strFilespec )
 
	Dim colFiles, objFile, objFSO, objRE, wshShell
	Dim strFiles, strPattern
 
	' Return "Error" on missing or invalid filespec
	GetFiles = Array( "Error" )
	If Trim( strFilespec ) = ""  Then Exit Function
	If InStr( strFilespec, "\" ) Then Exit Function
 
	Set wshShell = CreateObject( "WScript.Shell" )
	Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
	Set objRE    = New RegExp
 
	' Convert DOS wildcards to regex pattern
	objRE.Pattern    = "([\.\(\)\[\]\{\}\$])"
	objRE.Global     = True
	objRE.IgnoreCase = True
	strPattern       = objRE.Replace( strFilespec, "\$1" )
	strPattern       = Replace( strPattern,  "?", "[^\\]"  )
	strPattern       = Replace( strPattern,  "*", "[^\\]*" )
	objRE.Pattern    = "(^|\\)" & strPattern & "$"
 
	' Get a collection of files
	Set colFiles  = objFSO.GetFolder( wshShell.CurrentDirectory ).Files
	strFiles = ""
	' Iterate through the list of files
	For Each objFile In colFiles
		' Check if the file name matches filespec
		If objRE.Test( objFile.Path ) Then
			' Add the file to the list
			strFiles = strFiles & ";" & objFile.Name
		End If
	Next
 
	' Return the list of files as an array
	'GetFiles = Split( Mid( strFiles, 2 ), ";" )
	GetFiles = strFiles

	' Cleanup
	Set colFiles  = Nothing
	Set objRE     = Nothing
	Set objFSO    = Nothing
	Set wshShell  = Nothing
End Function


Regards,
Berndt

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report