- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'd like to know whether it possible to count SurfaceBodies of any Assembly (including those of MultiBody parts present) with just one LINQ query.
For now I can do this for single-level (no-subassemblies) assemblies only with iLogic-code like:
Dim assyDoc As AssemblyDocument = ThisDoc.Document
MsgBox((From occ As ComponentOccurrence In assyDoc.ComponentDefinition.Occurrences.AllLeafOccurrences Select occ.SurfaceBodies.Count).Sum, , "Number of bodies in the assembly:" )
BUT this code is not applicable for more complex (even two-level) assembly - returns error "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))").
The same error will occur with traditional cycle-based code like:
Dim ttlSolidQty As Integer For Each occ As ComponentOccurrence In compDef.Occurrences.AllLeafOccurrences ' !! ComponentOccurrenceProxy
' If TypeOf occ Is ComponentOccurrence Then logger.info(occ.Name & " - occ")
' If TypeOf occ Is ComponentOccurrenceProxy Then logger.info(occ.Name & " - occPROXY")
ttlSolidQty += occ.SurfaceBodies.Count
Next
MsgBox(ttlSolidQty, , "Number of bodies in the assembly:" )
Some LeafOccurrences are just ComponentOccurrence while other (those at 2nd and deeper levels) are both ComponentOccurrence and ComponentOccurrenceProxy.
This same code would work OK without Type Declaration in FOR line like:
For Each occ In compDef.Occurrences.AllLeafOccurrences
But it seems to be impossible to just omit Type Declaration In the LINQ query mentioned - it would then return "Overload resolution failed because no accessible 'Sum' accepts this number of arguments."
What I'm missing?
Please vote for Inventor-Idea Text Search within Option Names
Solved! Go to Solution.