Witam
Mam małe makro, które pobiera elementy nazwy pliku. Gotowy do wypełnienia formularza, aby uniknąć rozbieżności między " nazwą pliku " a " informacjami o nomenklaturze " w celu zautomatyzowanego zarządzania, które pojawi się później...
Właściwości wypełniają się dobrze, ale formularz wydaje się pusty. Mogę zrobić F5 lub odbudować, nic się nie dzieje
Co mogę dodać na końcu makra, aby odświeżyć formularz?
Zasadniczo musisz otworzyć 3D, aby formularz wyświetlał się poprawnie, podczas gdy w tym czasie, równolegle, kartusz planu części jest kompletny...
Oto mój kod
Dim swApp As Object
Dim swModel As ModelDoc2
Przyciemnij konfigurację jako SldWorks.Configuration
Dim swCustProp As CustomPropertyManager
Dim lRetVal tak długo
Dim myValue0 As Ciąg
Dim myValue1 As Ciąg
Przyciemnij myValue2 jako ciąg
Dim myValue3 As Ciąg
Dim myValue4 As Ciąg
Dim myValue5 As Ciąg
Dim myValue6 As Ciąg
Dim myValue7 As Ciąg
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
maValeur0 = swModel.GetTitle 'On récupère le nom du fichier
maValeur1 = Left(maValeur0, 6) 'On récupère les 6 premiers caractères du nom du fichier'
maValeur2 = Left(maValeur0, 12) 'On récupère les 12 premiers caractères du nom du fichier'
maValeur3 = Right(maValeur2, Len(maValeur2) - Len(maValeur1)) '2 moins 1'
maValeur4 = Right(maValeur0, 7) 'On récupère l'extension'
maValeur5 = Left(maValeur0, 13) 'On récupère les 13 premiers caractères du nom du fichier'
maValeur6 = Right(maValeur0, Len(maValeur0) - Len(maValeur5)) 'On récupére tout au delà du 13éme caractére'
maValeur7 = Left(maValeur6, Len(maValeur6) - Len(maValeur4)) 'on enlève l'extention à 5'
Set config = swModel.GetActiveConfiguration
Set cusPropMgr = config.CustomPropertyManager
lRetVal = cusPropMgr.Add3("N° Plan / Réf / Dim", swCustomInfoType_e.swCustomInfoText, maValeur3, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
lRetVal = cusPropMgr.Add3("Désignation", swCustomInfoType_e.swCustomInfoText, maValeur7, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
MsgBox "Formulaire complété" & Path, vbInformation
Koniec sub'
Witam
Nie używam formularza, ale Ctrl+Q nie rozwiązuje problemu? (przez makro, wymuś przebudowę)
2 polubienia
Witam.
'+1 na odbudowę.
Dodam linię rekordu.
swModel.Save3(swSaveAsOptions_Silent, lBłędy, lOstrzeżenia)
2 polubienia
Ctrl+Q (Jest tak "wychodzący" z domu, że nigdy o tym nie myślę na SW!)
Działa połowicznie, pokazuje mi tylko ref ^^'
Dla Save... Nic lepszego 
Z drugiej strony, przypadkiem, widzę, że gdy przechodzę z biblioteki projektów do formularza, ładuje się on ponownie zakończony. Dlaczego prosta przebudowa nie ładuje formularza wypełnionego przez właściwości?
CTRL+Q kontra F5
... F5 w Solidworks służy do pokazywania/ukrywania paska narzędzi filtru wyboru... 
To powiedziawszy, gryzę palce, gdy wykonuję CTRL+Q w innym oprogramowaniu...
Pytania:
Czy formularz jest aktywny po uruchomieniu makra?
Czy korzystasz z konfiguracji? (Jeśli tak jest, a Rekonstrukcja jest już częścią Pracy, myślę, że ta rekonstrukcja powinna zostać rozszerzona na wszystkie konfiguracje...)
zmień ForceRebuilt na ForceRebuild3(False)
Odpowiada CTRL+SHIFT+Q
Niestety ten sam efekt występuje w przypadku 2 "ForceRebuilds". Wyświetlany jest tylko mój ref, a nie oznaczenie. A jeśli poprosi mnie o zapisanie formularza, usuwa oznaczenie we właściwościach, tak jakby formularz stał się wzorcem.
Więc tak, formularz jest nadal aktywny. Do tej pory dobrze mi to odpowiadało, jeśli chodzi o zarządzanie wiadomościami w moich zespołach.
Wyłączanie i włączanie go działa. Ale dlaczego nie w moim makro? grrr powiedział:
Więc tak, może aktualizacja konfiguracji. Ale w tym egzemplarzu testowym mam tylko wadę.
Makro nie działa na formularz, ale na właściwości. Może da się go otworzyć zamkniętego przez API?
Prawdopodobnie
Ale tam! Daleko mi już do bycia asem w skali makro.
Wyobrażam sobie, że nie masz pakietu Mycad z Smartproperties... To rozwiąże wiele twoich problemów.
3 polubienia
Aby wypróbować w makrze:
swApp.ActivateTaskPane swDesignLibrary
…
[Twoje makro]
…
swApp.ActivateTaskPane swCustomProps
→ Zasadniczo symulujemy zmianę w panelu Okienko zadań (zakładki po prawej stronie Solidworks)
Dim swApp As Object
Dim swModel As ModelDoc2
Dim config As SldWorks.Configuration
Dim swCustProp As CustomPropertyManager
Dim lRetVal As Long
Dim maValeur0 As String
Dim maValeur1 As String
Dim maValeur2 As String
Dim maValeur3 As String
Dim maValeur4 As String
Dim maValeur5 As String
Dim maValeur6 As String
Dim maValeur7 As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
swApp.ActivateTaskPane swDesignLibrary
maValeur0 = swModel.GetTitle 'On récupère le nom du fichier
maValeur1 = Left(maValeur0, 6) 'On récupère les 6 premiers caractères du nom du fichier'
maValeur2 = Left(maValeur0, 12) 'On récupère les 12 premiers caractères du nom du fichier'
maValeur3 = Right(maValeur2, Len(maValeur2) - Len(maValeur1)) '2 moins 1'
maValeur4 = Right(maValeur0, 7) 'On récupère l'extension'
maValeur5 = Left(maValeur0, 13) 'On récupère les 13 premiers caractères du nom du fichier'
maValeur6 = Right(maValeur0, Len(maValeur0) - Len(maValeur5)) 'On récupére tout au delà du 13éme caractére'
maValeur7 = Left(maValeur6, Len(maValeur6) - Len(maValeur4)) 'on enlève l'extention à 5'
Set config = swModel.GetActiveConfiguration
Set cusPropMgr = config.CustomPropertyManager
lRetVal = cusPropMgr.Add3("N° Plan / Réf / Dim", swCustomInfoType_e.swCustomInfoText, maValeur3, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
lRetVal = cusPropMgr.Add3("Désignation", swCustomInfoType_e.swCustomInfoText, maValeur7, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
swApp.ActivateTaskPane swCustomProps
MsgBox "Formulaire complété" & Path, vbInformation
End Sub`
1 polubienie
Myślę , że @Maclane jest prawdą, a przynajmniej zbliża się do testu!
W przeciwnym razie znalazłem ten, który jest również do niego zbliżony, na niemieckim forum:
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
'Auf SW zugreifen
Set swApp = Application.SldWorks
'An aktives Dokument anklinken
Set swModel = swApp.ActiveDoc
swModel.CustomInfo("FTL-Besch") = "Hallo"
'Wechsel auf "SOLIDWORKS Ressourcen "
swApp.ActivateTaskPane (3) '(swTaskPaneTab_e.swResources)
'Wechsel auf "Benutzerdefinierte Eigenschaften"
swApp.ActivateTaskPane (5) '(swTaskPaneTab_e.swCustomProps)
End Sub
Wiosna:
https://ww3.cad.de/foren/ubb/Forum2/HTML/033024.shtml
Pomoc dotycząca edycji oprogramowania:
https://help.solidworks.com/2024/English/api/swconst/SolidWorks.Interop.swconst~SolidWorks.Interop.swconst.swTaskPaneTab_e.html?id=2e29ce3
1 polubienie
Cze wszystkim
Rozwiązanie @sbadenis sprawdza się doskonale.
Wielkie podziękowania dla was wszystkich za pomoc.
Oto mój ostateczny kod, jeśli może komuś pomóc
Dim swApp As Object
Dim swModel As ModelDoc2
Dim config As SldWorks.Configuration
Dim swCustProp As CustomPropertyManager
Dim lRetVal As Long
Dim maValeur0 As String
Dim maValeur1 As String
Dim maValeur2 As String
Dim maValeur3 As String
Dim maValeur4 As String
Dim maValeur5 As String
Dim maValeur6 As String
Dim maValeur7 As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
maValeur0 = swModel.GetTitle 'On récupère le nom du fichier
maValeur1 = Left(maValeur0, 6) 'On récupère les 6 premiers caractères du nom du fichier'
maValeur2 = Left(maValeur0, 12) 'On récupère les 12 premiers caractères du nom du fichier'
maValeur3 = Right(maValeur2, Len(maValeur2) - Len(maValeur1)) '2 moins 1'
maValeur4 = Right(maValeur0, 7) 'On récupère l'extension'
maValeur5 = Left(maValeur0, 13) 'On récupère les 13 premiers caractères du nom du fichier'
maValeur6 = Right(maValeur0, Len(maValeur0) - Len(maValeur5)) 'On récupére tout au delà du 13éme caractére'
maValeur7 = Left(maValeur6, Len(maValeur6) - Len(maValeur4)) 'on enlève l'extention à 5'
Set config = swModel.GetActiveConfiguration
Set cusPropMgr = config.CustomPropertyManager
lRetVal = cusPropMgr.Add3("N° Plan / Réf / Dim", swCustomInfoType_e.swCustomInfoText, maValeur3, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
lRetVal = cusPropMgr.Add3("Désignation", swCustomInfoType_e.swCustomInfoText, maValeur7, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
swModel.CustomInfo("FTL-Besch") = "Hallo"
swApp.ActivateTaskPane (3)
swApp.ActivateTaskPane (5)
MsgBox "Formulaire complété" & Path, vbInformation
End Sub
Nie jesteś pewien, czy ten wiersz jest przydatny, musi dodać właściwość FTL-Bessh z wartością "Hallo":
swModel.CustomInfo("FTL-Besch") = "Hallo"
Możesz podziękować @Maclane , bez których nigdy nie znalazłbym tego rozwiązania.
2 polubienia
Argg!, Byłem już prawie na miejscu! 
Dobra robota @sbadenis 
1 polubienie
Rzeczywiście
bez '''
swModel.CustomInfo("FTL-Besch") = "Hallo"
ça marche tout pareil.
Encore merci à tous !
1 polubienie
I wreszcie, mała kopia zapasowa na końcu nie zjada chleba.
Przyznaję, że często kombinuję trochę na miejscu. Może nie jest to optymalne, ale działa!
Dim swApp As Object
Dim part As Object
Dim swModel As ModelDoc2
Dim config As SldWorks.Configuration
Dim swCustProp As CustomPropertyManager
Dim lRetVal As Long
Dim maValeur0 As String
Dim maValeur1 As String
Dim maValeur2 As String
Dim maValeur3 As String
Dim maValeur4 As String
Dim maValeur5 As String
Dim maValeur6 As String
Dim maValeur7 As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
maValeur0 = swModel.GetTitle 'On récupère le nom du fichier
maValeur1 = Left(maValeur0, 6) 'On récupère les 6 premiers caractères du nom du fichier'
maValeur2 = Left(maValeur0, 12) 'On récupère les 12 premiers caractères du nom du fichier'
maValeur3 = Right(maValeur2, Len(maValeur2) - Len(maValeur1)) '2 moins 1'
maValeur4 = Right(maValeur0, 7) 'On récupère l'extension'
maValeur5 = Left(maValeur0, 13) 'On récupère les 13 premiers caractères du nom du fichier'
maValeur6 = Right(maValeur0, Len(maValeur0) - Len(maValeur5)) 'On récupére tout au delà du 13éme caractére'
maValeur7 = Left(maValeur6, Len(maValeur6) - Len(maValeur4)) 'on enlève l'extention à 5'
Set config = swModel.GetActiveConfiguration
Set cusPropMgr = config.CustomPropertyManager
lRetVal = cusPropMgr.Add3("N° Plan / Réf / Dim", swCustomInfoType_e.swCustomInfoText, maValeur3, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
lRetVal = cusPropMgr.Add3("Désignation", swCustomInfoType_e.swCustomInfoText, maValeur7, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
swApp.ActivateTaskPane (3)
swApp.ActivateTaskPane (5)
Set part = swApp.ActiveDoc
Dim swErrors As Long
Dim swWarnings As Long
boolstatus = part.Save3(1, swErrors, swWarnings)
MsgBox "Formulaire complété" & Path, vbInformation
End Sub
1 polubienie
Witam wszystkich, a szczególnie @Maclane , którzy dobrze mnie odblokowali.
Udało mi się mieć coś, co działa świetnie, a od wczoraj już nie działa.
Majstrowałem, bo w końcu nie zarządzam już konfiguracjami, które przy okazji sprawiały mi problemy.
Zakodowałem to:
Teraz usuwa typ mojej właściwości " text " i nie wypełnia już wartości.
Dim swApp As Object
Dim part As Object
Dim swModel As ModelDoc2
Dim swCustProp As CustomPropertyManager
Dim lRetVal As Long
Dim maValeur0 As String
Dim maValeur1 As String
Dim maValeur2 As String
Dim maValeur3 As String
Dim maValeur4 As String
Dim maValeur5 As String
Dim maValeur6 As String
Dim maValeur7 As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
maValeur0 = swModel.GetTitle 'On récupère le nom du fichier
maValeur1 = Left(maValeur0, 6) 'On récupère les 6 premiers caractères du nom du fichier'
maValeur2 = Left(maValeur0, 12) 'On récupère les 12 premiers caractères du nom du fichier'
maValeur3 = Right(maValeur2, Len(maValeur2) - Len(maValeur1)) '2 moins 1'
maValeur4 = Right(maValeur0, 7) 'On récupère l'extension'
maValeur5 = Left(maValeur0, 13) 'On récupère les 13 premiers caractères du nom du fichier'
maValeur6 = Right(maValeur0, Len(maValeur0) - Len(maValeur5)) 'On récupére tout au delà du 13éme caractére'
maValeur7 = Left(maValeur6, Len(maValeur6) - Len(maValeur4)) 'on enlève l'extention à 5'
lRetVal = swModel.DeleteCustomInfo("N° Plan / Réf / Dim")
lRetVal = swModel.AddCustomInfo3("", "N° Plan / Réf / Dim", PropertyManagerPage, maValeur3)
lRetVal = swModel.DeleteCustomInfo("Désignation")
lRetVal = swModel.AddCustomInfo3("", "Désignation", PropertyManagerPage, maValeur7)
'swApp.ActivateTaskPane (3)
'swApp.ActivateTaskPane (5)
Set part = swApp.ActiveDoc
Dim swErrors As Long
Dim swWarnings As Long
boolstatus = part.Save3(1, swErrors, swWarnings)
MsgBox "NOM : " + maValeur7 + " - N° :" + maValeur3 + " - Enregistré" & Path, vbInformation
End Sub
Witam
Myślę, że właśnie w tym miejscu coś idzie nie tak: lRetVal = swModel.AddCustomInfo3("", "N° Plan / Réf / Dim", PropertyManagerPage, maValeur3)
AddCustomInfo3 należy skonfigurować w następujący sposób:
value = instance.AddCustomInfo3(Configuration, FieldName, FieldType, FieldValue)
Więc myślę, że to FiledType jest źle poinformowany... Zamiast PorpertyManagerPage umieść swCustomInfoType_e.swCustomInfoText
2 polubienia
Nawiasem mówiąc, wszystkie twoje linie AddCustominfo3 mają zostać cofnięte...
=> Zobacz odpowiedź @Cyril_f, ale także poprzednie wersje makra...
https://help.solidworks.com/2022/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IModelDoc2~AddCustomInfo3.html
Aby przejść dalej:
AddCustominfo3 jest uważany za przestarzały (solidworks wersja 2022 i +)
Do zastąpienia przez Add3
Daje to:
wartość = wystąpienie. Add3(nazwa_pola, typ_pola, wartość_pola, nadpisanieIstniejące)
https://help.solidworks.com/2022/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.icustompropertymanager~add3.html
1 polubienie
Dobry... W każdym razie na początku, po prostu wykonując małą wymianę zaproponowaną przez @Cyril_f, wszystko idzie dobrze.
Poszedłbym głębiej z czystą głową. Tracę wiele neuronów, kiedy w to wchodzę .
Jesteś na szczycie!
Dziękuję.