- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need to write a script which goes through an assembly and all of the subassemblies, checks parts for a specific parameter matching a specific value (IsProfile = True) and if the parameter matches, open the part and save a copy as an STP file using the part reference as the file name.
I have ripped off and attempted to modify the script below, but it wants to open every part in the model. in my case there are 1900 (200+ unique instances) parts, once the part is open it will then try match the value and if it's able it should try to export the part, however since there are so many parts and the vast majority of them don't contain the required parameter (or do but the parameter is not matching) I don't want to have inventor spend two days opening 1900 components and only exporting 20 of them.
I'm fairly new to iLogic and I'm happy setting and looping through parts but this is a little beyond my skill level.
so for clarity, I want to,
Go through each component,
If it has a specific parameter (IsProfile = True)
Open the part and save a copy as an STP using the part number as filename
Close the part and move on to the next
Else
Skip the part and move on to the next
'check that the active document is an assembly file If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then MessageBox.Show("This Rule " & iLogicVb.RuleName & " only works on Assembly Files.", "WRONG DOCUMENT TYPE", MessageBoxButtons.OK, MessageBoxIcon.Error) Return End If 'define the active document as an assembly file Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oAsmName As String = ThisDoc.FileName(False) 'without extension 'get user input Dim RUsure = MessageBox.Show( "This will create a STEP file for all components." _ & vbLf & " " _ & vbLf & "Are you sure you want to create STEP Drawings for all of the assembly components?" _ & vbLf & "This could take a while.", "iLogic - Batch Output STEPs ", MessageBoxButtons.YesNo) If RUsure = vbNo Then Return Else End If '- - - - - - - - - - - - -STEP setup - - - - - - - - - - - - Dim oPath = ThisDoc.Path 'get STEP target folder path ' original => oFolder = oPath & "\" & oAsmName & " STEP Files" Dim oFolder = oPath & "\ExportedComponents" '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 '- - - - - - - - - - - - -Assembly - - - - - - - - - - - - ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName & (".stp"), True) '- - - - - - - - - - - - -Components - - - - - - - - - - - - 'look at the files referenced by the assembly Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments 'work the referenced models For Each oRefDoc As Document In oRefDocs Dim oCurFile As Document = ThisApplication.Documents.Open(oRefDoc.FullFileName, True) Dim oCurFileName = oCurFile.FullFileName Dim ShortName = IO.Path.GetFileNameWithoutExtension(oCurFileName) Dim oPropSets As PropertySets = oCurFile.PropertySets Dim oPropSet As PropertySet = oPropSets.Item("Design Tracking Properties") Dim oPartNumiProp As [Property] = oPropSet.Item("Part Number") If Parameter.Param("IsProfile") = True Then Try oCurFile.SaveAs(oFolder & "\" & oPartNumiProp.Value & (".stp"), True) Catch MessageBox.Show("Error processing " & oCurFileName, "ilogic") End Try oCurFile.Close() Else oCurFile.Close() End If Next '- - - - - - - - - - - - - MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
Any help would be massively appreciated.
Solved! Go to Solution.