By Adam Nagy
If you want to find out how big the areas are in the assembly that need to be covered with certain paints then you can write a code to collect that data.
In this case to take into account any face colour that might have been overridden at the main assembly level, we'll iterate through all the faces in context of the top assembly. We just have to keep a list of all the materials we encountered, and the area they cover altogether.
To help with this process I'm using a Dictionary object. In case of VBA you can use the one available from "Microsoft Scripting Runtime" library:
Other languages provide their own Dictionary implementation that you can use - e.g. .NET has it as well.
For testing purposes I'm using the "Personal Computer.iam" sample that is available from the Autodesk Inventor 2016 Samples under "Models\Assemblies\Personal Computer":
Here is our code:
Sub CollectPaintedAreas() Dim doc As AssemblyDocument Set doc = ThisApplication.ActiveDocument Dim cd As AssemblyComponentDefinition Set cd = doc.ComponentDefinition ' This object type is from ' "Microsoft Scripting Runtime" library Dim dict As Dictionary Set dict = New Dictionary ' Check all the faces for their appearance and area On Error Resume Next Dim co As ComponentOccurrence For Each co In cd.Occurrences.AllLeafOccurrences Dim sb As SurfaceBody For Each sb In co.SurfaceBodies Dim f As Face For Each f In sb.Faces Dim a As Asset Set a = f.Appearance ' Some faces might have issues with ' Appearance property If Err = 0 Then If dict.Exists(a.DisplayName) Then dict(a.DisplayName) = _ dict(a.DisplayName) + f.Evaluator.Area Else Call dict.Add( _ a.DisplayName, f.Evaluator.Area) End If End If Err.Clear Next Next Next
' If you also want to handle weldment assemblies and their weld beads
If TypeOf cd Is WeldmentComponentDefinition Then
Dim wcd As WeldmentComponentDefinition
Set wcd = cd Dim wbead As WeldBead
For Each wbead In wcd.Welds.WeldBeads
Dim fs As Faces
Set fs = wbead.BeadFaces
Set f = fs(fs.Count)
Set a = f.Appearance
' Some faces might have issues with
' Appearance property
If Err = 0 Then
If dict.Exists(a.DisplayName) Then
dict(a.DisplayName) = _
dict(a.DisplayName) + f.Evaluator.area
Else
Call dict.Add( _
a.DisplayName, f.Evaluator.area)
End If
Else
Const name = "Unknown"
If dict.Exists(name) Then
dict(name) = _
dict(name) + f.Evaluator.area
Else
Call dict.Add( _
name, f.Evaluator.area)
End If
End If
Err.Clear
Next
End If
' List result Dim n As Variant For Each n In dict Debug.Print n + " = " + Str(dict(n)) + " cm2" Next End Sub
The result:
Silicon Nitride - Polished = 12916.9688783868 cm2 Glossy - Black = 2339.14399193464 cm2 Chrome - Polished = 3851.9558804525 cm2 Smooth - Ivory = 42.4976735204942 cm2 Clear - Green 1 = 1.40193572166445 cm2 Zinc = 777.846133032108 cm2 Cool White = 130.026627637732 cm2 Snow = 497.991799292123 cm2 Aluminum - Polished = 1798.11482682528 cm2 Copper - Polished = 23.2457401847515 cm2 Pink Rose = 1.94839840336866 cm2 Blue - Wall Paint - Glossy = 66.2601255359018 cm2 Violet = 2.30497698015977 cm2 Smooth - Dark Forest Green = 1746.5581771357 cm2 Green Pastel = 2.03418124319939 cm2 Pink = 2.03418124319939 cm2 Sky Blue Medium = 2.03418124319939 cm2 Smooth - Yellow = 30.2747833343406 cm2 Dark Gray = 289.6377248152 cm2 Light Gray = 86.5221761930381 cm2 Glossy - Gold = 1.89552392144668 cm2 Light Red = 29.8206048586813 cm2 Teflon = 23.5951135218548 cm2 Wheat = 13.1217919533048 cm2 Aluminum - Polished-1 = 2.91547594742265E-02 cm2 Default = 421.056440220586 cm2 Red = 57.6774842076835 cm2 Rubber-Black = 214.031238785277 cm2 White = 1.21634005726582 cm2 Light Beige = 2.96880505764235 cm2 Orange (Pale) = 6117.16485607271 cm2 Orange (Inventor) = 12.359525846104 cm2
If you want to do the same inside a part document, then you could do it like this:
Sub CollectPaintedAreasInPartDocument() Dim doc As PartDocument Set doc = ThisApplication.ActiveDocument Dim cd As PartComponentDefinition Set cd = doc.ComponentDefinition ' This object type is from ' "Microsoft Scripting Runtime" library Dim dict As Dictionary Set dict = New Dictionary ' Check all the faces for their appearance and area On Error Resume Next Dim sb As SurfaceBody For Each sb In cd.SurfaceBodies Dim f As Face For Each f In sb.Faces Dim a As Asset Set a = f.Appearance ' Some faces might have issues with ' Appearance property If Err = 0 Then If dict.Exists(a.DisplayName) Then dict(a.DisplayName) = _ dict(a.DisplayName) + f.Evaluator.area Else Call dict.Add( _ a.DisplayName, f.Evaluator.area) End If End If Err.Clear Next Next ' List result Dim n As Variant For Each n In dict Debug.Print n + " = " + Str(dict(n)) + " cm2" Next End Sub