Hi,
Is it possible to generate file name based on the folder structure where I want this file to be saved?
Example:
I have folder structure like this: C:\VaultWorkspace\Projects\AA\BB\CCC\D\EE\FFFFF
And file should have name: AABB-CCC-D-EE-FFFFF.iam
Thanks all for your help.
Milan
Solved! Go to Solution.
Hi,
Is it possible to generate file name based on the folder structure where I want this file to be saved?
Example:
I have folder structure like this: C:\VaultWorkspace\Projects\AA\BB\CCC\D\EE\FFFFF
And file should have name: AABB-CCC-D-EE-FFFFF.iam
Thanks all for your help.
Milan
Solved! Go to Solution.
Solved by Andrii_Humeniuk. Go to Solution.
Solved by Andrii_Humeniuk. Go to Solution.
Solved by Andrii_Humeniuk. Go to Solution.
Solved by Andrii_Humeniuk. Go to Solution.
Solved by Andrii_Humeniuk. Go to Solution.
Hi @zikmund . Please try this code:
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If oFileDlg.FileName Is Nothing Or oFileDlg.FileName = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sExten As String = System.IO.Path.GetExtension(oFileDlg.FileName)
Dim sF_Name As String = System.IO.Path.GetFileNameWithoutExtension(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sE_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sFullName As String = sPath & "\" & sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & _
"-" & sE_Name & "-" & sF_Name & sExten
oDoc.SaveAs(sFullName, False)
End sub
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Hi @zikmund . Please try this code:
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If oFileDlg.FileName Is Nothing Or oFileDlg.FileName = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sExten As String = System.IO.Path.GetExtension(oFileDlg.FileName)
Dim sF_Name As String = System.IO.Path.GetFileNameWithoutExtension(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sE_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sFullName As String = sPath & "\" & sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & _
"-" & sE_Name & "-" & sF_Name & sExten
oDoc.SaveAs(sFullName, False)
End sub
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Hi Andrii,
I created new rule (I tried assembly and part) and copied the code, but when I ran it, it just opened the save dialog and File name row is empty.
Milan
Hi Andrii,
I created new rule (I tried assembly and part) and copied the code, but when I ran it, it just opened the save dialog and File name row is empty.
Milan
FFFFF - is name file or folder? If folders then you need this code:
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sExten As String = System.IO.Path.GetExtension(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sFullName As String = sPath & "\" & sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & _
"-" & sE_Name & "-" & sF_Name & sExten
oDoc.SaveAs(sFullName, False)
End Sub
You need to choose the path to save the file, only then the rule will understand the required file name.
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
FFFFF - is name file or folder? If folders then you need this code:
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sExten As String = System.IO.Path.GetExtension(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sFullName As String = sPath & "\" & sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & _
"-" & sE_Name & "-" & sF_Name & sExten
oDoc.SaveAs(sFullName, False)
End Sub
You need to choose the path to save the file, only then the rule will understand the required file name.
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Hi Andrii,
Thanks for your help. It works perfectly for the assemblies! Amazing!
Can you help me also with the parts? Our idea is that each part will be named AABB-CCC-D-EE-FFFFF.GGGG
Where GGGG will be autogenerated sequence.
Do you think it's possible?
With best regards
Milan
Hi Andrii,
Thanks for your help. It works perfectly for the assemblies! Amazing!
Can you help me also with the parts? Our idea is that each part will be named AABB-CCC-D-EE-FFFFF.GGGG
Where GGGG will be autogenerated sequence.
Do you think it's possible?
With best regards
Milan
The file name will be the time of its creation. Example: 638187949256360534. This will help avoid file name mismatches.
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") + 1)
Dim sFullDocName As String
If TypeOf oDoc Is AssemblyDocument Then
sFullDocName = sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & "-" & sE_Name & "-" & sF_Name & ".iam"
Else If TypeOf oDoc Is PartDocument Then
sFullDocName = DateTime.Now.Ticks & ".ipt"
End If
Dim sFullName As String = sPath & "\" & sFullDocName
oDoc.SaveAs(sFullName, False)
End Sub
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
The file name will be the time of its creation. Example: 638187949256360534. This will help avoid file name mismatches.
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") + 1)
Dim sFullDocName As String
If TypeOf oDoc Is AssemblyDocument Then
sFullDocName = sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & "-" & sE_Name & "-" & sF_Name & ".iam"
Else If TypeOf oDoc Is PartDocument Then
sFullDocName = DateTime.Now.Ticks & ".ipt"
End If
Dim sFullName As String = sPath & "\" & sFullDocName
oDoc.SaveAs(sFullName, False)
End Sub
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
In this variant, the current waves and seconds when saving are taken as a unique number. But there is a possibility that there will be matches in the file names.
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") + 1)
Dim sShortName As String = sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & "-" & sE_Name & "-" & sF_Name
Dim sFullDocName As String
If TypeOf oDoc Is AssemblyDocument Then
sFullDocName = sShortName & ".iam"
Else If TypeOf oDoc Is PartDocument Then
sFullDocName = sShortName & "_" & DateTime.Now.Minute & DateTime.Now.Millisecond & ".ipt"
End If
Dim sFullName As String = sPath & "\" & sFullDocName
oDoc.SaveAs(sFullName, False)
End Sub
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
In this variant, the current waves and seconds when saving are taken as a unique number. But there is a possibility that there will be matches in the file names.
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") + 1)
Dim sShortName As String = sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & "-" & sE_Name & "-" & sF_Name
Dim sFullDocName As String
If TypeOf oDoc Is AssemblyDocument Then
sFullDocName = sShortName & ".iam"
Else If TypeOf oDoc Is PartDocument Then
sFullDocName = sShortName & "_" & DateTime.Now.Minute & DateTime.Now.Millisecond & ".ipt"
End If
Dim sFullName As String = sPath & "\" & sFullDocName
oDoc.SaveAs(sFullName, False)
End Sub
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
This code checks whether the part exists in the folder and numbers them in order.
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") + 1)
Dim sShortName As String = sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & "-" & sE_Name & "-" & sF_Name
Dim sFullDocName As String
If TypeOf oDoc Is AssemblyDocument Then
sFullDocName = sShortName & ".iam"
Else If TypeOf oDoc Is PartDocument Then
Dim lUnqNumb As String = GetUnqNumb(sPath & "\" & sShortName)
If lUnqNumb Is Nothing Or lUnqNumb = "" Then Exit Sub
sFullDocName = sShortName & "_" & lUnqNumb & ".ipt"
End If
Dim sFullName As String = sPath & "\" & sFullDocName
oDoc.SaveAs(sFullName, False)
End Sub
Private Function GetUnqNumb(sShortName As String) As String
Dim sInt As String
For i As Integer = 1 To 99999
sInt = i
If InStrRev(sInt, "", -1) = 1 Then
sInt = "0000" & sInt
Else If InStrRev(sInt, "", -1) = 2 Then
sInt = "000" & sInt
Else If InStrRev(sInt, "", -1) = 3 Then
sInt = "00" & sInt
Else If InStrRev(sInt, "", -1) = 4 Then
sInt = "0" & sInt
Else If InStrRev(sInt, "", -1) = 5 Then
sInt = sInt
End If
If Not System.IO.File.Exists(sShortName & "_" & sInt & ".ipt") Then
Return sInt
End If
Next i
Return Nothing
End Function
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
This code checks whether the part exists in the folder and numbers them in order.
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") + 1)
Dim sShortName As String = sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & "-" & sE_Name & "-" & sF_Name
Dim sFullDocName As String
If TypeOf oDoc Is AssemblyDocument Then
sFullDocName = sShortName & ".iam"
Else If TypeOf oDoc Is PartDocument Then
Dim lUnqNumb As String = GetUnqNumb(sPath & "\" & sShortName)
If lUnqNumb Is Nothing Or lUnqNumb = "" Then Exit Sub
sFullDocName = sShortName & "_" & lUnqNumb & ".ipt"
End If
Dim sFullName As String = sPath & "\" & sFullDocName
oDoc.SaveAs(sFullName, False)
End Sub
Private Function GetUnqNumb(sShortName As String) As String
Dim sInt As String
For i As Integer = 1 To 99999
sInt = i
If InStrRev(sInt, "", -1) = 1 Then
sInt = "0000" & sInt
Else If InStrRev(sInt, "", -1) = 2 Then
sInt = "000" & sInt
Else If InStrRev(sInt, "", -1) = 3 Then
sInt = "00" & sInt
Else If InStrRev(sInt, "", -1) = 4 Then
sInt = "0" & sInt
Else If InStrRev(sInt, "", -1) = 5 Then
sInt = sInt
End If
If Not System.IO.File.Exists(sShortName & "_" & sInt & ".ipt") Then
Return sInt
End If
Next i
Return Nothing
End Function
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
@Andrii_Humeniuk Maybe one last request of your help.
Is it possible to reserve GGGG from 0001 to 0999 for sub-assemblies and 1000 - 9999 for parts?
Milan
@Andrii_Humeniuk Maybe one last request of your help.
Is it possible to reserve GGGG from 0001 to 0999 for sub-assemblies and 1000 - 9999 for parts?
Milan
Please check if this code works as you wanted.
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") + 1)
Dim sShortName As String = sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & "-" & sE_Name & "-" & sF_Name
Dim sFullDocName As String
Dim lUnqNumb As String
If TypeOf oDoc Is AssemblyDocument Then
If Not System.IO.File.Exists(sPath & "\" & sShortName & ".iam") Then
sFullDocName = sShortName & ".iam"
Else
lUnqNumb = GetUnqNumbAssemb(sPath & "\" & sShortName)
sFullDocName = sShortName & "_" & lUnqNumb & ".iam"
End If
Else If TypeOf oDoc Is PartDocument Then
lUnqNumb = GetUnqNumbPart(sPath & "\" & sShortName)
If lUnqNumb Is Nothing Or lUnqNumb = "" Then Exit Sub
sFullDocName = sShortName & "_" & lUnqNumb & ".ipt"
End If
Dim sFullName As String = sPath & "\" & sFullDocName
oDoc.SaveAs(sFullName, False)
End Sub
Private Function GetUnqNumbAssemb(sShortName As String) As String
Dim sInt As String
For i As Integer = 1 To 999
sInt = i
If InStrRev(sInt, "", -1) = 1 Then
sInt = "000" & sInt
Else If InStrRev(sInt, "", -1) = 2 Then
sInt = "00" & sInt
Else If InStrRev(sInt, "", -1) = 3 Then
sInt = "0" & sInt
End If
If Not System.IO.File.Exists(sShortName & "_" & sInt & ".iam") Then
Return sInt
End If
Next i
Return Nothing
End Function
Private Function GetUnqNumbPart(sShortName As String) As String
Dim sInt As String
For i As Integer = 1000 To 9999
sInt = i
If InStrRev(sInt, "", -1) = 1 Then
sInt = "000" & sInt
Else If InStrRev(sInt, "", -1) = 2 Then
sInt = "00" & sInt
Else If InStrRev(sInt, "", -1) = 3 Then
sInt = "0" & sInt
Else If InStrRev(sInt, "", -1) = 4 Then
sInt = sInt
End If
If Not System.IO.File.Exists(sShortName & "_" & sInt & ".ipt") Then
Return sInt
End If
Next i
Return Nothing
End Function
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Please check if this code works as you wanted.
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") + 1)
Dim sShortName As String = sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & "-" & sE_Name & "-" & sF_Name
Dim sFullDocName As String
Dim lUnqNumb As String
If TypeOf oDoc Is AssemblyDocument Then
If Not System.IO.File.Exists(sPath & "\" & sShortName & ".iam") Then
sFullDocName = sShortName & ".iam"
Else
lUnqNumb = GetUnqNumbAssemb(sPath & "\" & sShortName)
sFullDocName = sShortName & "_" & lUnqNumb & ".iam"
End If
Else If TypeOf oDoc Is PartDocument Then
lUnqNumb = GetUnqNumbPart(sPath & "\" & sShortName)
If lUnqNumb Is Nothing Or lUnqNumb = "" Then Exit Sub
sFullDocName = sShortName & "_" & lUnqNumb & ".ipt"
End If
Dim sFullName As String = sPath & "\" & sFullDocName
oDoc.SaveAs(sFullName, False)
End Sub
Private Function GetUnqNumbAssemb(sShortName As String) As String
Dim sInt As String
For i As Integer = 1 To 999
sInt = i
If InStrRev(sInt, "", -1) = 1 Then
sInt = "000" & sInt
Else If InStrRev(sInt, "", -1) = 2 Then
sInt = "00" & sInt
Else If InStrRev(sInt, "", -1) = 3 Then
sInt = "0" & sInt
End If
If Not System.IO.File.Exists(sShortName & "_" & sInt & ".iam") Then
Return sInt
End If
Next i
Return Nothing
End Function
Private Function GetUnqNumbPart(sShortName As String) As String
Dim sInt As String
For i As Integer = 1000 To 9999
sInt = i
If InStrRev(sInt, "", -1) = 1 Then
sInt = "000" & sInt
Else If InStrRev(sInt, "", -1) = 2 Then
sInt = "00" & sInt
Else If InStrRev(sInt, "", -1) = 3 Then
sInt = "0" & sInt
Else If InStrRev(sInt, "", -1) = 4 Then
sInt = sInt
End If
If Not System.IO.File.Exists(sShortName & "_" & sInt & ".ipt") Then
Return sInt
End If
Next i
Return Nothing
End Function
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Hi @Andrii_Humeniuk,
I tested the file creations and it works awesome. However people complains they would like to keep also the possibility to enter unique file name by user.
Is it possible to add some kind of condition that if user fills the file name manualy, it will skip the automatic naming process, but if user not fills the name, it will go through the automation?
Thanks again.
Milan
Hi @Andrii_Humeniuk,
I tested the file creations and it works awesome. However people complains they would like to keep also the possibility to enter unique file name by user.
Is it possible to add some kind of condition that if user fills the file name manualy, it will skip the automatic naming process, but if user not fills the name, it will go through the automation?
Thanks again.
Milan
Hi @zikmund . Yes, it can be done. When you change the text (Select the file storage path) when saving the file, a file with your name will be created.
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
If Not MyFile.Contains("Select the file storage path") Then oDoc.SaveAs(MyFile, False): Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") + 1)
Dim sShortName As String = sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & "-" & sE_Name & "-" & sF_Name
Dim sFullDocName As String
Dim lUnqNumb As String
If TypeOf oDoc Is AssemblyDocument Then
If Not System.IO.File.Exists(sPath & "\" & sShortName & ".iam") Then
sFullDocName = sShortName & ".iam"
Else
lUnqNumb = GetUnqNumbAssemb(sPath & "\" & sShortName)
sFullDocName = sShortName & "_" & lUnqNumb & ".iam"
End If
Else If TypeOf oDoc Is PartDocument Then
lUnqNumb = GetUnqNumbPart(sPath & "\" & sShortName)
If lUnqNumb Is Nothing Or lUnqNumb = "" Then Exit Sub
sFullDocName = sShortName & "_" & lUnqNumb & ".ipt"
End If
Dim sFullName As String = sPath & "\" & sFullDocName
oDoc.SaveAs(sFullName, False)
End Sub
Private Function GetUnqNumbAssemb(sShortName As String) As String
Dim sInt As String
For i As Integer = 1 To 999
sInt = i
Select Case sInt.Length
Case 1
sInt = "000" & sInt
Case 2
sInt = "00" & sInt
Case 3
sInt = "0" & sInt
End Select
If Not System.IO.File.Exists(sShortName & "_" & sInt & ".iam") Then
Return sInt
End If
Next i
Return Nothing
End Function
Private Function GetUnqNumbPart(sShortName As String) As String
For i As Integer = 1000 To 9999
If Not System.IO.File.Exists(sShortName & "_" & i & ".ipt") Then
Return i
End If
Next i
Return Nothing
End Function
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Hi @zikmund . Yes, it can be done. When you change the text (Select the file storage path) when saving the file, a file with your name will be created.
Sub main
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = "Select the file storage path"
oFileDlg.ShowSave()
MyFile = oFileDlg.FileName
If MyFile Is Nothing Or MyFile = "" Then Exit Sub
If Not MyFile.Contains("Select the file storage path") Then oDoc.SaveAs(MyFile, False): Exit Sub
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sCutName As String = sPath.Remove(0, sPath.IndexOf("Projects\") + 9)
Dim sA_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sB_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sC_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sD_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
sCutName = sCutName.Remove(0, sCutName.IndexOf("\") +1)
Dim sE_Name As String = sCutName.Substring(0, sCutName.IndexOf("\"))
Dim sF_Name As String = sCutName.Remove(0, sCutName.IndexOf("\") + 1)
Dim sShortName As String = sA_Name & sB_Name & "-" & sC_Name & "-" & sD_Name & "-" & sE_Name & "-" & sF_Name
Dim sFullDocName As String
Dim lUnqNumb As String
If TypeOf oDoc Is AssemblyDocument Then
If Not System.IO.File.Exists(sPath & "\" & sShortName & ".iam") Then
sFullDocName = sShortName & ".iam"
Else
lUnqNumb = GetUnqNumbAssemb(sPath & "\" & sShortName)
sFullDocName = sShortName & "_" & lUnqNumb & ".iam"
End If
Else If TypeOf oDoc Is PartDocument Then
lUnqNumb = GetUnqNumbPart(sPath & "\" & sShortName)
If lUnqNumb Is Nothing Or lUnqNumb = "" Then Exit Sub
sFullDocName = sShortName & "_" & lUnqNumb & ".ipt"
End If
Dim sFullName As String = sPath & "\" & sFullDocName
oDoc.SaveAs(sFullName, False)
End Sub
Private Function GetUnqNumbAssemb(sShortName As String) As String
Dim sInt As String
For i As Integer = 1 To 999
sInt = i
Select Case sInt.Length
Case 1
sInt = "000" & sInt
Case 2
sInt = "00" & sInt
Case 3
sInt = "0" & sInt
End Select
If Not System.IO.File.Exists(sShortName & "_" & sInt & ".iam") Then
Return sInt
End If
Next i
Return Nothing
End Function
Private Function GetUnqNumbPart(sShortName As String) As String
For i As Integer = 1000 To 9999
If Not System.IO.File.Exists(sShortName & "_" & i & ".ipt") Then
Return i
End If
Next i
Return Nothing
End Function
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Can't find what you're looking for? Ask the community or share your knowledge.