So i have been trying to fix a part of code from my larger ilogic script.
the script gives or should give the ability to select parts or assemblies in an assembly and export them to a desired location. the location etc is chosen via a dll vbform so that works. it detects all the selected parts and names them after completion.
except that when it exports them it exports the assembly multiple times under the file names of the selected items.
help would be greatly appreciated ๐
Sub SelectedExport(PDFPath As String, oRev As String) 'Make a ref to active doc Dim oDoc As Document oDoc = ThisApplication.ActiveDocument 'selected components collection Dim oSelected As ObjectCollection oSelected = ThisApplication.TransientObjects.CreateObjectCollection Dim oCount As Integer oCount = oDoc.SelectSet.Count 'Check that at least 1 is selected If oCount = 0 Then MessageBox.Show("Please select a component.", "iLogic") Exit Sub 'bail out End If 'add to Object Collection Dim i As Long For i = 1 To oCount If oDoc.SelectSet.Item(i).Type = _ ObjectTypeEnum.kComponentOccurrenceObject Then oSelected.Add (oDoc.SelectSet.Item(i)) End If Next 'get step translator 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 ' 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 'do stuff to the selected files here: Dim x As Integer = 1 For Each Item In oSelected Dim oCC As ComponentOccurrence = TryCast(oSelected.Item(x), ComponentOccurrence) Dim oSelectedDoc As Document oSelectedDoc = oCC.Definition.Document Dim CurFileName As String 'get the path and file name of the selected item CurFileName = oSelectedDoc.FullFileName Dim FNamePos As Long FNamePos = InStrRev(CurFileName, "\", -1) Dim docFName As String docFName = Right(CurFileName, Len(CurFileName) - FNamePos) DocName = Left(docFName, Len(docFName) -4) 'defines backslash as the subdirectory separator ' Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar ' 'find the postion of the last backslash in the path ' FNamePos = InStrRev(CurFileName, "\", -1) ' 'get the file name with the file extension ' Name = Right(CurFileName, Len(CurFileName) - FNamePos) ' 'get the path of the folder containing the file ' Folder_Location = Left(CurFileName, Len(CurFileName) - Len(Name)-1) oData.FileName = PDFPath & "\" & DocName & "_Rev" & iProperties.Value(oSelectedDoc.DisplayName, "Project", "Revision Number") &".stp" oSTEPTranslator.SaveCopyAs(oDoc, oContext, oOptions, oData) x = x + 1 Next End If 'get names item name from collection For Each oItem In oSelected oMsg = oMsg & vbLf & oItem.Name Next MessageBox.Show(oCount _ & " Component(s) selected." & vbLf & oMsg, "iLogic") End Sub
Solved! Go to Solution.
Solved by JhoelForshav. Go to Solution.
Hi @Anonymous
Try changing the line:
oSTEPTranslator.SaveCopyAs(oDoc, oContext, oOptions, oData)
To:
oSTEPTranslator.SaveCopyAs(oSelectedDoc, oContext, oOptions, oData)
oDoc = the main assembly in your code, so the original line just exports that one for each iteration of the loop.
oSelectedDoc represents the document of the selected occurrence, meaning it'll change to be each selected occurrences document throughout the iterations of your loop ๐
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
Thank you for this it helps a lot when picking out parts from massive assemblies. ๐
for anyone interested in the full code and dll you can contact me.
Can't find what you're looking for? Ask the community or share your knowledge.