Hello
I have a function in a macro that selects parts based on ownership, in order to move those parts to a folder next.
The problem is that it also selects the parts below the constraints N°1 on the attached image whose symmetrical or repetition parts and especially the one that causes problems are the parts in a belt function see N°2. (see why at the end of the subject)
Is it possible when selecting not to select everything below constraints or at least not to select what is contained in a constraint function?
Attached is my code:
Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long, catSelect As String)
Dim vChilds As Variant, vChild As Variant
Dim swChildComp As SldWorks.Component2
Dim MyString As String
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Set swApp = Application.SldWorks
vChilds = swComp.GetChildren
For Each vChild In vChilds
Set swChildComp = vChild
Dim FileName As String
FileName = swChildComp.GetPathName
Debug.Print "Part Name : " & FileName
FileName = Left(FileName, InStr(FileName, ".") - 1)
FileName = Right(FileName, Len(FileName) - InStrRev(FileName, "\"))
Debug.Print "Part Name : " & FileName
MyString = FileName
Dim ActiveConfig As String
ActiveConfig = swChildComp.ReferencedConfiguration
Debug.Print "Configuration: " & ActiveConfig
FileName = swChildComp.GetPathName
If swChildComp.GetSuppression() <> swComponentSuppressionState_e.swComponentSuppressed Then
Dim swPart As SldWorks.modelDoc2
Set swPart = swChildComp.GetModelDoc2()
'Récupère la catégorie de la configuration active
Set swCustPropMgr = swPart.Extension.CustomPropertyManager(ActiveConfig) 'get properties
categorie = swCustPropMgr.Get("Categorie") 'get categorie
designation = swCustPropMgr.Get("Designation")
'Si la catégorie de la config active est vide on récupère celle du document
If categorie = "" Then
Set swCustPropMgr = swPart.Extension.CustomPropertyManager("") 'get properties
categorie = swCustPropMgr.Get("Categorie") 'get categorie
If designation = "" Then
designation = swCustPropMgr.Get("Designation") 'get categorie
End If
End If
Debug.Print "Catégorie: " & categorie
If catSelect = "FI" Then
folderName = "FI"
If (categorie = "Fourniture Industrielle" And Not (designation Like "STD*")) Or (categorie = "Tuyauterie") Or ((categorie = "Sans Catégorie") And (MyString Like "Bipod*")) Or ((categorie = "Sans Catégorie") And (MyString Like "Tripod*")) Then
compteur = compteur + 1
retVal = swChildComp.Select2(True, 0)
End If
ElseIf catSelect = "Visserie" Then
folderName = "Visserie"
Debug.Print "Type:" & swPart.GetType
If (categorie = "Visserie") Or ((categorie = "Sans Catégorie") And (swPart.GetType = 2) And (Not MyString Like "Bipod*") And (Not MyString Like "Tripod*")) Then
compteur = compteur + 1
retVal = swChildComp.Select2(True, 0)
End If
ElseIf catSelect = "Reconductible" Then
folderName = "Reconductible"
'If categorie = "Reconductible" Then
If (categorie = "Reconductible") And (Not designation Like "STD*") Then
compteur = compteur + 1
retVal = swChildComp.Select2(True, 0)
End If
ElseIf catSelect = "Electricite" Then
folderName = "Electricité"
If categorie = "Electricite" Then
compteur = compteur + 1
retVal = swChildComp.Select2(True, 0)
End If
ElseIf catSelect = "STD" Then
folderName = "STD"
If designation Like "STD*" Then
compteur = compteur + 1
retVal = swChildComp.Select2(True, 0)
End If
End If
End If
Debug.Print
Next
End Sub
Indeed in Solidworks there is a bug if you select the part contained in a belt function that you right-click add to the new folder the part of this function is both above the constraints and below it (visually - see attached file)
If necessary, I also attach the full macro.
createfolderbyproperties.swp
dbggtzkwq9.gif