10-19-2018
08:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-19-2018
08:36 AM
Hi @Anonymous,
As mentioned , you can search and ask programming questions of this type on the Inventor Customization forum:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
But here is a quick example that will do what you're looking for. I would create this as an external rule.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Imports System.IO
GetInput:
Six_Digit = InputBox("Enter 6 Digit number", "iLogic", )
If Six_Digit = "" Then
Return
Else If Len(Six_Digit) <> "6" Then
MessageBox.Show("Input must be 6 digits", "ilogic")
Goto GetInput
End If
Dim oDoc As Document
Dim sFilename As String
oFolder = "C:\TEMP\Library\"
Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oFolder, _
"*.*", SearchOption.AllDirectories )
For Each oFilename As String In oFilenames
If oFilename.Contains(Six_Digit) Then
Dim oOptions As Inventor.NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDoc = ThisApplication.Documents.OpenWithOptions(oFilename, oOptions, False)
sFilename = oFilename
Exit For
End If
Next
If sFilename = "" Then
MessageBox.Show("No matching libary file found.", "iLogic")
Return
End If
iCounter = 0
oProjectfolder = "C:\TEMP\Work\"
Dim oProject_Filenames() As String
oProject_Filenames = System.IO.Directory.GetFiles(oProjectfolder, _
"*.*", SearchOption.AllDirectories )
'count existing project files
For Each oFilename As String In oProject_Filenames
If oFilename.Contains(Six_Digit) Then
iCounter = iCounter + 1
End If
Next
'increment counter
iCounter = iCounter + 1
'find the postion of the last backslash in the path
FNamePos = InStrRev(sFilename, "\", -1)
'get the file name with the file extension
oName = Right(sFilename, Len(sFilename) - FNamePos)
'get the file name (without extension)
ShortName = Left(oName, Len(oName) - 4)
'get extension
oExt = Right(oName, 4)
If iCounter < 10 Then
iCounter = "00" + CStr(iCounter)
ElseIf iCounter < 100 Then
iCounter ="0" + CStr(iCounter)
Else
iCounter = CStr(iCounter)
End If
oNewName = ShortName & "_" & iCounter
'save new document
oDoc.SaveAs(oProjectfolder & oNewName & oExt, True)
oDoc.Close
MessageBox.Show("New file created: " & vbLf & oProjectfolder & oNewName & oExt, "iLogic")