Unable to apply finish to multiple of the same part within an assembly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi guys,
I have a script I use to apply a powder coat finish to all faces in an assembly, but it fails when I have multiple of the same part within it. This is a problem as most of the assemblies I design are held together with fasteners, which are all the same part. Here is the script that I'm using:
Option Explicit On
Sub Main
Dim oInvApp As Inventor.Application = ThisApplication
Dim oADoc As AssemblyDocument = TryCast(ThisDoc.FactoryDocument, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
'set list of components to skip
Dim oSkipList As New ArrayList
oSkipList.Clear
' oSkipList.Add("20110") 'add parts to skip here
' oSkipList.Add("20224")
Dim oFaceColl As Inventor.FaceCollection
For Each oComponent In oADoc.ComponentDefinition.Occurrences
If oComponent.Suppressed = True Then Continue For
If TypeOf oComponent.Definition Is VirtualComponentDefinition Then Continue For
GetFaces(oComponent, oFaceColl, oSkipList)
Next
Dim oFinishColour = "Manor Red"
Dim oAppearance As Object = oADoc.AppearanceAssets.Item(oFinishColour)
Dim oFinishFeats As FinishFeatures = oADef.Features.FinishFeatures
Dim oFinishDef As FinishDefinition = oFinishFeats.CreateFinishDefinition(oFaceColl, FinishTypeEnum.kMaterialCoatingFinishType, "Powder Coat", oAppearance)
Dim oFinishFeat As FinishFeature = oFinishFeats.Add(oFinishDef)
End Sub
Function GetFaces(occ As Inventor.ComponentOccurrence, Optional ByRef faceColl As Inventor.FaceCollection = Nothing, Optional oSkipList As ArrayList = Nothing) As Inventor.FaceCollection
If (occ Is Nothing) OrElse occ.Suppressed Then Return Nothing
If TypeOf occ.Definition Is VirtualComponentDefinition Then Return Nothing
Dim oOccName As String = Split(occ.Name, ":")(0)
If oSkipList.Contains(oOccName) Then Return Nothing
If faceColl Is Nothing Then faceColl = ThisApplication.TransientObjects.CreateFaceCollection()
For Each oBody As SurfaceBody In occ.SurfaceBodies
For Each oFace As Face In oBody.Faces
faceColl.Add(oFace)
Next 'oFace
Next 'oBody
If occ.SubOccurrences IsNot Nothing AndAlso occ.SubOccurrences.Count > 0 Then
For Each oSubOcc As Inventor.ComponentOccurrence In occ.SubOccurrences
GetFaces(oSubOcc, faceColl, oSkipList)
Next 'oSubOcc
End If
Return faceColl
End Function
The code fails on the line:
Dim oFinishDef As FinishDefinition = oFinishFeats.CreateFinishDefinition(oFaceColl, FinishTypeEnum.kMaterialCoatingFinishType, "Powder Coat", oAppearance)
With the error "The parameter is incorrect. (0x80070057 (E_INVALIDARG))"
At the moment I have made made the function skip these parts which are used multiple times, by adding their part numbers to an array. This is not ideal as the finish does not include the fasteners, and going forward I want to use this code for larger assemblies that contain multiples of parts that are manufactured in house.
Does anyone know a way to get this to work, or is it a bug? I'm running Inventor 2025.3.1. I have tried on multiple machines and got the same error.