- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have an adapted rule from a previous discussion, Re: File rename popup that renames parts when placed into assemblies. I have adapted it to rename a sub assembly when placed into the main assembly. What I need is to either trigger the "Rename" rule to run in the sub assembly's parts when it runs in the assembly or, if possible, have the assembly rule also rename the parts.
To avoid confusion I should mention that the assembly is a door with two parts, a frame and a door. There are also many accessories but they do not require renaming as they are static add-ons.
Here is the code being used on the assembly
Code Snippet
Imports System.IO '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 (*.iam)|*.iam" 'set the directory to open the dialog at oFileDlg.InitialDirectory = ThisDoc.WorkspacePath() Dim fileName As String = "DW-" & 1 & ".iam" Dim fInfo As FileInfo() Dim dirInfo As New DirectoryInfo(oFileDlg.InitialDirectory) fInfo = dirInfo.GetFiles() Dim i As Integer = 1 Dim file As FileInfo Reiterate:For Each file In fInfo If file.Name = fileName Then i = i + 1 fileName = "DW-" & i & ".iam" Goto Reiterate End If Next 'set the file name string to use in the input box oFileDlg.FileName = fileName '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
And the code for one of the parts within the assembly.
Code Snippet
Imports System.IO '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() Dim fileName As String = "Frame-" & 1 & ".ipt" Dim fInfo As FileInfo() Dim dirInfo As New DirectoryInfo(oFileDlg.InitialDirectory) fInfo = dirInfo.GetFiles() Dim i As Integer = 1 Dim file As FileInfo Reiterate:For Each file In fInfo If file.Name = fileName Then i = i + 1 fileName = "Frame-" & i & ".ipt" Goto Reiterate End If Next 'set the file name string to use in the input box oFileDlg.FileName = fileName '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
As you can see they are nearly identical, My attempts at triggering the ipt rule from the iam have been unsuccessful and since there may be other doors with frame names containing the same extension number this may not be the best way to go anyway, unless I can transfer the extension number from the assembly to the part.
Solved! Go to Solution.