Hi all
Being a designer/editor by trade and a little coder of passion, I tackled stronger than me in VBA macro coding.
My goal is to be able to lower the recovery bar in all parts of an assembly. To do this, I would like the macro to select and open, one by one, the parts (with or without an on-screen display) and then move down the resume bar in the tree and save the part. If in my set there were to be a subset, I would like him to open this subset (same as for the parts, with display or not) and start opening the parts one by one again to start the first step again.
Here is a little diagram:
SW ASSEMBLY-----> Open part and ass (which are not deleted) -------> If it's a part --------> then go down the resume bar + save + close
I
I-----> If it is an assembly, do the same as box 2
here is the code and where I am, it's a code that I found on the Web, but which apparently was coded a little "in a hurry" on this forum: https://forum.solidworks.com/thread/159206
My code corrected as best I could : The problem with my code is that there are errors everywhere... error 91, then sometimes 13.... I am lost and would need the help of one of you who knows about it!! Thanks in advance;)
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModel1 As SldWorks.ModelDoc2
Dim swAssembly As SldWorks.AssemblyDoc
Dim CompNum As Integer
Dim CompNum1 As Integer
Dim components As SldWorks.Component2
Dim components1 As SldWorks.Component2
Dim component As SldWorks.Component2
Dim component1 As SldWorks.Component2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swAssembly = swModel
' Get number of components, not including child components in subassemblies
CompNum = swAssembly.GetComponentCount(True)
components = swAssembly.GetComponents(True)
Dim i as Integer
For i = 0 To CompNum
component = components(i)
swModel1 = component. GetModelDoc2
'open part from assembly function (if subassembly, create another for-loop with same procedure)
If swModel1.GetType = swDocPART Then
Set swModel = swApp.ActivateDoc3(component. Name2, False, swRebuildOnActivation_e.swUserDecision, 0)
boolstatus = share. FeatureManager.EditRollback(swMoveRollbackBarTo_e.swMoveRollbackBarToEnd, "")
boolstatus = share. EditRebuild3()
swModel.SaveAs (component. GetPathName)
swApp.CloseDoc component. GetPathName
Set swModel = swApp.ActiveDoc
ElseIf swModel1.GetType = swDocASSEMBLY Then
CompNum1 = swModel1.GetComponentCount(True)
components1 = swModel1.GetComponents(True)
Sun j As Integer
For j = 0 TB CompNum1
component1 = components1(j)
swModel1 = component1. GetModelDoc2
Set swModel = swApp.ActivateDoc3(component. Name2, False, swRebuildOnActivation_e.swUserDecision, 0)
boolstatus = share. FeatureManager.EditRollback(swMoveRollbackBarTo_e.swMoveRollbackBarToEnd, "")
boolstatus = share. EditRebuild3()
swModel.SaveAs (component. GetPathName)
swApp.CloseDoc component. GetPathName
Next
End If
Next
End Sub