- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here is my scenario. I have an iLogic rule that automatically saves an .ipt file as a .stp file and an .stl file and also attaches them to the .ipt file. This allows me to check into Vault, the .ipt file and both of the attached files together.
My rule is setup to save the .stp and .stl files as the iProperties "Part Number", not the actual file name. The rule also looks at the iProperties "Revision Number" and appends it with an "_" on the end of the new file name. If the Revision Number is "-", then it appends "0" to the filename, otherwise it uses whatever Rev letter is currently in the field...ie "A, B, C"
This image shows the filename is "Z-Eric999.ipt and the stp/stl filenames are pulled from the Part Number. Then, there is no revision, so it appends "_0" to the name.
We are using catogories/lifecycles for Revision control in Vault. So, if I change my vault lifecycle back to Work in Progress and check the files out again, to make a change, the Revision is bumped to Revision "A". Now, I'm back in Inventor making my changes and I save my part again. This triggers my iLogic rule to resave the .stp and .stl files again. So far, up to this point, everything works the way I want.
My problems begin when my rule automatically resaves the .stp and .stl files. Now, the rule sees that the Revision Number is different (now it's "A") and saves a new file with the part number and "_A" appended to the name. It then attaches this new file to the .ipt file along with the previously attached files.
This image shows both the originally attached files and the newly resaved files also attached.
So,when I check the .ipt file into the vault, it checks in all the attached files, but the newest files don't match the revision level in the vault, because they are brand new and have not be through the lifecycle yet.
This image shows the revision level mismatch in vault.
I'd really like the iLogic rule to replace the files with the newly saved files, remaining attached and maintaining the current vault revision level. And, in vault, there'd only be one .stp and one .stl file attached to the .ipt file instead of accumulating multiple files.
I have separate rules for the .stp and .stl file saving, but they are triggered at the same time when saving the .ipt file.
Here is my current .stp file rule.
SyntaxEditor Code Snippet
''' <summary> ''' Will only run if the activedocument has been saved. ''' </summary> Sub Main() Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Export and Attach Step file") If Not iProperties.Value("Project", "Part Number") = "" Then Dim filenameToAttach As String = ExportToStep() If Not filenameToAttach = String.Empty Then Dim doc As Document = ThisApplication.ActiveDocument AddReferences(doc, filenameToAttach) End If Else MessageBox.Show("NuTec Part Number is blank...Cannot save the .stp file","Error Saving File") trans.Abort() End If End Sub ''' <summary> ''' Returns an empty string if the stp file didn't save for some reason. ''' </summary> ''' <returns></returns> Function ExportToStep() As String Dim filename As String ' Get the STEP translator Add-In. Dim oSTEPTranslator As TranslatorAddIn oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}") Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap Dim Rev As String If iProperties.Value("Project", "Revision Number") = "-" Then Rev = "_0" ElseIf iProperties.Value("Project", "Revision Number") = "" Then Rev = "" ElseIf Not iProperties.Value("Project", "Revision Number") = "-" Or iProperties.Value("Project", "Revision Number") = "" Then Rev = "_" & iProperties.Value("Project", "Revision Number") End If oStepFileName = iProperties.Value("Project", "Part Number") & Rev If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then ' Set application protocol. ' 2 = AP 203 - Configuration Controlled Design ' 3 = AP 214 - Automotive Design oOptions.Value("ApplicationProtocolType") = 3 ' Other options... 'oOptions.Value("Author") = "" 'oOptions.Value("Authorization") = "" 'oOptions.Value("Description") = "" 'oOptions.Value("Organization") = "" oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim oData As DataMedium oData = ThisApplication.TransientObjects.CreateDataMedium oData.FileName = ThisDoc.Path & "\" & oStepFileName & ".stp" oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData) filename = oData.FileName End If If System.IO.File.Exists(filename) Then Return filename Else Return "" End If End Function ''' <summary> ''' Attaches any file using the full c:\path\to\your\file.extension format. ''' </summary> ''' <param name="odoc"></param> ''' <param name="selectedfile"></param> Public Sub AddReferences(ByVal odoc As Inventor.Document, ByVal selectedfile As String) Dim oleReference As ReferencedOLEFileDescriptor If selectedfile.Contains("|") Then ' we have multiple files selected. Dim file As String() = selectedfile.Split("|") For Each s As String In file oleReference = odoc.ReferencedOLEFileDescriptors _ .Add(s, OLEDocumentTypeEnum.kOLEDocumentLinkObject) oleReference.BrowserVisible = True oleReference.Visible = False oleReference.DisplayName = Mid$(s, InStrRev(s, "\") + 1) Next Else oleReference = odoc.ReferencedOLEFileDescriptors _ .Add(selectedfile,OLEDocumentTypeEnum.kOLEDocumentLinkObject) oleReference.BrowserVisible = True oleReference.Visible = False oleReference.DisplayName = Mid$(selectedfile, InStrRev(selectedfile, "\") + 1) End If End Sub
Solved! Go to Solution.