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

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

Anonymous
Not applicable
631 Views
1 Reply
Message 1 of 2

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

Anonymous
Not applicable

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:

 

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

 

 

632 Views
1 Reply
Reply (1)
Message 2 of 2

Yijiang.Cai
Autodesk
Autodesk

Nice code sample, and really useful!

Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
0 Likes