Created
December 16, 2022 03:56
-
-
Save AmenJlili/ed1a86b83c62e0b93f29658d9533e1a4 to your computer and use it in GitHub Desktop.
AssemblyConfigRipper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dim swApp As SldWorks.SldWorks | |
Dim swAssemblyDoc As AssemblyDoc | |
Dim swcomponent As Component2 | |
Dim vcomponents As Variant | |
Dim processedFiles As Collection | |
Dim component | |
Sub main() | |
Set processedFiles = New Collection | |
Set swApp = Application.SldWorks | |
Set swAssemblyDoc = swApp.ActiveDoc | |
'make check if the active document | |
vcomponents = swAssemblyDoc.GetComponents(False) | |
For Each component In vcomponents | |
Set swcomponent = component | |
Dim swmodel As ModelDoc2 | |
Set swmodel = swcomponent.GetModelDoc2 | |
If Not swmodel Is Nothing Then | |
If ExistsInCollection(processedFiles, swmodel.GetTitle()) = False Then | |
SaveConfigurations swmodel | |
processedFiles.Add swmodel.GetTitle(), swmodel.GetTitle() | |
End If | |
End If | |
Next | |
End Sub | |
Function SaveConfigurations(ByRef swmodel As ModelDoc2) As String | |
Dim extensions(1 To 3) As String | |
extensions(1) = ".step" | |
extensions(2) = ".igs" | |
extensions(3) = ".x_t" | |
swmodel.Visible = True | |
Dim configurationNames As Variant | |
configurationNames = swmodel.GetConfigurationNames | |
For Each ConfigurationName In configurationNames | |
swmodel.ShowConfiguration2 ConfigurationName | |
For Each Extension In extensions | |
Dim output As String | |
output = "C:\BOM Export\" | |
output = output + Left(swmodel.GetTitle(), 6) + "_" + ConfigurationName + Extension | |
Dim saveRet As Boolean | |
Dim errors As Long | |
Dim warnings As Long | |
saveRet = swmodel.Extension.SaveAs3(output, SwConst.swSaveAsCurrentVersion, SwConst.swSaveAsOptions_Silent, Nothing, Nothing, errors, warnings) | |
Next Extension | |
Next ConfigurationName | |
swmodel.Visible = False | |
End Function | |
Public Function ExistsInCollection(col As Collection, key As Variant) As Boolean | |
On Error GoTo err | |
ExistsInCollection = True | |
IsObject (col.Item(key)) | |
Exit Function | |
err: | |
ExistsInCollection = False | |
End Function |
It is for an assembly, yes. Just run the SaveConfigurations on the active document to adapt it for a part document.
It is for an assembly, yes. Just run the SaveConfigurations on the active document to adapt it for a part document.
Apologies, I'm very new to the Solidworks API scene so I'm having trouble understanding what you mean?
The best way for us to help you with the changes you'd like is through our consulting work - Feel free to reach out to me by email amen at bluebyte.biz
You can also your question at cadoverflow.com
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is for an assembly Doc yes? How would you adapt it for a part?