- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is actually an extension of another post Prompted name change when placing parts in an assembly hat has been resolved, now I would like to expand on.
I have been asked to see if I can get Inventor to automatically provide a new name extension # when placing the component in the assembly.
The component name structure is setup with a prefix "S-C-" with the component # "1" ending with an identifier "Metal", this is an example of a "Metal Screed Corner" The name structure cannot be changed our to our automatic BOM generator, we only change the component #.
I would need a bit of code that can look at the files in the destination folder, compare them and update the component # to the next available.
The code I have now looks like this and is linked to a form with a rename button and is set to activate when the component is placed into an assembly.
Code Snippet
'define the active document oDoc = ThisDoc.Document 'create a file dialog box Dim oFileDlg As inventor.FileDialog = Nothing InventorVb.Application.CreateFileDialog(oFileDlg) 'set the assembly part name to = filename oDoc.DisplayName = "" 'set Part type oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt" 'set the directory to open the dialog at oFileDlg.InitialDirectory = ThisDoc.WorkspacePath() 'check occurance of "S-C-1-Metal" need to look for the #'Change the # to the next available # 'set the file name string to use in the input box (using the next available # in place if +1) oFileDlg.FileName = "S-C-" & +1 & "-Metal" 'check occurance of "S-C-1-Metal" need to look for the #'Change the # to the next available # 'work with an error created by the user backing out of the save oFileDlg.CancelError = True On Error Resume Next 'specify the file dialog as a save dialog (rather than a open dialog) oFileDlg.ShowSave() 'catch an empty string in the imput If Err.Number <> 0 Then MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled") ElseIf oFileDlg.FileName <> "" Then MyFile = oFileDlg.FileName 'save the file oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As End If
I have the filename set to insert a "1" into the filename but would like it to change to a "2" if "1" is in use and so on.
I have a couple of extra lines describing what I would like to add.
Any ideas?
Solved! Go to Solution.