Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Michael.Navara
in reply to: BeKirra

The code snippet can be modified to change appearance of SurfaceBodyProxy at the assembly level.

If you want to add content of appearance library it is easy but you need to ensure the selected appearance to copy to the document before you assign them to the body.

See Set the appearance of an occurrence API Sample for more information.

Sub Main()
    Dim bodyProxy As SurfaceBodyProxy
    Dim pick = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Pick a body")
    Dim surfaceBodyProxy As SurfaceBodyProxy = TryCast(pick, SurfaceBodyProxy)
    If Not surfaceBodyProxy Is Nothing Then
        bodyProxy = surfaceBodyProxy
    Else
        Return
    End If

    ChangeAppearance(bodyProxy)

    ThisApplication.ActiveDocument.Update()
End Sub

Private Sub ChangeAppearance(bodyProxy As SurfaceBodyProxy)
    Dim asmDef As AssemblyComponentDefinition = bodyProxy.ContainingOccurrence.ContextDefinition
    Dim asmDoc As AssemblyDocument = asmDef.Document
    Dim assetNames = asmDoc.AppearanceAssets.OfType(Of Asset).Select(Function(x) x.DisplayName)
    Dim selectedAssetName As String = InputListBox("Select Appearance", assetNames).ToString()

    Dim selectedAsset As Asset = asmDoc.AppearanceAssets.OfType(Of Asset).FirstOrDefault(Function(x) x.DisplayName = selectedAssetName)
    If selectedAsset Is Nothing Then Return

    bodyProxy.Appearance = selectedAsset

End Sub