1 Reply Latest reply on Jan 21, 2013 3:19 AM by Yong Ning

    How to set oneself Material ?

    Yong Ning

      Set Material Property Name Example (VB)

      This example shows how to set a part's material property name.

      http://help.solidworks.com/2012/English/api/sldworksapi/set_material_property_name_example_vb.htm

       

      'Set Material Property Name Example (VB)

      'This example shows how to set a part's material property name.

       

      '------------------------------------------------------------------

      '

      ' Preconditions: Part document is open.

      '

      ' Postconditions: Model and part material property name changed to Alloy Steel.

      '

      '------------------------------------------------------------------

      'Option Explicit

      Sub main2()

          Dim swApp                       As SldWorks.SldWorks

          Dim swModel                     As SldWorks.ModelDoc2

          Dim swPart                      As SldWorks.PartDoc

          Dim i                           As Long

          Dim bRet                        As Boolean

         

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          Set swPart = swModel

         

          Debug.Print "File = " & swModel.GetPathName

          Debug.Print "  Old model material   = " & swModel.MaterialIdName

          Debug.Print "  Old part  material   = " & swPart.MaterialIdName

         

          ' Apply new material. This operation overwrites the information in

          ' ModelDoc2::MaterialIdName and PartDoc::MaterialIdName.

          swPart.SetMaterialPropertyName "SolidWorks Materials.sldmat", "Alloy Steel"

         

          Debug.Print "  New model material   = " & swModel.MaterialIdName

          Debug.Print "  New part  material   = " & swPart.MaterialIdName

      End Sub

      '---------------------------------------

       

       

      Help me,

       

      swPart.SetMaterialPropertyName "SolidWorks Materials.sldmat", "Alloy Steel"

       

      How to change sldmat, set oneselft material.

       

       

      a0.jpg

      Thanks .

       

      http://help.solidworks.com/2012/English/api/sldworksapi/get_and_set_material_visual_properties_example_vb.htm

        • Re: How to set oneself Material ?
          Yong Ning

          Sub Main1()

            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

            Dim swPart As SldWorks.PartDoc

            Dim sMatName As String

            Dim sMatDB As String

            Dim bRet As Boolean

             Set swApp = Application.SldWorks

             Set swModel = swApp.ActiveDoc

             Set swPart = swModel

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

            Debug.Print "File = " & swModel.GetPathName

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

          End Sub