Memory Usage Apprentice (will not close an opened file)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear All,
I'm making a rule that compares some info between two folders with the same part(name)s.
The rule does what it has to do. (i've tested the rule with smaller folders)
The real comparison is between two folders.
- 4286 stp-files
- 29.510 ipt-files
There are two problems that I run into:
1. Mainproblem: (second part of the rule) it opens the file with Apprentice, but it doesn't close it. After approx.4000 files my system memory is used 100% and goes very slow till it eventually crashes at approx 7000 files. (As seen in the picture you can see that the parts counter in the right bottom corner is going up)
2. Small thing I don't like: (First part of the rule) normally when closing ipt-files I used "oFile.Close" but this doesn't seem to work with opened stp-files. So now I use "ThisApplication.ActiveDocument.Close(True)" This works but if, for some reason, the file with the rule becomes the active document. It will close that with a catastrophic failure. Is there a way to still use a kind of "oFile.Close" so that I am sure the stp-file is closed?
'Name of Rule: Compare_stp_vs_ipt(EXCEL) '---------------------------------------------------------------------------- 'Tooltip: Tool to compare stp-files with parts '---------------------------------------------------------------------------- 'Needed for subdirectories Imports System.IO 'Define stuff Dim oList_stp As New List(Of String) Dim oList_ipt As New List(Of String) Dim oListResults As New List(Of String) Dim oListFaults As New List(Of String) Dim oProcessPath_stp As String Dim oProcessPath_ipt As String Dim invApprentice As New Inventor.ApprenticeServerComponent 'Location+Name Log file oExceldoc = "C:\20190129 - Compare_stp-ipt\Log_V5_(Excel).xlsx" 'Location Step-files oProcessPath_stp = "C:\20190129 - Compare_stp-ipt\Step-files" 'Location ipt-files oProcessPath_ipt = "C:\20190129 - Compare_stp-ipt\ipt-files" '[ Get Information stp-files 'Get the files in the specified directory For Each oDir In System.IO.Directory.GetDirectories(oProcessPath_stp) For Each oFilename In System.IO.Directory.GetFiles(oDir & "\", "*.stp") 'Don't process this folder If oFilename.IndexOf("05=CW-panels and Frameworks") = -1 Then 'True = Opens visible 'False = Opens unvisible oFile = ThisApplication.Documents.Open(oFilename, True) Try Dim oPartDoc As PartDocument oPartDoc = oFile oPartDoc.ComponentDefinition.Material = oPartDoc.Materials("Default") 'Update iProperties Physical ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute 'Get Partnumber Try oPartnumber = oFile.Displayname Catch oPartnumber = "" End Try 'Get Mass Try oMass = Round(oFile.PropertySets.Item("Design Tracking Properties").Item("Mass").Value, 9) Catch oMass = "" End Try 'Get Area Try oArea = Round(oFile.PropertySets.Item("Design Tracking Properties").Item("SurfaceArea").Value, 9) Catch oArea = "" End Try 'Get Volume Try oVolume = Round(oFile.PropertySets.Item("Design Tracking Properties").Item("Volume").Value, 9) Catch oVolume = "" End Try 'PrincipalMomentsOfInertia (3) 'XYZMomentsOfInertia (6) Dim Moment(2) As Double oFile.ComponentDefinition.MassProperties.PrincipalMomentsOfInertia (Moment(0), Moment(1), Moment(2)) 'Get Inertial Properties: Principal Moments: I1 Try oPM1 = CStr(Round(Moment(0), 8)) Catch oPM1 = "" End Try 'Get Inertial Properties: Principal Moments: I2 Try oPM2 = CStr(Round(Moment(1), 8)) Catch oPM2 = "" End Try 'Get Inertial Properties: Principal Moments: I3 Try oPM3 = CStr(Round(Moment(2), 8)) Catch oPM3 = "" End Try oArguments = oPartnumber & "/" & oMass & "/" & oArea & "/" & oVolume & "/" & oPM1 & "/" & oPM2 & "/" & oPM3 oList_stp.Add(oArguments) Catch oListFaults.Add(oFilename) End Try 'close the file 'oFile.Close 'doesn't work in opened stp-files ThisApplication.ActiveDocument.Close(True) 'Second option End If Next Next oList_stp.sort() '] MessageBox.Show(oList_stp.Count & " stp-files are processed, Now ipt-files will start", "Title") '[ Get information ipt-files 'Get the files in the specified directory For Each oDir In System.IO.Directory.GetDirectories(oProcessPath_ipt) For Each oFilename In System.IO.Directory.GetFiles(oDir & "\", "*.ipt") If oFilename.IndexOf("OldVersions") = -1 Then Try oFile = invApprentice.Open(oFilename) Dim oPartDoc As PartDocument oPartDoc = oFile TempMaterial = oPartDoc.ComponentDefinition.Material.Name 'Get Current material oPartDoc.ComponentDefinition.Material = oPartDoc.Materials("Default") 'Temporary change Material 'Update iProperties Physical ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute 'Get Partnumber Try oPartnumber = oFile.Displayname Catch oPartnumber = "" End Try 'Get Path Try oPath = oFilename Catch oPath = "" End Try 'Get Mass Try oMass = Round(oFile.PropertySets.Item("Design Tracking Properties").Item("Mass").Value, 9) Catch oMass = "" End Try 'Get Area Try oArea = Round(oFile.PropertySets.Item("Design Tracking Properties").Item("SurfaceArea").Value, 9) Catch oArea = "" End Try 'Get Volume Try oVolume = Round(oFile.PropertySets.Item("Design Tracking Properties").Item("Volume").Value, 9) Catch oVolume = "" End Try 'PrincipalMomentsOfInertia (3) 'XYZMomentsOfInertia (6) Dim Moment(2) As Double oFile.ComponentDefinition.MassProperties.PrincipalMomentsOfInertia (Moment(0), Moment(1), Moment(2)) 'Get Inertial Properties: Principal Moments: I1 Try oPM1 = CStr(Round(Moment(0), 8)) Catch oPM1 = "" End Try 'Get Inertial Properties: Principal Moments: I2 Try oPM2 = CStr(Round(Moment(1), 8)) Catch oPM2 = "" End Try 'Get Inertial Properties: Principal Moments: I3 Try oPM3 = CStr(Round(Moment(2), 8)) Catch oPM3 = "" End Try oArguments = oPartnumber & "[" & oPath & "]" & "/" & oMass & "/" & oArea & "/" & oVolume & "/" & oPM1 & "/" & oPM2 & "/" & oPM3 oList_ipt.Add(oArguments) 'Put old material back oPartDoc.ComponentDefinition.Material = oPartDoc.Materials(TempMaterial) Catch oListFaults.add(oFilename) End Try 'close the file invApprentice.Close() End If Next Next oList_ipt.sort() '] '[ Compare For Each oSTP In oList_stp For Each oIPT In oList_ipt If Left(oSTP,18) = Left(oIPT,18) And oSTP.Remove(0,oSTP.IndexOf("/")) <> oIPT.Remove(0,oIPT.IndexOf("/")) Then 'If Name = Name and /iProp <> /iProp oListResults.Add(oIPT.Remove(oIPT.IndexOf("/")) & " < < Is not the same as > > " & Left(oSTP,18)) End If Next Next oListResults.sort() '] '[ Put results in Excel oCell = 1 'Where the Magic Happens For Each oListResult In oListResults GoExcel.CellValue(oExceldoc,"Sheet1", "A" & oCell) = oListResult oCell = oCell + 1 Next '----------------------------------------------------------------------- 'Uncomment below if you want to put information all parts to excel (Can take more time) oCell = 1 'Where the Magic Happens For Each oSTP In oList_stp GoExcel.CellValue(oExceldoc,"Sheet2", "A" & oCell) = oSTP oCell = oCell + 1 Next oCell = 1 'Where the Magic Happens For Each oIPT In oList_ipt GoExcel.CellValue(oExceldoc,"Sheet3", "A" & oCell) = oIPT oCell = oCell + 1 Next oCell = 1 'Where the Magic Happens For Each oFault In oListFaults GoExcel.CellValue(oExceldoc,"Sheet4", "A" & oCell) = oFault oCell = oCell + 1 Next '-------------------------------------------------------------------------- GoExcel.Save GoExcel.Close '] 'Tool to open the created excel booleanParam = InputRadioBox("Do you want to open the list?", "Yes", "No", booleanParam, Title := "List is Done") If booleanParam = True Then ThisDoc.Launch(oExceldoc) End If