9 Replies Latest reply on Mar 9, 2018 4:37 AM by Deepak Gupta

    Macro to modify property value

    Emilio Mercado

      Hello I´m new with the use of visual basic in solidworks and I need help with a basic application. After using Property Tab Builder I´m able to set the properties required in my shop BOM´s, but I´d like to automatically set the Description text value depending on the Thickness value. I think Case function could be used to list all the possible cases but I´m not really sure how it can be done.


      For example, in this case I´d like to get "Plate 15".


      Thank you

        • Re: Macro to modify property value
          Carrie Ives

          Just put the thickness property in as part of the description property. I put the project into my description in the example below.

          So, put in:

          Plate $PRP:"Calibre"

          Sometimes SolidWorks seems to care about upper/lower case on properties.

            • Re: Macro to modify property value
              Emilio Mercado

              Thank you Carrie! Well, this could work if "Plate" is always on the text, that should be a variable too. On Description I need to put the commercial name of the sheet metal thickness, below I list some other examples:

              • Thickness: 1.5           Description: LAM C16
              • Thickness: 1.9           Description: LAM C14
              • Thickness: 0.91           Description: LAM C20
              • Thickness: 15           Description: Plate 15
              • Thickness: 6          Description: Plate 6
                • Re: Macro to modify property value
                  Carrie Ives

                  Think about where you can afford manual steps and how many people are going to be touching this. Is there a fairly short list? Can you trust the people working on parts to do it right? If it is a short list and you have people that pay attention, I would just have a drop down in the property tab builder for them to pick the right description.


                  If is a longer list and you need more automation, you may want to look at a macro. I'm just learning macros. There are examples of ones that will let you get the custom property information. So, starting from one of those, you could read the thickness. Then based on the thickness, set the description. I'm sure there is a better way than if statements, but that's what I've used for things so far.


                  Are you using gauge tables or anything like that to drive your thicknesses? I don't know if you could pull something from that to help with the description. I don't know what information is in the gauge tables. I don't see anything obvious when I make a sheetmetal part.


                  Good luck,


                    • Re: Macro to modify property value
                      Emilio Mercado

                      I´ve been using a drop down list in the property tab builder in the past and the people were making mistakes picking the wrong description. That´s the problem I´m looking to solve through automation. The list is not as short as the one I wrote above, it was just a quick example.

                      I need the macro to read the existing value of thickness, so it can set the description automatically. I suggested Case statement instead of If because I´ve read something about, but not really sure how to write it on the code.

                        • Re: Macro to modify property value
                          Deepak Gupta

                          Do all the parts in you assembly are sheet metal parts? If yes then automation would be easier and macro can be made to traverse the top level assy and update the property for every single component (part). 


                          You can use the case codes as

                          Select Case sThickness ' You need to get the part thickness value in MM

                                  Case "1.5"

                                      Description= "LAM C16"

                                  Case "1.9"

                                      Description= "LAM C14"

                                  Case "0.91"

                                      Description= "LAM C20"

                                  Case "15"

                                      Description= "PLATE 15"

                                  Case "6"

                                      Description= "PLATE 6"

                                  Case Else

                                     Description= "THICKNESS UNKNOWN"

                          End Select


                          But if the answer is no, then you would have to define a property for the thickness (which macro can read) OR do it manually.

                  • Re: Macro to modify property value
                    Matt Peneguy

                    Seems like it'd be easier just to link it to the dimension?

                    Just open the Custom Properties, put the cursor in the box and double click the part and select the dimension.  It'll put the dimension name in there and then you'll have the value in the custom property, no macro necessary.

                    Edit to add: Carrie Ives, ya beat me to it!  Good Job!

                      • Re: Macro to modify property value
                        Emilio Mercado

                        It´s easier but sometimes I work with large assemblies, so I will spend a lot of time opening the property window and linking the property with the dimension on the model. With a macro I´m looking to simplify this by just clicking a macro button

                          • Re: Macro to modify property value
                            Matt Peneguy

                            The problem with what you are suggesting is that without a handle, it is hard to get the "thickness".  If you are using Sheetmetal, it may work (I don't know much about sheetmetal).  But, if you are using plain SW part templates, unless all of these parts have the same handle (dimension name) this may be hard to code into a macro.

                            Edit to Add:

                            But, the second part of what you are asking for, a look up table that cross lists the thickness to a text field, should be easy enough to do with a macro.  Solving the first part of your problem is the difficult part.  Maybe you could post up a sample part or two for people to look at?