4 Replies Latest reply on Nov 11, 2016 5:44 AM by Klaus Massler

    Can I change material without taking the appearance?

    Aaron Torberg

      Hey all,

       

           I would like to have macro that sets a specific material but I do not want the appearance of the model to change.  Can I do this?  I thought I could get the original appearance, change the material, then change the appearance back like this but its not working...?  I am pretty new to the whole api thing so go easy on me if I have made a rookie mistake...   Thanks.

       

      DisplayChange.JPG

        • Re: Can I change material without taking the appearance?
          Patrick Colliflower

          Let me preface and say I'm very new to macros etc...

           

          I recorded this macro while changing a material, and unchecked the "apply material appearance" as shown below.

          1006.PNG

          Maybe you can use it in your coding? Seems to work for me.

           


          Dim swApp As Object

          Dim Part As Object
          Dim boolstatus As Boolean
          Dim longstatus As Long, longwarnings As Long

          Sub main()

          Set swApp = _
          Application.SldWorks

          Set Part = swApp.ActiveDoc
          Dim myModelView As Object
          Set myModelView = Part.ActiveView
          myModelView.FrameState = swWindowState_e.swWindowMaximized
          boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 0, Nothing, 0)
          boolstatus = Part.Extension.SelectByID2("Unknown", "BROWSERITEM", 0, 0, 0, False, 0, Nothing, 0)
          Part.ClearSelection2 True
          Part.SetMaterialPropertyName2 "Default", "C:/Program Files/SolidWorks Corp/SOLIDWORKS (2)/lang/english/sldmaterials/SOLIDWORKS Materials.sldmat", "6061 Alloy"
          Part.ClearSelection2 True
          End Sub

            • Re: Can I change material without taking the appearance?
              Aaron Torberg

              Thanks for the reply Patrick, I tried this also and had no luck.  Our materials property database is in EPDM so without checking out the database I think I cannot permanently set the material appearance tab to not include the appearance.  That is why I'm trying to get the appearance first then restore it after the material change.

                • Re: Can I change material without taking the appearance?
                  Aaron Torberg

                  Figured it out... Thanks for the help!

                   

                   

                  Option Explicit

                   

                  Sub main()

                   

                      Dim swApp As SldWorks.SldWorks

                      Dim myModel As SldWorks.ModelDoc2

                      Dim myPart As SldWorks.PartDoc

                      Dim myMatVisProps As SldWorks.MaterialVisualPropertiesData

                      Dim longstatus As Long

                   

                      Set swApp = Application.SldWorks

                      Set myModel = swApp.ActiveDoc

                      Set myPart = myModel

                      Set myMatVisProps = myPart.GetMaterialVisualProperties()

                   

                      myMatVisProps.ApplyAppearance = False

                      longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swAllConfiguration, Nothing)

                      myPart.SetMaterialPropertyName2 "Default", "Lanco Materials", "ALUMINUM 6061-T6"

                   

                  End Sub