Witam
Mam funkcję w makrze, która wybiera części na podstawie własności, aby przenieść te części do następnego folderu.
Problem polega na tym, że wybiera również części poniżej wiązań nr 1 na załączonym obrazie, których symetryczne lub powtarzające się części, a zwłaszcza ta, która sprawia problemy, to części w funkcji pasa, patrz nr 2. (zobacz dlaczego na końcu tematu)
Czy przy wyborze można nie zaznaczać wszystkiego poniżej ograniczeń lub przynajmniej nie wybierać tego, co jest zawarte w funkcji ograniczenia?
W załączeniu mój kod:
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
Rzeczywiście, w Solidworks występuje błąd, jeśli wybierzesz część zawartą w funkcji paska, którą klikniesz prawym przyciskiem myszy, dodaj do nowego folderu, część tej funkcji znajduje się zarówno powyżej wiązań, jak i poniżej nich (wizualnie - patrz załączony plik)
W razie potrzeby załączam również pełne makro.
createfolderbyproperties.swp
dbggtzkwq9.gif