Hi all
I'm currently working on a project to automate some folders and I'd like to integrate some features into my existing macro, which inserts and exports a BOM in an assembly in TXT format.
I thank those who will take the time to read me, and to give me a few moments to unblock myself. :)
The export and save part of the BOM is going well, but I have a problem when I try to retrieve the values of the properties of one of the components (the only one to have these properties): CLIENT, LOCAL, CPLT LOCAL, DEAL, DRAFTSMAN, QTE ASS) before copying them under the same name = value in the assembly.
I had tinkered with something by "manipulating" the exported Excel table based on:
AFFAIRE = Range("BG2:BG1000").Find("*", , , , xlByColumns).Value 'Cherche la première valeur non vide
On Error Resume Next
But this only works if the property does exist. In short, I would like to find a more precise and safe solution.
I've searched and tried a lot of bits of code and/or solutions found on the site or elsewhere, but I really don't know enough about APIs and VBA code to adapt it to my needs.
However, I have identified some interesting functions, of which here is an example below to simply read the CODE properties in a MsgBox. (that would already be a good step:) but unfortunately doesn't work)
Dim swSelMgr As SldWorks.SelectionMgr
Dim swSelComp As Variant
Dim swSelModel As SldWorks.ModelDoc2
Dim swCustPropMgr As CustomPropertyManager
Dim swEnt As SldWorks.Entity
Dim val As String
Dim valout As String
Set swSelComp = swBOMAnnotation.GetComponents2(2, Configuration)
Set swCustPropMgr = swSelComp.Extension.CustomPropertyManager("")
swCustPropMgr.Get4 "CODE", False, val, valout 'Change property name here
MsgBox "Value: " & val & "Evaluated value: " & valout
The final idea would therefore be to retrieve the component variable, copy it into the assembly, and then into each of the parts with the properties CODIFICATION ="X"
Do you have any advice and obvious corrections to share with me in order to unblock me? I thank you very much in advance. Do not hesitate to ask me for more details.
I'm attaching my two pieces of code, one of which is really rough and used for my research / test... The second is the simplest one that works when the properties are entered.
PS: I should point out that I don't have the myCADtools available.
Thank you all.
Michael
test_export_txt_nomenclature.swp