Message 1 of 10
Apply Finish to Sub Assembly within Assembly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to add a finish to a sub assembly within an assembly. I have the following code that selects every face of a sub assembly when the user picks one in an assembly, but when I try to add those faces to a finish feature definition I get the error "The parameter is incorrect. (0x80070057 (E_INVALIDARG))", due to the line setting the finish definition. It seems as if something is incorrect with the face collection. Is there a better way of applying finishes, or what am I doing wrong here?
Sub Main()
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oFaceCol As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection
Dim oFaceProx As FaceProxy
Dim oComponent As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "select subassembly")
If oComponent.Definition.Type = ObjectTypeEnum.kAssemblyComponentDefinitionObject
Dim oDef As AssemblyComponentDefinition = oComponent.Definition
For Each oFaceProx In GetProxies(oComponent)
ThisApplication.CommandManager.DoSelect(oFaceProx)
oFaceCol.Add(oFaceProx)
Next
End If
MsgBox(oFaceCol.Count)
'Create finish definition.
Dim oFinishColour = iProperties.Value("Custom", "Box Colour")
Dim oAppearance As Object = oAsm.AppearanceAssets.Item(oFinishColour)
Dim oFinishFeatures As FinishFeatures = oAsm.ComponentDefinition.Features.FinishFeatures
Dim oFinishDef As FinishDefinition = oFinishFeatures.CreateFinishDefinition(oFaceCol, FinishTypeEnum.kMaterialCoatingFinishType, "Powder Coat", oAppearance)
'Create finish feature
Try
Dim oFinish As FinishFeature = oFinishFeatures.Add(oFinishDef)
Catch
Logger.Trace("Couldn't create finish in " & oAsm.DisplayName & ".")
End Try
End Sub
Function GetProxies(oComponent As ComponentOccurrence) As ObjectCollection
Dim oProxCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oDef As AssemblyComponentDefinition = oComponent.Definition
For Each oComp As ComponentOccurrence In oDef.Occurrences
If oComp.Definition.Type = ObjectTypeEnum.kAssemblyComponentDefinitionObject
For Each oProx1 As FaceProxy In GetProxies(oComp)
Dim oProx2 As FaceProxy
Call oComponent.CreateGeometryProxy(oProx1, oProx2)
oProxCol.Add(oProx2)
Next
Else
Dim oCompDef As PartComponentDefinition = oComp.Definition
For Each oBod As SurfaceBody In oCompDef.SurfaceBodies
For Each oFace As Face In oBod.Faces
Dim oProx1 As FaceProxy
Dim oProx2 As FaceProxy
Call oComp.CreateGeometryProxy(oFace, oProx1)
Call oComponent.CreateGeometryProxy(oProx1, oProx2)
oProxCol.Add(oProx2)
Next
Next
End If
Next
Return oProxCol
End Function