4 Replies Latest reply on Jun 22, 2015 6:33 AM by Deepak Gupta

    Help with an if statement macro

    Leslie Terry



      I am hoping there is someone who can assist me with or advise me on an ''if statement'' macro.


      I am hoping it would be possible to run an ''if statement'' when importing Solid Edge files that would look for certain information within delimiters to create a custom property for the part. To give an example:


      Part Name : 1522-658-15-001

      Custom Property : Material Type - SPC (Mild steel - 15)


      I want to find out if it would be possible to get a macro to pick up on a 2 digit field within a part name in order to populate custom properties with a material type. If there is anyone who could assist me with this, any help on the matter would be greatly appreciated.





        • Re: Help with an if statement macro
          Deepak Gupta

          Hi Leslie this seems possible. Do you've all the files in the same file nomenclature i.e. XXXX-XXX-XX-XXX. And how many different material names would be there?


          Also can you please remove all other two same posts so that people can reply on the same post here.


          The specified item was not found.

          The specified item was not found. 

            • Re: Help with an if statement macro
              Deepak Gupta

              Here are the codes you can try. Make sure file is saved before using it. Add the further cases are required as I've tested only two of them.


              Dim swApp                   As SldWorks.SldWorks

              Dim swModel                 As SldWorks.ModelDoc2

              Dim sFileName               As String

              Sub main()


              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc


              sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

              sFileName = Left(sFileName, InStrRev(sFileName, ".") - 5)

              sFileName = Right(sFileName, 2)


              Select Case sFileName

                  Case 29

                      swModel.AddCustomInfo2 "Material Type", swCustomInfoText, "BRASS(C2801)"

                  Case 30

                      swModel.AddCustomInfo2 "Material Type", swCustomInfoText, "COPPER(C1100)"

                  Case Else

              End Select

              End Sub

            • Re: Help with an if statement macro
              Leslie Terry

              Hi again Deepak Gupta,


              Thanks for the reply! As requested, below is a brief overview of how I managed to use your assistance in resolving the importing of Solid Edge assemblies to be batch unfolded by the Sheetworks for Unfold Unfolding Operator.


              The Unfold Operator has a feature written into it that opens 3D Cad Assemblies and generates flat pattern data to be saved into the Amada Software database for processing on Sheet metal CNC machines. As Sheetworks is based on Solidworks, there are some limitations to importing other files in that no custom property data is extracted from the imported files. Using the base information you assisted me with, I managed to modify the code slightly to allow for all of the required material fields needed as well as for different part name lengths. Once this was done, I configured the Unfold Operator to run the macro at time of opening part files in order to populate the custom properties with a base material type that was linked to the Amada database. I then instructed the Unfold Operator to analyse the thickness of the part from the front face which would then allowed the software to define a material type and thickness to the part. Once this is applied to the part, flat pattern data as well as Product Data is created and saved to the Amada Database for processing on the CNC machines (Laser, Turret Punch, Bending, etc.)


              I have saved a screen shot below of the Unfold Operator with the settings described above for reference purposes. You have helped me to resolve an issue that I could not overcome without manual data input because of the limitations imposed by the importing of foreign 3D models. Solidworks is a great package and with the forum and individuals like yourself who are able and willing to assist users, Solidworks will remain the greatest 3D CAD package!


              Thank you again for your help, it is very much appreciated!


              Sheetworks For Unfold by Amada.jpg