Message 1 of 2
Replacing multiple Model References in .idw by referencing a spreadsheet.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have been using the code below to replace the model reference for a part file on a single sheet drawing then saving the drawing as that number.
This code works well but, what I would like to be able to do is modify the code to replace multiple references on several sheets, where each sheet contains a different model which could be an assembly or a part file.
Each sheet would only contain a single model reference and the save as would be the first model reference from Sheet 1, although this is the least important part of the process as can be manually saved once references have been replaced.
Dim oFileDlg As Inventor.FileDialog
ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Microsoft Excel Files (*.xlsx; *.xls)|*.xlsx;*.xls|"
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim oFD As FileDescriptor
oFD = openDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
'define the XLS to look at
myXLS = "C:\Local Folder\my_Spreadsheet.xlsx"
''uncomment the line below to open the spreadsheet but would need to change the name
''GoExcel.Open(myXLS, "")
'define the correct columns, rows and cells
myOriginalNumberColumn = "UK_Part_Number"
myNewNumberColumn = "A"
'Define the Original Part Number
myNumber = iProperties.Value(openDoc,"Project", "Part Number")
'find the row containing the original part number
myRow = GoExcel.FindRow(myXLS, "Sheet1", myOriginalNumberColumn, "=", myNumber)
'find the corresponding New Number cell
myCell = GoExcel.CellValue(myXLS, "Sheet1", myNewNumberColumn & myRow)
Dim myCellString As String = myCell
'replace model reference with new version
oFD.ReplaceReference("C:\Local Folder\" & myCell & ".ipt")
openDoc.Update()
'save off a copy
ThisDoc.Document.SaveAs(ThisDoc.Path & "\" & myCell & ".idw", True)
Has anybody attempted similar who could offer any assistance please?