Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 516

Inventor API: Change the color of a selected face in an assembly document

$
0
0

Q:  How can I change the color of the face by selecting a face object from an assembly document?

A:  In an assembly document you should use the NativeObject of a face proxy object to obtain the original occurrence. By modifying the NativeObject's color property you can modify the color of the face in the assembly.

Selecting face in an assembly context you really get FaceProxy object of this face. You need to use NativeObject property of this face proxy object to get reference to the original face. Then you are able to modify face color.

The following VBA example demonstrates how this is done.

Sub test()
    Dim oSelectSet As SelectSet
    Set oSelectSet = ThisApplication.ActiveDocument.SelectSet
   
    On Error Resume Next
    If oSelectSet.count <> 1 Then
        Exit Sub
    End If
   
    ' check if it's a face
    Dim oFaceProxy As FaceProxy
    Set oFaceProxy = oSelectSet.Item(1)
   
    If oFaceProxy Is Nothing Then
        Exit Sub
    End If
    On Error GoTo 0
   
    ' get the native object, which resides in the definition of the occurrence
    Dim oFace As Face
    Set oFace = oFaceProxy.NativeObject
   
    ' get the document where the face belongs
    Dim oDoc As Document
    Set oDoc = oFace.Parent.ComponentDefinition.Document
   
' NOTE: make sure that the style "myColor" already

' exists in the document where the face belongs
' if it does not exist yet then this call will fail

 

    Dim oStyle As RenderStyle
    Set oStyle = oDoc.RenderStyles.Item("myColor") 'your customized color
   
    Call oFace.SetRenderStyle(kOverrideRenderStyle, oStyle)
End Sub

 

by Vladimir Ananyev

Viewing all articles
Browse latest Browse all 516

Trending Articles