I need to redirect the save path of a file

I need to redirect the save path of a file

Miguel.CarvajalS34Q6
Advocate Advocate
347 Views
2 Replies
Message 1 of 3

I need to redirect the save path of a file

Miguel.CarvajalS34Q6
Advocate
Advocate

I am using a code to organize the name with which the inventor's .ipt file will be saved. but I would like to be able to select the location where it will be saved.
Thank you very much for the help.

this is the code used

 

'get model doc

oModleDoc = ThisDoc.ModelDocument

 

'process file name

'get  position of the last backslash

Dim FNamePos As Long

FNamePos = InStrRev(oModleDoc.FullFileName, "\", -1)      

'get file name

Dim docFName As String

docFName = Right(oModleDoc.FullFileName, Len(oModleDoc.FullFileName) - FNamePos)

 

'define the property set

oDTPs = oModleDoc.PropertySets.Item("Design Tracking Properties")

'define the property

oPN = oDTPs.Item("Part Number").Value

 

'replace old file name with iproperty value

oPathAndName = Replace(oModleDoc.FullFileName,docFName,oPN)

'save off a copy

ThisDoc.Document.SaveAs(oPathAndName & ".ipt" , True)

'present message to user

MessageBox.Show("File saved to: " & oPathAndName & ".ipt", "iLogic")

0 Likes
Replies (2)
Message 2 of 3

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @Miguel.CarvajalS34Q6 . Please review if this is what you wanted.

 

oModleDoc = ThisDoc.ModelDocument
Dim FNamePos As Long
FNamePos = InStrRev(oModleDoc.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(oModleDoc.FullFileName, Len(oModleDoc.FullFileName) - FNamePos)
oDTPs = oModleDoc.PropertySets.Item("Design Tracking Properties")
oPN = oDTPs.Item("Part Number").Value
oPathAndName = Replace(oModleDoc.FullFileName,docFName,oPN)

oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.ipt)|*.ipt|All Files (*.*)|*.*"
oFileDlg.FileName = oPathAndName & ".ipt"
oFileDlg.ShowSave()
If oFileDlg.FileName Is Nothing Or oFileDlg.FileName = "" Then Exit Sub	
Dim sPath As String = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Dim sName As String = System.IO.Path.GetFileNameWithoutExtension(oFileDlg.FileName)
oDoc.SaveAs(sPath & "\" & sName & ".ipt", False)

 

Example execution of this code.

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.

EESignature

Message 3 of 3

Miguel.CarvajalS34Q6
Advocate
Advocate
unfortunately the code does not perform the expected task, thank you very much for the suggestion
0 Likes