7 Replies Latest reply on Mar 29, 2016 4:13 AM by Deepak Gupta

    How to change color of face AND change custom property at same time?

    Alex Danishevsky

      Hi all,

       

      I've gotten as far as I could with my narrow VB knowledge by looking through examples and I'm most of the way there but need some help. Attached is a basic shelf with some custom properties (the macro is attached as well). I want to select a few edge faces in the assembly, run the macro and have it change the face colors but also change "Long F" custom property to "Ding!" for the selected part. It works some of the time but not others which makes me think my loop needs to be corrected. This tool is to assign edgebanding codes to the factory for finishing sides of wood parts. So selecting either 1 face on 1 part or 1 face on 3 parts, they should all change color and each part should get the "Long F" custom property updated. Please help.

       

       

       

      Option Explicit

      Dim swApp As SldWorks.SldWorks

       

      Sub main()

      Dim swModel As SldWorks.ModelDoc2

      Dim vComps As Variant

      Dim swComp As SldWorks.Component2

      Dim swAssy As SldWorks.AssemblyDoc

      Dim i As Integer

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

      Dim swSelMgr As SldWorks.SelectionMgr

      Dim swFace As SldWorks.Face2

      Dim vProps As Variant

      Dim cpm As CustomPropertyManager

      Dim eb As String

       

       

          Set swSelMgr = swModel.SelectionManager

          Set swAssy = swModel

           vComps = swAssy.GetComponents(False)

          'updateProperty swModel

         

          For i = 1 To swSelMgr.GetSelectedObjectCount2(-1)

          Set swComp = vComps(i)

          Set swModel = swComp.GetModelDoc2

          Set cpm = swModel.Extension.CustomPropertyManager("")

          'updateProperty swModel

           eb = "Ding!"

           eb = Replace(eb, "_", " ")

       

       

      cpm.Delete "Long F"

      cpm.Add2 "Long F", swCustomInfoText, eb

       

       

              Set swFace = swSelMgr.GetSelectedObject6(i, -1)

              vProps = swFace.GetMaterialPropertyValues2(1, Empty)

              vProps(0) = 1 'R

              vProps(1) = 1 'G

              vProps(2) = 0 'B

              vProps(3) = 1

              vProps(4) = 1

              vProps(5) = 0.8

              vProps(6) = 0.3125

              vProps(7) = 0

              vProps(8) = 0

              swFace.SetMaterialPropertyValues2 vProps, 1, Empty

          Next i

      End Sub