@mecanicu wrote:
Kudos for this code.
I tried this code on a multi body part and it's working as expected but I would like to know if it's possible to modify this code to exclude first two body (or specific body by name) and if it's possible to use a specific set of custom appearances (a custom library or a user list)
Thank you!
Change by body index
Sub main()
Dim oDoc As PartDocument = ThisDoc.Document
Dim oChangeBodyIndex As Integer
oChangeBodyIndex=1
Call oChangeBodyColorByIndex(oDoc,oChangeBodyIndex)
End Sub
Private Function oChangeBodyColorByIndex(oDoc As PartDocument,oBodyIndex As Integer)
Dim oStyle As RenderStyle
Dim oRscount As Double
oRscount = oDoc.RenderStyles.Count
Dim oRandItem As Double
Dim oStyle_Array As New ArrayList
For Each oStyle In oDoc.RenderStyles
oStyle_Array.Add(oStyle.Name)
Next
For Each oFace As Face In oDoc.ComponentDefinition.SurfaceBodies.Item(oBodyIndex).Faces
oRandItem = Round((oRscount - 2) * Rnd() + 1, 0)
oStyle= oDoc.RenderStyles(oStyle_Array(oRandItem))
oFace.SetRenderStyle(kOverrideRenderStyle, oStyle)
Next
end Function
change color by body Name
Sub main()
Dim oDoc As PartDocument = ThisDoc.Document
Dim oBodyName As String
oBodyName="Solid1"
Call oChangeBodyColorByName(oDoc,oBodyName)
End Sub
Private Function oChangeBodyColorByName(oDoc As PartDocument,oBodyName As String)
Dim oStyle As RenderStyle
Dim oRscount As Double
oRscount = oDoc.RenderStyles.Count
Dim oRandItem As Double
Dim oStyle_Array As New ArrayList
For Each oStyle In oDoc.RenderStyles
oStyle_Array.Add(oStyle.Name)
Next
For Each oSolid As SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
If oSolid.Name=oBodyName then
For Each oFace As Face In oSolid.Faces
oRandItem = Round((oRscount - 2) * Rnd() + 1, 0)
oStyle= oDoc.RenderStyles(oStyle_Array(oRandItem))
oFace.SetRenderStyle(kOverrideRenderStyle, oStyle)
Next
end if
Next
end Function