Hello
I'm looking for a macro that will allow me to extract the part family from a part file.
And that this macro is carried out for an entire folder (containing X part file)
I specify that the pieces do not have the family part to create.
What interests me is to retrieve ONE property common to all my parts in an Excel file.
Ideas are welcome.
Thank you
1 Like
Hello
I'm sharing a macro I made that has most of the functions you need (search in a folder and subfolder of SW parts; read and modify custom properties; fill in a text file)
Be careful it's a bit of a mess because it doesn't finalize
macrorecusive.txt
Hello slauzeral,
But your macro doesn't help me much.
Thank you for your help!
1 Like
remrem
August 30, 2016, 2:04pm
4
Hello
To be sure to understand. You want a macro that:
Loops .sldprt and .sldasm files from a folder Recovers a property of each of the files Adds the value of the property to an Excel table.
2 Likes
Hi remrem,
When you say "loop files" what do you mean?
Otherwise yes, I specify that there are only .sldprt files
For the rest that's it,
Recovers a property of each of the files Adds the value of the property to an Excel table
1 Like
remrem
August 30, 2016, 3:34pm
6
Therefore
Searches for .sldprt files in a folderRecovers a property of each of the files Adds the value of the property to an Excel table. What is the name of the property?
Do I have to go back to the workbook information about each of the files: Name, path, etc?
Should we also search in the subfolders?
Have you ever made other macros?
Is it possible to have a folder with consistent files to test?
I know that's a lot of questions, but it's essential before coding anything. ;-)
2 Likes
Yes, that's exactly it:
"Searches for .sldprt files in a folder
Recovers a property of each of the files
Adds the value of the property to an Excel spreadsheet."
For your questions:
What is the name of the property? $PROPRIETE@Number of Holes .
Do I have to go back to the workbook information about each of the files: Name, path, etc? No, only the field of property .
Should we also search in the subfolders? No, the documents are directly in a file.
Have you ever made other macros? For the macro ones, I arrived "by groping" by picking up pieces right and left...
I attach a file with 5 pieces to test.
lynkoa.zip
Hello
You should look with this formula:
Sub parametre()
Dim retVal As Boolean Dim Property As String piece = Sheets("Chemin_pièce"). Range("A1") Opens file links
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.OpenDoc6(piece, 1, 0, "", longstatus, longwarnings)
Set swModel = swApp.ActiveDoc Set swConfigMgr = swModel.ConfigurationManager Set swConfig = swConfigMgr.ActiveConfiguration Z=swConfig.Name 'Retrieves the name of the configuration property = swModel.GetCustomInfoValue(Z, "Weight") Sheets("Sheet1"). Range("A1"). Value = ' property 'copies' the value of the 'weight' property into the Excel sheet
End Sub
You should try with that, then you have to create the loop that allows you to around it.
Good luck
1 Like
Hi PierrotDls,
Thanks for the macro,
It's a very good start !!
It allows me to retrieve the property for the defined part.
Now I have to find:
- How to open the ".sldprt" files of a folder and not a specific file.
- Increment the "A1" cell so that the properties fill in one below the other.
Thank you!
Good evening
Attached is a snippet of code to scan the file.
Just add the functions to retrieve the property you are looking for and it should work.
scan_dossier.txt
1 Like
Hi Cyril.f
Thanks for the macro,
But when I add the recovery lines of my property I have a direct compilation error.
Dim fso As FileSystemObject
A user-defined type not defined.
If you can help me... Thank you
Cyril.f
September 1, 2016, 9:31am
12
Hello
You need to activate the following references in the vba editor (tools> References):
Microsoft Scripting Runtime
Solidworks 20xx type library
1 Like
Yes indeed that's what I just saw.
So perfect (well the macro is probably not the cleanest and simplest but it works)
Thank you!