02-13-2023
09:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
02-13-2023
09:17 PM
Here is a method to do this. It will rely on finding a filename within a column and then with the new row determined by the form (parameter change) select a new file name and replace this occurrence. Note replacing occurrence will need a fullfilename, path and filename including extension.
Dim asmDoc As AssemblyDocument = ThisDoc.Document
Dim compDef As AssemblyComponentDefinition = asmDoc.ComponentDefinition
Dim Occs As ComponentOccurrences = compDef.Occurrences
Dim excelFileLocation As String = "********\End Suction Pump Drawings\Pumps\Pump Layout Spreadsheet Test.xlsx"
'Automatic setting of Pump Model.
MultiValue.List("PumpModel") = GoExcel.CellValues(excelFileLocation, "Sheet1", "A2", "A10")
'Intial List creation to ensure list not blank on creation.
If PumpModel = "" Then
PumpModel = MultiValue.List("PumpModel").Item(0)
End If
Dim NewRow1 As Integer = GoExcel.FindRow(excelFileLocation, "Sheet1", "Pump Model", "=", PumpModel)
If NewRow1 = -1 Then MessageBox.Show("Error retrieving row, exiting", "Error Check") : Return
Dim OldFileName1 As String
Dim NewFileName1 As String
For Each Occ As ComponentOccurrence In Occs
Dim FileName As String = System.IO.Path.GetFileName(Occ.Definition.Document.FullFileName)
Dim Path As String = System.IO.Path.GetDirectoryName(Occ.Definition.Document.FullFileName)
'[Occurrence(1) replace
'Check if occurrence filename is in the correct column, so we change the right occurrence.
Dim OldRow1 As Integer = GoExcel.FindRow(excelFileLocation, "Sheet1", "Volute", "=", FileName)
If OldRow1 = -1 Then MessageBox.Show("Error retrieving row, exiting", "Error Check") : Return
OldFileName1 = GoExcel.CellValue(excelFileLocation, "Sheet1", "B" & OldRow1)
If FileName = OldFileName1 Then
NewFileName1 = GoExcel.CellValue(excelFileLocation, "Sheet1", "B" & NewRow1)
Logger.Info("Path: " & Path)
Logger.Info("NewRow: " & NewRow1)
Logger.Info("OldRow: " & OldRow1)
Logger.Info("FileName: " & FileName)
Logger.Info("OldFileName: " & OldFileName1)
Logger.Info("NewFileName: " & NewFileName1)
Try
Occ.Replace(Path & "\" & NewFileName1, False)
Catch
End Try
End If
'[
'[Occurrence(2) replace
'Copy first structure and rename variables
']
Next
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan
Or if this helped you, please, click (like)
Regards
Alan