Change part feature (Fillet in this case) face color from Assembly itself

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
it is my first share, and i am sharing it because as this forum helps me a lot when i need so i feel that i shoud share something which can help someone there.
i wrote this code by modifying code from topic "Re: Change User Parameter Custom Property with VB" by Bg45 in reply to: jddickson.
and it is shared below...
Purpose: Change part feature (Fillet in this case) face color from Assembly itself color by RGB value.
feature name ("Fillet3"), please change it to desired/your feature.
part name (in which feature name "Fillet3" is) = "Sketch.ipt", please change it to desired/your part
Public Sub Main()
Dim R As Byte, G As Byte, B As Byte
R = 255
G = 255
B = 0
Call tryl3(R, G, B)
End Sub
Public Sub tryl3(R, G, B)
'Get the active assembly document.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
'Iterate through all of the documents referenced by the assembly.
Dim oDoc As Document
For Each oDoc In oAsmDoc.AllReferencedDocuments
'Check to see if this is a part and part name is "Sketch.ipt".
If oDoc.DocumentType = kPartDocumentObject And oDoc.DisplayName = "Sketch.ipt" Then
Debug.Print oDoc.DisplayName
Debug.Print oDoc.FullFileName
Dim oPartDoc As PartDocument
Set oPartDoc = oDoc
Dim oFeatures As PartFeatures
Set oFeatures = oPartDoc.ComponentDefinition.Features
'Check to see if the part document contains Features.
If oFeatures.Count > 0 Then
Dim oFeature As PartFeature
'Loop through each Feature.
For Each oFeature In oFeatures
'look for oFeature.Type Fillet and Feature Name = "Fillet3"
If oFeature.Type = kFilletFeatureObject And oFeature.Name = "Fillet3" Then
Debug.Print oFeature.Name
Set oFeature = oFeatures.Item("Fillet3")
'MsgBox oFeature.Name 'oUserParam.Value
Dim oTG As TransientObjects
Set oTG = ThisApplication.TransientObjects
Dim oAssets As Assets
Set oAssets = oPartDoc.Assets
Dim oAsset As Asset
On Error Resume Next
Set oAsset = oAssets.Item("Test")
If Err.Number <> 0 Then
Call oAssets.Add(kAssetTypeAppearance, "Generic", "Test", "Test")
End If
Dim generic_color As ColorAssetValue
Set generic_color = oAsset.Item("generic_diffuse")
generic_color.Value = oTG.CreateColor(R, G, B)
Set oFillet = oFeature 'oCompDef.Features.FilletFeatures("Fillet3")
Dim oFace As Face
i = 1
For i = 1 To 24
Set oFace = oFillet.Faces.Item(i) 'The face
oFace.Appearance = oAsset
Next
End If
Next oFeature
Else
Debug.Print "No userparameter is available"
End If
End If
Next oDoc
oAsmDoc.Update
End Sub