Hi, A little late, put together this code and it served me. Previously I had made one that identified the occurrence and opened a selected file in false mode, but this type of code gave a problem if the created piece had not been saved (for example, a piece created in the frame generator not yet saved). This new code opens in context and makes the changes it is not necessary that the piece is saved
change appearance of part
Sub Main()
'Change the appearance of part
'The part may not be saved
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oPart As ComponentOccurrence
Line1 :
'''Pick part occurrence
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Part")
If oPart Is Nothing Then
Exit Sub
Else
Dim oAsset As Asset
Dim oAsset_Array As New ArrayList
For Each oAsset_Array_X In ThisApplication.ActiveAppearanceLibrary.AppearanceAssets
oAsset_Array.Add(oAsset_Array_X.DisplayName)
oAsset_Array.Sort()
Next
'present the user with the list to choose from
100:
oAsset_Array_Selected = InputListBox("CHOOSE TEXTURE FROM ABOVE LIST", oAsset_Array, oAsset_Array.Item(0), "TEXTURE SELECTION", "LIST OF TEXTURES")
If oAsset_Array_Selected = "" Then GoTo 100 :
Dim oDef As PartDocument
oDef = oPart.Definition.Document
Dim oRenderStyle As RenderStyle
oRenderStyle = oDef.RenderStyles.Item(oAsset_Array_Selected)
oDef.ActiveRenderStyle = oRenderStyle
iLogicVb.UpdateWhenDone = True
End If
End Sub
change material of part
Sub Main()
'Change the material of part
'The part may not be saved
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oPart As ComponentOccurrence
Line1 :
'''Pick part occurrence
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Seleccione Pieza")
If oPart Is Nothing Then
Exit Sub
Else
Dim oDef As PartDocument
oDef = oPart.Definition.Document
Dim oMaterialAssets As AssetsEnumerator
oMaterialAssets = oDef.MaterialAssets
Dim oAsset As Asset
Dim oAsset_Array As New ArrayList
For Each oAsset_Array_X In ThisApplication.ActiveMaterialLibrary.MaterialAssets
oAsset_Array.Add(oAsset_Array_X.DisplayName)
oAsset_Array.Sort()
Next
'present the user with the list to choose from
100:
oAsset_Array_Selected = InputListBox("CHOOSE TEXTURE FROM ABOVE LIST", oAsset_Array, oAsset_Array.Item(0), "TEXTURE SELECTION", "LIST OF TEXTURES")
If oAsset_Array_Selected = "" Then GoTo 100:
oDef.ComponentDefinition.Material =oDef.Materials.Item(oAsset_Array_Selected )
iLogicVb.UpdateWhenDone = True
End If
End Sub
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn