Weldment BOM - Plate vs. Grating

When we create our grating for work platforms, etc., we model it as an extruded plate feature with no details. Of course, this throws off the weight, so I've combated this by adding a material in our database that corrects the mass by fudging a density so that the weight per square foot matches real life. this all works OK, but here's where my problem is...

I run a macro (shown below) that does several things.

1) it renames the weldment folders

2) Creates a bounding box

3) Adds a mass (for BOM)

4) Adds a type (for BOM)

5) Determines if a member is a plate or bent sheet metal (for BOM)

  5a) Modifies the Stock Size

  5b) Adds the Length

  5c) Modifies the description to suit

My issue is that this macro identifies my grating as a plate and my BOM populates with plate.

I didn't create the macro, I've only modified it to suit so i don't know if this is even possible, but is it possible to add a lookup function on the plate material and if it matches "W19-4 1 1/2" x 3/16" GRTG" to populate the properties as such:

Grade= W19-4

Stocksize=  1 1/2" x 3/16"

Length= (as per bounding box)

Type= GRTG

Description= Grating

My concern is that the grating material name could vary according to size (ex. W19-4 1” x 1/8” GRTG, or SP19-2 2 1/2” x 3/16” GRTG).

Any suggestions on how to modify this code to suit?

!

Option Explicit

Private Const propname1 As String = "Mass" ' change to "MASS" or whatever you prefer

Private Const propname2 As String = "Description"

Private Const propname3 As String = "Type"

Private Const propname4 As String = "StockSize"

Private Const propname5 As String = "Grade"

Private Const propname6 As String = "Length"

Private Const propname7 As String = "Mark"

Private Const propname8 As String = "PARTNUMBER"

Private Const propname9 As String = "Sheet Metal Thickness"

Private Const propname10 As String = "ANGLE1"

Private Const proptype As String = "Text" ' in english you must change to "Text". See comment in code…

Dim swApp As Object

Sub Main()

Dim swApp As SldWorks.SldWorks

Set swApp = Application.SldWorks

Dim doc As SldWorks.ModelDoc2: Set doc = swApp.ActiveDoc

Dim partdoc As SldWorks.partdoc: Set partdoc = doc

Dim f As IFeature: Set f = doc.FirstFeature

Dim bRet As Boolean

Dim n As Integer: n = 0

Dim num As String

Dim modDocExt As SldWorks.ModelDocExtension

Dim Part As Object

Dim boolstatus As Boolean

Dim BodyFolder As SldWorks.BodyFolder

Dim BodyCount As Long

Do While Not f Is Nothing

If f.GetTypeName = "CutListFolder" Then

       

        Set BodyFolder = f.GetSpecificFeature2

        BodyCount = BodyFolder.GetBodyCount

    If BodyCount > 0 Then

        n = n + 1

        If n < 1000 Then

        num = "-" + Right(Str\$(n), Len(Str\$(n)) - 1)

        End If

        If n < 100 Then

        num = "-" + Right(Str\$(n), Len(Str\$(n)) - 1)

        End If

        If n < 10 Then

        num = "-0" + Right(Str\$(n), Len(Str\$(n)) - 1)

    End If

End If

If Right(doc.GetTitle, 7) = ".SLDPRT" Or Right(doc.GetTitle, 7) = ".SLDASM" Then

    f.Name = Left(doc.GetTitle, Len(doc.GetTitle) - 7) + num

Else

    f.Name = Left(doc.GetTitle, Len(doc.GetTitle)) + num

End If

'f.Name = Left(Right(doc.GetTitle, 10), 3) + num

'add 3d bounding box

   Set Part = swApp.ActiveDoc

   Set modDocExt = Part.Extension

   boolstatus = modDocExt.SelectByID2(f.Name, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)

   modDocExt.Create3DBoundingBox

  

            

               

                'del Mark and PARTNUMBER

                bRet = f.CustomPropertyManager.Delete(propname7)

                bRet = f.CustomPropertyManager.Delete(propname8)

               

                'mass

                bRet = f.CustomPropertyManager.Delete(propname1)

                bRet = f.CustomPropertyManager.Add(propname1, proptype, Chr\$(34) + "SW-Mass@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                'bRet = f.CustomPropertyManager.Add(propname1, proptype, Chr\$(34) + "SW-Mass@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + " kg")

                'If f.CustomPropertyManager.Add(propname1, proptype, Chr\$(34) + "SW-Mass@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "kg") Then

                'Debug.Print "Property "; propname1; " added to feature "; f.Name

                'End If

               

                'desc

                'If f.CustomPropertyManager.Add(propname2, proptype, "PLATE") Then

                'Debug.Print "Property "; propname2; " added to feature "; f.Name

                'End If

               

                'type

                If f.CustomPropertyManager.Add(propname3, proptype, "PL") Then

                Debug.Print "Property "; propname3; " added to feature "; f.Name

                End If

               

               

                'Plate & Formed Plate stocksize and Length and desc

                If f.CustomPropertyManager.Get(propname10) = "" Then

                   If f.CustomPropertyManager.Get(propname9) = "" Then

                       bRet = f.CustomPropertyManager.Delete(propname4)

                       bRet = f.CustomPropertyManager.Add(propname4, proptype, Chr\$(34) + "PL" + "SW-3D-Bounding Box Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-3D-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                       bRet = f.CustomPropertyManager.Delete(propname6)

                       bRet = f.CustomPropertyManager.Add(propname6, proptype, Chr\$(34) + "SW-3D-Bounding Box Length@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                      

                       'desc plate

                       bRet = f.CustomPropertyManager.Delete(propname2)

                       bRet = f.CustomPropertyManager.Add(propname2, proptype, "PLATE")

   

                       'If f.CustomPropertyManager.Add(propname4, proptype, Chr\$(34) + "SW-3D-Bounding Box Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-3D-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) Then

                       'Debug.Print "Property "; propname4; " added to feature "; f.Name

                       'End If

                   Else

                       bRet = f.CustomPropertyManager.Delete(propname4)

                       bRet = f.CustomPropertyManager.Add(propname4, proptype, Chr\$(34) + "PL" + "SW-Sheet Metal Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

   

                       bRet = f.CustomPropertyManager.Delete(propname6)

                       bRet = f.CustomPropertyManager.Add(propname6, proptype, Chr\$(34) + "SW-Bounding Box Length@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                      

                       'desc formed plate

                       bRet = f.CustomPropertyManager.Delete(propname2)

                       bRet = f.CustomPropertyManager.Add(propname2, proptype, "FORMED PLATE")

                      

                       'If f.CustomPropertyManager.Add(propname4, proptype, Chr\$(34) + "SW-Sheet Metal Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) Then

                       'Debug.Print "Property "; propname4; " added to feature "; f.Name

                       'End If

                   End If

                Else

                End If

              

                'grade

                If f.CustomPropertyManager.Add(propname5, proptype, Chr\$(34) + "SW-Material@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) Then

                Debug.Print "Property "; propname5; " added to feature "; f.Name

                End If

                             

End If

Set f = f.GetNextFeature

Loop

End Sub

SolidworksApi macros