AnsweredAssumed Answered

Color Changing Macro

Question asked by Chris Tellers on Mar 18, 2013
Latest reply on Mar 18, 2013 by Chris Tellers

Good Morning

 

I am running the code below to cycle through a user selected faces or features to change them to the selected color (I have a userform they select the color from)

 

Everything works great except when you select more that 2 of any type (face or feature) it does the first two selection fine then it will not set the vProps Variable.  Not sure what I am missing.

 

Code -------------------------------------------------------------------------

Sub Color_Code()

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swFace As SldWorks.Face2

Dim swFeat As SldWorks.Feature

Dim i As Integer

Dim vProps As Variant

Dim Part As Object

Dim boolstatus As Boolean

 

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

 

 

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

    If swSelMgr.GetSelectedObjectType3(i, -1) = swSelBODYFEATURES Then

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

        vProps = swFeat.GetMaterialPropertyValues2(i, Empty)

        vProps(0) = VProp0

        vProps(1) = VProp1

        vProps(2) = VProp2

        vProps(3) = 1

        vProps(4) = 1

        vProps(5) = 0.8

        vProps(6) = 0.3125

        vProps(7) = 0

        vProps(8) = 0

        swFeat.SetMaterialPropertyValues2 vProps, swAllConfiguration, Empty

    ElseIf swSelMgr.GetSelectedObjectType3(i, -1) = swSelFACES Then

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

        vProps = swFace.GetMaterialPropertyValues2(i, Empty)

        vProps(0) = VProp0

        vProps(1) = VProp1

        vProps(2) = VProp2

        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

    Else

        MsgBox "Please select a Feature or Face"

    End If

Next i

 

 

 

swModel.ClearSelection2 True

 

 

'Closes User Form

If PinDialogValue = 1 Then

    'Do Nothing

Else

    Unload ColorManager

End If

 

 

'Redraw to see new color

swModel.GraphicsRedraw2

 

 

End Sub

--------------------------------------------------------------------------------------------

 

Any help would be greatly appreciated.

 

Thanks

Chris

Outcomes