8 Replies Latest reply on Jul 3, 2015 2:46 PM by Adam Hoffman

    Material driven Cut List Properties

    Shaun Jalbert

      I have a script that goes through a bunch of routines, but the one of interest looks at any extruded plates and recognizes if the material assigned has "GRTG" in the name implying grating and if it does, then it pulls the material name (string) apart to populate the Cut List Properties. This function works really well.

       

      So we identified that we need another function to identify if the material has "EXP METAL" in the name implying expanded metal. If it does, then we want the Cut List Properties populated a certain way.

      The material is as follows:

      5.00#/SQ FT (CS) EXP METAL

       

      where:

      StockSize_Short = 5.00#/SQ FT

      Grade = CS

      Type = EXP METAL

       

      From this string, the following Cut List Properties would populate:

      StockSize = StockSize_Short x SW-3D-Bounding Box Width x SW-3D-Bounding Box Length x Type

      Description = Expanded Metal

       

      For reference, my plates, I've been using this string to populate the Stock Size and I want to use this method to populate both the SW-3D-Bounding Box Width & Length (noted above) the same way.

      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))

       

       

      Here's the Grating Code for Reference:

       

                   Dim sMaterial As String
                   sMaterial = GetFeatureCustomProp("Material", f)
                   If Not sMaterial = "" Then
                   Dim iP As Integer
                   iP = InStr(1, sMaterial, "GRTG")
                      'If the material is grating then let's change the values
                      If iP > 0 Then
                      ChangeCustomPropForGrating sMaterial, f
                      End If 'End of material being grating if
                   End If 'End of material being blank if

       

       

      Sub ChangeCustomPropForGrating(ByVal TheMaterial As String, ByVal TheFeature As SldWorks.Feature)

      Dim bRet                As Boolean

      Dim iGrtg               As Integer

      Dim iSpace              As Integer

      Dim sGrade              As String

      Dim sStockSize          As String

      Dim sStockSize_Short    As String

      Dim sType               As String

      sType = "GRTG"

      iGrtg = InStrRev(TheMaterial, sType)

      If iGrtg > 0 Then

         iSpace = InStr(1, TheMaterial, " ")

         sGrade = Left(TheMaterial, iSpace - 1)

         sStockSize = sGrade + " " + Trim(Mid(TheMaterial, iSpace, iGrtg - iSpace))

         sStockSize_Short = sGrade + " " + Trim(Mid(TheMaterial, iSpace, iGrtg - iSpace))

         bRet = TheFeature.CustomPropertyManager.Set2(propname5, sGrade)

         bRet = TheFeature.CustomPropertyManager.Set2(propname4, sStockSize)

         bRet = TheFeature.CustomPropertyManager.Set2(propname11, sStockSize_Short)

         bRet = TheFeature.CustomPropertyManager.Set2(propname3, sType)

         bRet = TheFeature.CustomPropertyManager.Set2(propname2, "BAR GRATING")

      End If

      End Sub

       

      How can I manipulate this to work as intended. I tried copying and pasting this and modifying, but I can't figure it out.

      (Full macro is attached)

       

      Thanks,

      Shaun

        • Re: Material driven Cut List Properties
          Adam Hoffman

          Shaun,

           

          Try looking through this macro as an example on how to do string manipulation in VB6.

          You may also want to reference this webpage whenever you need to process strings in VB6.

          I still do! Visual Basic 6 String Functions | Visual Basic 6 (VB6)

          Using these functions you should be able to add to your existing code accomplishing what you need.

          Hope this helps!

            • Re: Material driven Cut List Properties
              Shaun Jalbert

              Hi Adam:

              I actually referenced this link, maybe you sent it to me before, but I couldn't extract the information that I was after, it just kept the full string and not the portion that I required. I tried a few times and no success. I just couldn't figure it out and was spending too much time on it.

               

              I'll try it again, when I have some downtime and see how it goes.

               

              Shaun

                • Re: Material driven Cut List Properties
                  Shaun Jalbert

                  Hey Adam:

                   

                  I took another shot at it and no success.

                  I think the area that I'm have difficulty with is this portion below.

                   

                  I applied a material to a cut list body called:

                  5.00#/SQ FT (CS) EXP METAL

                   

                  After running the macro, I checked the custom properties and it seems like the function that checks if it's expanded metal or not isn't working because nothing changes.

                  Here's a screen shot of what I see and what I actually want edited beside the values.Screenshot_1.jpg

                   

                  And here's the code modification - basically a copy and paste of the grating code you provided me last week - but something is clearly wrong with the modifications that I attempted. What am I doing wrong?

                   

                             'Let's see if the material is expanded metal
                             Dim sExpMetalMaterial As String
                             sExpMetalMaterial = GetFeatureCustomProp("Material", f)
                             If Not sExpMetalMaterial = "" Then
                             Dim iPExpMetal As Integer
                             iP = InStr(1, sExpMetalMaterial, "EXP METAL")
                                 'If the material is expanded metal then let's change the values
                                 If iPExpMetal > 0 Then
                                 ChangeCustomPropForExpMet sExpMetalMaterial, f
                                 End If 'End of material being expanded metal if
                             End If 'End of material being blank if

                   

                   

                   

                  Sub ChangeCustomPropForExpMet(ByVal TheMaterial As String, ByVal TheFeature As SldWorks.Feature)

                  Dim bRet                As Boolean

                  Dim iExpMetal          As Integer

                  Dim iSpace              As Integer

                  Dim sGrade              As String

                  Dim sStockSize          As String

                  Dim sStockSize_Short    As String

                  Dim sType              As String

                  sType = "EXP METAL"

                  iExpMetal = InStrRev(TheMaterial, sType)

                  If iExpMetal > 0 Then

                    iSpace = InStr(1, TheMaterial, " ")

                    sGrade = Trim(Mid(TheMaterial, "(", iExpMetal - ")"))

                    sStockSize_Short = Left(TheMaterial, "(" - 1) + " " + Left(TheMaterial, iSpace - 1)

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

                    bRet = TheFeature.CustomPropertyManager.Set2(propname5, sGrade)

                    bRet = TheFeature.CustomPropertyManager.Set2(propname4, sStockSize)

                    bRet = TheFeature.CustomPropertyManager.Set2(propname11, sStockSize_Short)

                    bRet = TheFeature.CustomPropertyManager.Set2(propname3, sType)

                    bRet = TheFeature.CustomPropertyManager.Set2(propname2, "BAR GRATING")

                   

                   

                  End If

                  End Sub

                    • Re: Material driven Cut List Properties
                      Tapani Sjoman

                      Hello Shaun, you should at least change "ByVal" to "ByRef" before each item you want to make any affect in your sub.

                      • Re: Material driven Cut List Properties
                        Shaun Jalbert

                        Well, I played with this some more and have it 95% working.
                        I can't get my stock size to populate, but if I comment out the following line, all seems to work just fine.

                        bRet = TheExpMetFeature.CustomPropertyManager.Set2(propname4, proptype, Chr$(34) + sStockSize_Short + "x" + Chr$(34) + "SW-3D-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) + " " + sType + Chr$(34)

                         

                        The Value should populate as:

                        "5.00#/SQ FT x "SW-3D-Bounding Box Width@@@MK-731064-07@test.SLDPRT" EXP METAL"

                        it should evaluate to:

                        5.00#/SQ FT x 8'-4 3/16" EXP METAL

                         

                        Below is the main parts of the code:

                        Can you see what's wrong with it?

                         

                                   'Let's see if the material is expanded metal
                                   Dim sExpMetalMaterial As String
                                   sExpMetalMaterial = GetFeatureCustomProp("Material", f)
                                   If Not sExpMetalMaterial = "" Then
                                   Dim iPExpMetal As Integer
                                   iPExpMetal = InStr(1, sExpMetalMaterial, "EXP METAL")
                                       'If the material is expanded metal then let's change the values
                                       If iPExpMetal > 0 Then
                                       ChangeCustomPropForExpMet sExpMetalMaterial, f
                                       End If 'End of material being expanded metal if
                                  

                        End If 'End of material being blank if

                         

                         

                        Sub ChangeCustomPropForExpMet(ByVal TheExpMetMaterial As String, ByVal TheExpMetFeature As SldWorks.Feature)

                        Dim swApp As SldWorks.SldWorks

                        Set swApp = Application.SldWorks

                        Dim bRet                As Boolean

                        Dim iExpMetal          As Integer

                        Dim iSpace              As Integer

                        Dim sGrade              As String

                        Dim sStockSize          As String

                        Dim sStockSize_Short    As String

                        Dim sType              As String

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

                        Dim f As IFeature: Set f = doc.FirstFeature

                         

                        sType = "EXP METAL"

                        iExpMetal = InStrRev(TheExpMetMaterial, sType)

                        If iExpMetal > 0 Then

                          sStockSize_Short = Left(TheExpMetMaterial, iExpMetal - 2)

                          sGrade = Mid(TheExpMetMaterial, iExpMetal + Len(sType) + 2, 2)

                          bRet = TheExpMetFeature.CustomPropertyManager.Set2(propname5, sGrade)

                          bRet = TheExpMetFeature.CustomPropertyManager.Set2(propname4, proptype, Chr$(34) + sStockSize_Short + "x" + Chr$(34) + "SW-3D-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) + " " + sType + Chr$(34)

                          bRet = TheExpMetFeature.CustomPropertyManager.Set2(propname11, sStockSize_Short)

                          bRet = TheExpMetFeature.CustomPropertyManager.Set2(propname3, sType)

                          bRet = TheExpMetFeature.CustomPropertyManager.Set2(propname2, "EXPANDED METAL")

                        End If

                        End Sub

                          • Re: Material driven Cut List Properties
                            Shaun Jalbert

                            I figured it out... Combination of things... but this fixed it.

                             

                               bRet = TheExpMetFeature.CustomPropertyManager.Delete(propname4)

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

                      • Re: Material driven Cut List Properties
                        Shaun Jalbert

                        By the way, thanks Adam Hoffman. I couldn't of done this without your example.

                         

                        Cheers,

                        Shaun