- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all!
I'm trying to get an iLogic rule to work but cant find out whats going wrong.
To let it find all parts in an assembly incl. sub assemblies is not very difficult but when I added a visibilty filter to it some weird stuff happend.
It should iterate through the whole assembly to see if a part is visible (or not) and if its visible the mass weight is added to a double to sum up everything and get a total weight string of all thats visible in the current view representation.
It goes wrong at subassemblies, the code seems to ignore parts that are used multiple times in that subassembly.
I tested the code with an adjusment to get a list of part names instead of the total mass sum. At the master view rep I get a list of all part names like it should do. When I switch to a view rep it shows a list of the names of all unique parts excl. multiple used parts instead of incl multiple used parts. it ignores a hidden subassembly and adds some parts to the list but it does correctly excludes parts in the direct main assembly that are hidden... I just cant wrap my mind around it what I told the code to do with this outcome.
Something is not right in the code, but I do no understand what is going wrong.
I added all 3 version of the code I tried for testing. The simplyfied code is where I want to go to, but maybe this just simply wont work.
'Simplyfied value code:
objDef = ThisDoc.Document.ComponentDefinition Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = objDef.Occurrences.AllLeafOccurrences Dim objComp As ComponentOccurrence
Dim val As Double Dim total As Double = 0 For Each objComp In oLeafOccs If Component.Visible(objComp.Name) = True Then val=objComp.MassProperties.Mass total=total+val Next Dim sTotal As String sTotal = total MessageBox.Show(sTotal, "Total weight") InventorVb.DocumentUpdate()
'Value code:
objApp = ThisApplication objApp.ScreenUpdating = False objApp.SilentOperation = True objDef = ThisDoc.Document.ComponentDefinition Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = objDef.Occurrences.AllLeafOccurrences Dim objComp As ComponentOccurrence Dim lisOccs As New ArrayList Dim val As Double Dim total As Double = 0 For Each objComp In oLeafOccs If Component.Visible(objComp.Name) = True Then lisOccs.Add(objComp.MassProperties.Mass) Next Dim sNames As String For Each val In lisOccs sNames = sNames & "; " & val Next MessageBox.Show(sNames, "Title") objApp.ScreenUpdating = True objApp.SilentOperation = False InventorVb.DocumentUpdate()
'Partname code:
objApp = ThisApplication objApp.ScreenUpdating = False objApp.SilentOperation = True objDef = ThisDoc.Document.ComponentDefinition Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = objDef.Occurrences.AllLeafOccurrences Dim objComp As ComponentOccurrence Dim lisOccs As New ArrayList Dim val As Double Dim total As Double = 0 For Each objComp In oLeafOccs If Component.Visible(objComp.Name) = True Then lisOccs.Add(objComp) Next Dim sNames As String For Each objComp In lisOccs 'objComp.Delete sNames = sNames & "; " & objComp.Name Next MessageBox.Show(sNames, "Title") objApp.ScreenUpdating = True objApp.SilentOperation = False InventorVb.DocumentUpdate()
Solved! Go to Solution.