4 Replies Latest reply on Jul 12, 2014 5:12 PM by Sanya Shmidt

    How to Read Material

    Sanya Shmidt

      Hello everyone,

       

      I need a little help with writing the code. Still monkeing around with assigning material properies...

       

      I know how to set material for the part:

       

      swModel.SetMaterialPropertyName2("Default", MaterialDB, "ASTM A36 Steel") ' (config, DBpath, material)

       

      But I don`t know how to read it to a variable? Can someone help?

       

      Thank you,

      Alex.

        • Re: How to Read Material
          Deepak Gupta

          But I don`t know how to read it to a variable? Can someone help?

          What you mean by that. Do you mean adding the custom property for the model and setting the value as the applied material OR something different.

            • Re: How to Read Material
              Sanya Shmidt

              I want to right a macro which will read Material from material library to a variable.

               

              For example I can read a custom property into the variable:

              PartType = swModel.CustomInfo2("", "Part Type")

               

              Can I read assigned material from material DB into a variable:

              something like

               

              _Material=swModel.MaterialPropertyName ???

               

              Thanks,

                • Re: How to Read Material
                  Deepak Gupta

                  Yes

                   

                  Option Explicit

                   

                  Sub main()

                   

                   

                      Dim swApp                      As SldWorks.SldWorks

                      Dim swModel                   As SldWorks.ModelDoc2

                      Dim swPart                      As SldWorks.PartDoc

                      Dim sMatName                As String

                      Dim sMatDB                    As String

                    

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                      Set swPart = swModel     

                   

                     sMatName = swPart.GetMaterialPropertyName2("Default", sMatDB)  

                   

                      Debug.Print "  Material = " & sMatName & " (" & sMatDB & ")"

                   

                  End Sub