Adding Vault saved location to title block.

Adding Vault saved location to title block.

ThomasSwanson
Advocate Advocate
322 Views
0 Replies
Message 1 of 1

Adding Vault saved location to title block.

ThomasSwanson
Advocate
Advocate

Hey guys, 

 

Working on a custom code to put the Vault file location into the title block. 

I have cheated a little bit buy using the save location on C: and then chopping off the first few characters (C:\vault\) inorder to get the file path to read the same as it would show in vault.  

 

The issues I am running into is the fact that the file has to be saved first  in order for it to create a physical location on the hard drive.  This rule runs perfect executing it using the after save event trigger.  Except that you cannot check it into the Vault afterwards because the rule dirtys the file.  Its a know issue https://knowledge.autodesk.com/support/inventor-products/troubleshooting/caas/sfdcarticles/sfdcartic...

 

So I followed the advice of the knowledge base post and moved it to a before save rule, and added a save as command to prompt the user to save the file before Inventor issued its save.  The problem here is the file has moved from its temp location with my save as command so it causes the save command from Inventor to kick out an error.

 

If this wasn't enough someone brought it to my attention that if you do a copy design then file location would be wrong in Vault until someone checked the file out and back in.

 

Here is the most revised code with it being configured to run with a before save event trigger.

Sub Main
'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"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.dwg)|*.dwg"
End If


'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
'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()


'catch an empty string in the imput
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName <> "" Then
MyFile = oFileDlg.FileName
'save the file 
oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
End If

'Fileloc

End Sub 

Sub Fileloc

Dim filelocation As String
Dim Vault_Location As String 
Dim GETSheetName As String 
Dim save_state As String


Try
	'This is looking for the Iproperty called Save_State
	'MessageBox.Show ("starting the try loop: " & save_state)
	save_state = iProperties.Value("Custom", "Save_State")
	'MessageBox.Show("end of try: "& save_state)
Catch
	'If the Save_State Variable doesn't exist this will create it and set it to True.
	save_state = "True"
	iProperties.Value("Custom", "Save_State") = save_state
	'MessageBox.Show("catching setting to True: " & save_state)
End Try

'This calles the Active File
filelocation = ThisDoc.PathAndFileName(False)
MessageBox.Show("Filelocation",filelocation)

	
'This IF statement looks for the : in the file path if found it will remove the needed amount of spaces from the file path	
If InStr(filelocation, ":") Then

	'MessageBox.Show("Path and filename:" & filelocation)
'       ' Extract the Vault location from the combined file path and part name
'		'filelocation variable looks like this "C:/Vault/desgins/Project/..." - we want "Project/..."
	GetSheetName = Mid (filelocation, 3, Len(filelocation)-2)
	'MessageBox.Show("Modified Path and filename:" & GetSheetName)
	iProperties.Value("Custom", "Vault_Location") = GetSheetName
Else
	' Couldn't find the ":", so just return the whole string
 	GetSheetName = filelocation
	iProperties.Value("Custom", "Vault_Location") = GetSheetName
End If

'MessageBox.Show("before if: " & iProperties.Value("Custom", "Save_State"))

'created a variable here to store the value of the Save_State iproperty. This test variable is then used to see if the rule needs to be run again
Dim test As String
test = iProperties.Value("Custom", "Save_State")
If test = "True" Then
	'this flag means this function needs to save the drawing again

	save_state = "False"
	iProperties.Value("Custom", "Save_State") = save_state
	ThisDoc.Save
	
	'MessageBox.Show("IF statement:"& save_state)
Else
	'this function has already run, so we don't need to save again
	save_state = "False"
	iProperties.Value("Custom", "Save_State") = save_state
	
End If

End Sub
0 Likes
323 Views
0 Replies
Replies (0)