How to not process parts in a certain layer

Hello, I am using some code that steps through an assembly and runs measure bodies on each individual part. However, I wanted to add an exception to the code, maybe an If statement, that will not process parts in a certain layer. What would that code be?

The component object has a .Layer property that you can check and take action based on the value. For instance:

If myComp.Layer = 1 Then
'do this
Else
'do that
End If

If you are processing a number of components in a For loop, you can use the Continue For command to skip processing this object and continue with the next one.

For Each tempComp in allComps
If tempComp.Layer = 1 Then
'skip this component, continue with the next one
Continue For
End If

'other commands to process the component

Next

So I attained the following code from this link: http://www.nxjournaling.com/content/assigning-active-assembly-array

I added the above If statement and it works, except for one thing.

For Each theComp As Assemblies.Component In myInfo.AllComponents
If theComp.Layers = 3 Then

else

Dim refName As String = theComp.ReferenceSet
GetCompBodies(theComp, theBodies, refName)
mb = myMeasure.NewMassProperties(massUnits, 0.99, theBodies.ToArray)
mb.InformationUnit = MeasureBodies.AnalysisUnit.PoundFoot

lw.WriteLine(theComp.DisplayName & "; " & refName & "; " & theBodies.Count.ToString & "; " & mb.Area.ToString())
totalArea += mb.Area
End If
Next

MakeWorkPart(Nothing)

lw.WriteLine("")
lw.WriteLine(";;total surface area;" & totalArea.ToString)

The last line in the code above is what is displaying the sum of the surface area, however the number is not accurate. I added the "mb.InformationUnit = MeasureBodies.AnalysisUnit.PoundFoot" to the code so it would calculate the numbers in pounds per foot and not inches.

If I run measure bodies from the menu and select the whole assembly the number it is producing in ft is very different then the number that is being produced by running the code above.

Also, even after excluding certain layers on the model, you can see in the listing window it generates that it did not measure the parts in the specified layer, but the total area that it produces (that last line of code) is the same no matter what you do. Why do you think that is?

The code also seems to report the number of bodies in the given reference set. Do these numbers match what you expect to see?

Yes the number of bodies in the reference sets is what I expected. So if I sum the area in a spread sheet, all of the numbers listed add up to be accurate. So it is only the totalVolume variable that is not summing up correctly, which isn't a big deal. So besides that the code is infact measuring everything accurately. Thanks again.

I don't see a totalVolume variable in the code posted...

Nothing stands out to me in the code snippet that you posted; if you'd like to email me the full code, I'll take a look at it as soon as I have the time. Email to info@nxjournaling.com