When you replace revised components in your assembly using the Replace or Replace All tools, you find yourself needing to browse through a lot of folders. You'd like to create an iLogic rule to look at the same folder path as the file being replaced.
Solution:
Here is a sample rule that uses the folder path and file name of a selected component to look for the next revision level. The input box defaults to 1+ the selected revision level, but allows the user to input any number. A Yes/No message allows the user to see exactly what file is to replace the selected one. If the file is not found a message is displayed.
I set this rule up as an External Rule, and run the rule while editing a top level assembly.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1yBC5GkeCY3X4AyGh4VvTysQZRjXWisXjaTbtW2mehRuuCOVkib_19wO2vstVmxx1ym2UJeYyKDotG8SBxHjtXZsH9svgmWdLFzilVbYOfc9bHZiJ1AZElxG9S1wU2UU5AYFPH2RzYMJs/s1600/Autodesk+Inventor+iLogic+Replace+Revision+1.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYtX_2vsU8-IYTk_ExwfdRnvw2D9q5cJON9scwPOhTTTYga9PnmI5dVbHLiRXCj49SIaVMfCZNxGhKIiZvTuQqErbC0YCYQ9IvYwRjtA85FzR0aDiHMMMpYP7b6Sf0XCw-0_l-rgl-iH-q/s1600/Autodesk+Inventor+iLogic+Replace+Revision+0.png)
When a file is pre-selected and the rule is run, I am greeted with an input box asking for the revision level to replace the selected file with. The input defaults to 1+ the value of the selected file's revision level:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPzyV05XDIeaw0zt3MtZOtRaZCgtLTUZ-8yOu3ozEcNMdukmvKsKr8AVAtq3JoAVdJOBN81NzxMWJ1notrKCfQoiXgkLhlcUMhPR361mOq3HAGI-f570nHXGJg76aDXxBhRH5_QwbNS6gm/s1600/Autodesk+Inventor+iLogic+Replace+Revision+2.png)
Next a message displays the file path and name of the selected file and the revised file that will replace it:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpwFJCtwE-MPRg-z-gt4pWXxhlFa-oWb2tmiSt-1zjHQEZYSNc4NfIiDY3vkMtKAY3iDAfiXIxNu94aZBBbPkGPQJxtyYyjxP-J5Lwu1DIA9aHDFT7bS-toNl9W5EaG5Ta-rf9r_Wgub7p/s1600/Autodesk+Inventor+iLogic+Replace+Revision+3.png)
When I click Yes, the replacement is made.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBUeVzR0jkuUa58GujJz2CB32kYCP5PAF1voke7WK9HbelSzjkmaoJVNfczypnRtB1fCIiOQuk3mrSfQ0UgyVXJLFh0GCbxAiKIWI_yGO_9K429hia-F8UqxNe4dFRYExWlObUPveNerLa/s1600/Autodesk+Inventor+iLogic+Replace+Revision+6.png)
In the event that I enter a revision level that creates a path to a file that does not exist, I receive a message telling me about it:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhWHhKh6RZ9gfG8AXGdAXYOCedj5aFeOaPUjpULPLqMF_4vSx05tHSaPImIThUQvfHUv-mWqonBtxyz3HhmRVFq5H6fDtMDQj0Z4RC_P-ZdmVP9FZmNOua288Tn2nstRWh3onUkGFDm2O_/s1600/Autodesk+Inventor+iLogic+Replace+Revision+4.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPGjQca5e53V02c3reecceV59D5VUg19YV1BQSTHxa4FSzIMvE1uy9BSV7yUlgW1g_B3LAM8njiOaQyL9marqaJ_20NuIbcOXseIfnBwRSx_aAkysmd0T-YCa9pHpRmr0HEynwAh7K7tzv/s1600/Autodesk+Inventor+iLogic+Replace+Revision+5.png)
Although I've used the file path and name to get the revision level in this example, I could have used the revision iProperty to pull in the revision level as well.
Here is the example rule:
'----start of ilogic code-------
'get currently selected component
Dim oOccurrence as ComponentOccurrence
Try
oOccurrence = ThisDoc.Document.SelectSet.Item(1)
Catch
MessageBox.Show("Please select a component before running this rule.", "iLogic")
Return
End Try
Dim doc As Document
Dim CurFileName As String
Dim NewFileName As String
'set the selected item
oOccurrence = ThisApplication.ActiveDocument.SelectSet.Item(1)
'get the selected item document occurrence name
doc = oOccurrence.Definition.Document
'get the path and file name of the selected item
CurFileName = doc.FullFileName
'defines backslash as the subdirectory separator
Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
'set array for each folder name found between backslashes in the source directory path
Dim oPathItems() As Object = CurFileName.Split(strCharSep)
'parse the path of the file, to get the folder names
'Example: N:\12-3456-78\Design Outputs\Rev #
Dim strDrive As String = oPathItems(0)‘returns N:
Dim strPN As String = oPathItems(1)'returns: 12-3456-78
Dim strOutputs As String = oPathItems(2)'returns: Design Outputs
Dim strOrigRevNum As String = oPathItems(3) 'returns: Rev #
Dim intOrigRevNum As Integer = Mid(strOrigRevNum,5) 'returns #
Dim strExt As String = LCase(System.IO.Path.GetExtension(CurFileName)) 'File Extension
‘get new Revision Number
'default input is 1+ the existing revison number, but any number can be input
Dim strRevNum As String = InputBox("Enter New Rev Number", “iLogic", intOrigRevNum +1)
if strRevNum = “” Then
Return
Else
End if
‘compile new name
NewFileName = strDrive & “\” & strPN & “\” &strOutputs & “\Rev ” _
& strRevNum & “\” & strPN & “ Rev “ & strRevNum & strExt
'check to see if the new revision level file exists
If(Not My.Computer.FileSystem.FileExists(NewFileName)) Then
MessageBox.Show(NewFileName & vbLF & “ does not exist.”, "File Does Not Exist")
Return
Else
End if
'provide feedback of the file replacement and ask if the user is sure
if MessageBox.Show(“This will replace: “ & vbLF & _
CurFileName & vbLF & _
“ with: “ & vbLF & _
NewFileName & vbLF & _
“ Are you sure?”, _
"iLogic", MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1) = vbYes Then
‘Replace all occurences, True = Replace All
oOccurrence.Replace (NewFileName, True)
Else
End if
'----end of ilogic code-------