Refreshing the form following a macro fill

Hello

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

End Sub'

Hello

I don't use the form, but a Ctrl+Q doesn't solve the problem? (by macro, forcerebuild)

2 Likes

Hello.
'+1 for reconstruction.
I'll add a record line.
swModel.Save3(swSaveAsOptions_Silent, lErrors, lWarnings)

2 Likes

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 :cry:

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 :grin: ... the F5 in Solidworks is used to show/hide the selection filter toolbar... :rofl:
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.

The macro does not act on the form but on the properties. Maybe it's possible to open it closed via APIs?

Probably
but there! I'm already far from being an ace in macro.

I imagine you don't have the Mycad suite with Smartproperties... it will solve a lot of your troubles.

3 Likes

To try in your macro:

swApp.ActivateTaskPane swDesignLibrary

[your macro]

swApp.ActivateTaskPane swCustomProps

→ 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`
1 Like

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

Spring:
https://ww3.cad.de/foren/ubb/Forum2/HTML/033024.shtml
Edit SW help:
https://help.solidworks.com/2024/English/api/swconst/SolidWorks.Interop.swconst~SolidWorks.Interop.swconst.swTaskPaneTab_e.html?id=2e29ce3

1 Like

Hi all

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

Not sure if this line is useful, it must add an FTL-Bessh property with "Hallo" as a value:

swModel.CustomInfo("FTL-Besch") = "Hallo"

You can thank @Maclane without whom I would never have found this solution.

2 Likes

Argg!, I was almost there! :grin:
Good job @sbadenis :stuck_out_tongue:

1 Like

Actually
without '''
swModel.CustomInfo("FTL-Besch") = "Hallo"

ça marche tout pareil.

Encore merci à tous !
1 Like

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
1 Like

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.
Capture

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

Hello

I think that's where it goes wrong: lRetVal = swModel.AddCustomInfo3("", "N° Plan / Réf / Dim", PropertyManagerPage, maValeur3)

AddCustomInfo3 should be set up as follows:

value = instance.AddCustomInfo3(Configuration, FieldName, FieldType, FieldValue)

So I think it's FiledType that is misinformed... Instead of PorpertyManagerPage, put swCustomInfoType_e.swCustomInfoText

2 Likes

By the way, all your AddCustominfo3 lines are to be taken back...
=> See @Cyril.f's answer but also the previous versions of the macro...
https://help.solidworks.com/2022/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IModelDoc2~AddCustomInfo3.html

To go further:
AddCustominfo3 is considered deprecated (solidworks version 2022 and +)
To be replaced by Add3
This gives:
value = instance. Add3(FieldName, FieldType, FieldValue, OverwriteExisting)
https://help.solidworks.com/2022/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.icustompropertymanager~add3.html

1 Like

Good... In any case, at first, just by doing the small replacement proposed by @Cyril.F, everything is going well.

I would go deeper with a clear head. I lose a lot of neurons when I get into it.

You're on top!
Thank you.