I have a small macro that retrieves elements of the file name. Ready to complete the form in order to avoid discrepancies between ' file name' and ' nomenclature info' for automated management that comes later... The properties fill in well but the form appears empty. I can do F5 or rebuild, nothing happens
What can I add to the end of my macro to refresh the form? Basically, you have to open the 3D for the form to display correctly, while at that time, in parallel, the cartouche of the part plan is completed...
Here's my code
Dim swApp As Object Dim swModel As ModelDoc2 Dim config As SldWorks.Configuration Dim swCustProp As CustomPropertyManager Dim lRetVal As Long Dim myValue0 As String Dim myValue1 As String Dim myValue2 As String Dim myValue3 As String Dim myValue4 As String Dim myValue5 As String Dim myValue6 As String Dim myValue7 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)
MsgBox "Formulaire complété" & Path, vbInformation
Ctrl+Q (It's so "leaving" home that I never think about it on SW!) it works halfway, it only shows me the ref ^^'
For the Save... Nothing better
On the other hand, by chance, I see that when I go from the design library to the form, it reloads completed. Why doesn't a simple rebuild load the form filled in by the properties?
CTRL+Q versus F5 ... the F5 in Solidworks is used to show/hide the selection filter toolbar... That said, I bite my fingers when I do a CTRL+Q in another software... Questions: Is your form active when you launch the macro? Do you use configurations? (If this is the case, and the Reconstruction is already part of the Job, I think that this reconstruction should be extended to all configurations...) change ForceRebuilt to ForceRebuild3(False) Corresponds to CTRL+SHIFT+Q
Unfortunately the same effect for the 2 "ForceRebuilds". Only my ref is displayed, not the designation. And if it asks me to save the form, it removes the designation in the properties as if the form became master.
So yes, the form is still active. Until now it suited me well to manage the news in my ensembles. Turning it off and on works. But why not in my macro? grrr
So yes, maybe an update of the configs. But in this test piece I have only the flaw.
→ Basically, we simulate a change in the TaskPane panel (tabs on the right of 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`
I think @Maclane holds the truth or at least comes close to testing! Otherwise I found this one that is also close to it, on a German 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
The solution of @sbadenis works perfectly. A big thank you to all of you for your help.
Here is my final code, if it can help anyone
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
And finally, a little backup at the end doesn't eat bread.
I often combine a little bit on the spot, I admit. It may not be optimal, but it works!
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
Hello everyone and especially @Maclane who had unblocked me well. I had managed to have something that works great, and since yesterday, it doesn't work anymore. I had tinkered because finally I no longer manage configs that were causing me problems by the way. I coded this: Now it deletes the type of my " text " property and no longer fills in the value.
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