Hi all
Could someone please advise me whether it is possible to automatically divert Inventor to save to a specific folder within the workspace???
If a certain iProperty is set to yes, we want the user to save that file into a particular folder, if they try and save it elsewhere a message is popped up telling them an error has been made please try and save in the correct folder.
Admittedly I am not the most competant iLogic programmer but this is what I have thus far
Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 5388 StartFragment: 314 EndFragment: 5356 StartSelection: 314 EndSelection: 314
SyntaxEditor Code Snippet
WorkspacePath=ThisDoc.WorkspacePath()
DrawingPath="C:\Live WorkSpace\Designs\3D Designs\3D Drawings"
If(NotSystem.IO.Directory.Exists(DrawingPath))ThenSystem.IO.Directory.CreateDirectory(DrawingPath)
EndIf
oDoc=ThisDoc.FileName
MessageBox.Show(oDoc, "Title")
ThisDoc.Document.SaveAs("C:\Live WorkSpace\Designs\3D Designs\3D Drawings\"&"\"&oDoc&".dwg" ,True)
'ThisDoc.Document.SaveAs(DrawingPath & "\" & ThisDoc.FileName(False) & (".dwg") ,True)
'ThisDoc.Save
If someone could just point me in the right direction
Thanks
GW
Solved! Go to Solution.
Solved by danvang. Go to Solution.
Yes it is possible. There are two ways that I can think of to do this. First is if that property is "yes" then you can set the path to a specified location and with an input box prompt the user for the file name. Then concatenate them for the save as. If that property is "no" then have the save as dialog appear. The save as dialog code can be found from Curtis Waguespack's blog. This option should be simple to do. The second option is to use the save as dialog code and add a "do loop" to check if the path is correct. If it is not then it should loop back and display the save as dialog. Hopefully that will help point you in the right direction or a direction.
Dan
Here I decided to give the second option a try. Using Curtis' saveas dialog code, i added the loop. See how this works.
-----------------
'file save as dialog
'define the active document
oDoc = ThisDoc.Document
'create a file dialog box
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
'check file type and set dialog filter
If oDoc.DocumentType = kPartDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
End If
'this variable is used to check if the path should be forced or nor
Dim blnPropertyChecker As Boolean = True
'this variable sets the forced path
Dim strForcedPath As String = ThisDoc.WorkspacePath() & "\Drawing\"
'this variable will be the saved path
Dim strSavePath As String = ""
'if the path is forced then set the initial directory to the forced path otherwise use the workspace path
If blnPropertyChecker = True Then
oFileDlg.InitialDirectory = strForcedPath
Else
'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
End If
'set the file name string to use in the input box
oFileDlg.FileName = iProperties.Value("Project", "Part Number")
'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()
'do until the strSavePath variable is set to something.
Do Until strSavePath <> ""
'catch an empty string in the input
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
'this is need to get out of the do loop if there's an empty string or if it was canceled.
strSavePath = "xxxx"
'if a file name was defined and the path is NOT forced then use what was entered
ElseIf oFileDlg.FileName <> "" And blnPropertyChecker = False Then
strSavePath = oFileDlg.FileName
oDoc.SaveAs(strSavePath,False)
'if the file name was defined and the path IS forced then.....
ElseIf oFileDlg.File <> "" And blnPropertyChecker = True Then
'declare a temporary variable and have it be the filename that was entered in the dialog. oFileDlg.FileName contains the file name and full path.
Dim strFileNameTemp As String = oFileDlg.FileName
'declare a variable to find the last "\"
Dim lgIndex As Long = strFileNameTemp.lastIndexof("\")
'declare a variable and only get the path from the file name
Dim strPathOnly As String = strFileNameTemp.substring(0, lgIndex + 1)
'If the path in oFileDlg.FileName is equal to the forced path then the user saved it in the correct location. Proceed with saveas
If strPathOnly = strForcedPath Then
'MessageBox.Show("matches")
strSavePath = oFileDlg.FileName
oDoc.SaveAs(strSavePath,False)
'else display the save dialog again.
Else
MessageBox.Show("Incorrect save location. Please try again.", "ID-10-T")
'MessageBox.Show("doesn't match")
On Error Resume Next
oFileDlg.ShowSave()
End If
End If
Loop
'MessageBox.Show(strSavePath, "final")
Hi danvang
Your code worked like a dream, I cannot thank you enough.
The only issue I now have is getting it to trigger correctly. Using 'After' or 'Before' save document does not interrupt the 'OnSave' trigger so to speak.
Once the file is saved, the code works perfectly, but what I really need is an 'OnSave' trigger.
GW
This code was written to display the file saveas during design automation. It sounds like you want the function to work with the regular saveas command. You may not be able to do this with iLogic so you probably will need to write an addin that will run during the "OnSave" event. You can probably still use some of the code i wrote to loop through and verify the path. If you are not familar with writing addins, i would recommend the "My First Pluggin" Tutorial to get started. Hope that helps.
Hi,
Apologized off my bad English, but could somebody help me to change the ilogic rule to form where first is asked (with messagebox) the project number, work number and then file name (to saved).
The save path should start “E:\\Vault project\” then is coming the project number\ work number \ filename.iam.
After these it’s saved automatic to right place and if it’s possible it showed the file path.
Thank you.