I'll need help, I've been working on it for quite some time without managing to move forward.
I would like to create a macro that would automatically populate the properties of the welded parts list with some specific properties. Here's the algorithm that I'd like the macro to do.
- Detect in the list of welded parts which are sheets
- If it is a sheet metal then recover the thickness of the sheet metal and the material.
- Create two properties "CODE" and "DETAIL" whose values will vary according to the thickness of the sheet and the material (e.g. for a 2mm sheet in S235 steel: CODE = 02156 and DETAIL=Black sheet 2mm thick - for a 5mm sheet in stainless steel: CODE = 02582 and DETAIL=Stainless steel sheet 5mm thick.
Today I can only make a macro that creates these properties on the first article but without assigning a variable value (I can't do much in summary).
I know I ask a lot but it would save me a lot of time.
Thanks in advance,
Moe
For your information, I'm still on SolidWorks 2012
Good evening, without the macro it will be difficult to improve it! Can you post it in a text file please?
But I think it would be wiser to break down your problems to ask several questions: it will be clearer for everyone and you will have a lot more answers rather than asking for a complete ready-made macro!
The first question would be: how do you check if a part is sheet metal with the PLCs?
The Mycad support has just told me that it was not possible to filter according to whether it is a sheet metal or a mechanically welded element. But I think it must be possible to filter by another property (example: when you create a sheet, SW creates a "Folds" property that it doesn't create in other cases).
In fact, we have sheets made of 304L stainless steel, 304L RAW STAINLESS STEEL, 316L stainless steel and 316L RAW STAINLESS steel and thicknesses of 1, 1.5, 2, 3 and 5mm with a specific CODE for each sheet.
I'd like to be able to run a macro that automatically adds a "CODE" property to the "Sheet" body based on the thickness and material chosen.
Have you managed to get your macro to work since then?
Note: I have SolidWorks configured in English so you will need to replace "Sheet Metal Thickness" and "Material" with the thickness and material properties of the parts.
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim custPrpMgr As SldWorks.CustomPropertyManager
Dim myThickness As String
Dim myMaterial As String
Dim myCode As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then Exit Sub
Set swFeat = swModel.FirstFeature
While Not swFeat Is Nothing
If swFeat.GetTypeName2 = "CutListFolder" Then
Set custPrpMgr = swFeat.CustomPropertyManager
custPrpMgr.Get2 "Sheet Metal Thickness", "", myThickness
Debug.Print "Epaisseur: " & myThickness
custPrpMgr.Get2 "Material", "", myMaterial
Debug.Print "Materiel: " & myMaterial
Select Case myMaterial
Case "INOX 304L"
Select Case myThickness
Case "1"
myCode = "0001"
Case "1.5"
myCode = "0002"
Case "2"
myCode = "0003"
Case "3"
myCode = "0004"
Case "5"
myCode = "0005"
End Select
Case "INOX 304L BRUT"
Select Case myThickness
Case "1"
myCode = "0011"
Case "1.5"
myCode = "0012"
Case "2"
myCode = "0013"
Case "3"
myCode = "0014"
Case "5"
myCode = "0015"
End Select
Case "INOX 316L"
Select Case myThickness
Case "1"
myCode = "0021"
Case "1.5"
myCode = "0022"
Case "2"
myCode = "0023"
Case "3"
myCode = "0024"
Case "5"
myCode = "0025"
End Select
Case "INOX 316L BRUT"
Select Case myThickness
Case "1"
myCode = "0031"
Case "1.5"
myCode = "0032"
Case "2"
myCode = "0033"
Case "3"
myCode = "0034"
Case "5"
myCode = "0035"
End Select
End Select
Debug.Print "Code: " & myCode
Debug.Print
custPrpMgr.Delete "CODE"
custPrpMgr.Add2 "CODE", swCustomInfoType_e.swCustomInfoText, myCode
End If
Set swFeat = swFeat.GetNextFeature
Wend
End Sub