09-01-2015
08:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
09-01-2015
08:54 AM
Thanks for the reply.
Here is what I have. It works but needs the file check so it would export the correct file not the assembly it is in. Could just exit if not in the same file.
' Start of iLogic code ******************************************* 'query user question = MessageBox.Show("Is a STEP file needed for " & ThisDoc.FileName(False), "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question) 'set condition based on answer If question = vbNo Then Exit Sub End If 'check to see if in drawing If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then doc = ThisApplication.ActiveDocument MsgBox("This iLogic rule will only run from a part or assembly", MsgBoxStyle.Exclamation, "Document Type Error") Exit Sub End If oPath=ThisDoc.Path oFolder = oPath & "\STEP FILES" 'Check to see if in same file or different'Is ThisDoc.FileName different from the Stepfilename needed?'if different, exit if same = then next 'Check for the STEP folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If 'Delete Files from folder containing this file name Dim path As String = ThisDoc.Path & "\STEP FILES\" For Each foundFile As String In My.Computer.FileSystem.GetFiles (path,Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories,"*" & ThisDoc.FileName(False) & "*") My.Computer.FileSystem.DeleteFile(foundFile) Next oRevNum = iProperties.Value("Project", "Revision Number") Stepfilename = ThisDoc.Path & "\STEP FILES\" & ThisDoc.FileName(False) Dim Sdate As String = DateString '& " " & TimeString CurrentFile = Stepfilename & " " & oRevNum & ".stp" ' 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 If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument _, oContext, oOptions) Then oOptions.Value("ApplicationProtocolType") = 3 oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim oData As DataMedium oData = ThisApplication.TransientObjects.CreateDataMedium ' Set export name of STEP file oData.FileName = currentFile oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext _, oOptions, oData) End If ' End of export code *********************************************** ' Ask user if they want to open the export folder OpenFolder = MessageBox.Show("Export successful! " & _ "- open containing folder now?", "Save2STEP", _ MessageBoxButtons.YesNo, _ MessageBoxIcon.Question,MessageBoxDefaultButton.Button1) If OpenFolder = vbYes Then Process.Start("explorer.exe", ThisDoc.Path & "\STEP FILES\") Else ' User says continue 'Return End If ' End of iLogic code **************************************************